[Numpy-discussion] Integer overflow in test_einsum (1.7.1)

Toder, Evgeny evgeny.toder at jpmorgan.com
Tue May 14 14:52:51 EDT 2013


C only does modular arithmetic for unsigned types. Signed types (like i2 used here, is should be signed short) are not allowed to overflow in C. I.e. not only  is the result not guaranteed to be modular, or not guaranteed to be consistent, the behavior of the whole program is not specified if it allows signed integer overflow. In practice, your often get two's complement arithmetic, because this is what all current CPUs implement.

So, does numpy implement modular (two's complement) arithmetic for signed types, or does it leave it to C compiler, which does not provide any guarantees?

Eugene

From: numpy-discussion-bounces at scipy.org [mailto:numpy-discussion-bounces at scipy.org] On Behalf Of Charles R Harris
Sent: Tuesday, May 14, 2013 2:25 PM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Integer overflow in test_einsum (1.7.1)


I don't know if it was intended in the test, but numpy doesn't guard against integer overflow. Rather, it takes the C approach and does modular arithmetic. I don't know how to fix that or even if it could be at this point given the historical lack of support. I suppose at some point there could be user type that made such checks, but it would be slower.

Chuck


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130514/d2952bbb/attachment.html>


More information about the NumPy-Discussion mailing list