[NumPy-Tickets] [NumPy] #1411: Array reshape bug
NumPy Trac
numpy-tickets@scipy....
Thu Feb 25 06:44:03 CST 2010
#1411: Array reshape bug
---------------------------------------------------+------------------------
Reporter: Han | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.core | Version: 1.3.0
Keywords: reshape, overflow, unpropagated error |
---------------------------------------------------+------------------------
(See also: http://bugs.python.org/issue6562 -- might be related?)
When reshaping a flat ndarray with a (mistaken) 64-bits long, an
OverflowError will be generated in the C layer, but not propagated
to the Python layer. This error can then be caught later on, in a totally
unrelated piece of code.
{{{
>>> from __future__ import with_statement
>>> import sys; sys.version
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit Intel)]'
>>> import threading
>>> import numpy as np
>>> # needing this to reproduce the error, but it can
... # also be reproduced in other ways
... lock = threading.RLock()
>>> # creating a flat array
... arr = np.arange(10)
>>> # reshaping the array, but mistakenly using a 64-bit integer
... arr_shaped = arr.reshape(1<<63)
>>> # all seems to go well up to this point..
... with lock:
... print "done!"
...
C:\Python25\lib\threading.py:697: RuntimeWarning: tp_compare didn't return
-1 or
-2 for exception
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "c:\python25\lib\threading.py", line 94, in acquire
me = currentThread()
File "c:\python25\lib\threading.py", line 697, in currentThread
return _active[_get_ident()]
OverflowError: long int too large to convert to int
}}}
Other ways to reproduce the OverflowError after creating arr_shaped:
{{{
>>> print arr_shaped
>>> import <anything>
>>> arr_shaped + 10 # or other operations
}}}
I also tested it on Python 2.6, with similar results.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1411>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list