[NumPy-Tickets] [NumPy] #2133: overflow not caught on operators with int32 array
NumPy Trac
numpy-tickets@scipy....
Tue May 15 19:44:24 CDT 2012
#2133: overflow not caught on operators with int32 array
------------------------+---------------------------------------------------
Reporter: mwtoews | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version: 1.6.1
Keywords: overflow |
------------------------+---------------------------------------------------
I see good overflow warnings operations on int32 scalars, but not for
int32 arrays:
{{{
import numpy as np
# Case 1: Good, proper data types are used to avoid overflow
np.array([1], dtype=np.long) + np.int32(2**31 - 1)
# array([2147483648], dtype=int64)
# Case 2: Bad, overflow happens and no warning raised
np.array([1], dtype=np.int32) + np.int32(2**31 - 1)
# array([-2147483648])
# Case 3: Similar bad, array vs. array
np.array([1], dtype=np.int32) + np.array([2**31 - 1], dtype=np.int32)
# array([-2147483648])
# Case 4: Better, a warning is raised
np.int32(1) + np.int32(2**31 - 1)
# __main__:1: RuntimeWarning: overflow encountered in long_scalars
# -2147483648
}}}
Here is what I can determine between operator ''op'' between arrays or
scalars:
1. array-long ''op'' scalar-32 = array-long, all good
2. array-32 ''op'' scalar-32 = array-32, no overflow warning!
3. array-32 ''op'' array-32 = array-32, no overflow warning!
4. scalar-32 ''op'' scalar-32 = scalar-32, helpful overflow warning
I would expect an overflow runtime warning for cases 2 and 3, similar to
case 4.
These results are with NumPy 1.6.1/Python 2.5.1 on Windows 32-bit, which I
installed from `numpy-unoptimized-1.6.1.win32-py2.5.exe` from
[http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy ~gohlke], but are
reproducible on 64-bit Linux.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2133>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list