Commit 0e25b01c authored by Kirill Smelkov's avatar Kirill Smelkov

bigarray: Test that asarray(BigArray(...)) does not hang

It was hanging with NumPy-1.9 before 425dc5d1 (bigarray: Raise
IndexError for out-of-bound element access), because of the following
correct NumPy commit:

    https://github.com/numpy/numpy/commit/d36f8227

and in particular

    https://github.com/numpy/numpy/commit/d36f8227#diff-6d326badc0872de91e025cbfb0be1aafR522

That PySequence_Fast(obj)    (with obj being BigArray)

creates iterator on top of obj and before our previous IndexError fix in
425dc5d1, this was looping forever.

Test explicitly with both NumPy 1.8 and NumPy 1.9, that this construct
does not hang.

/cc @Tyagov
parent 425dc5d1
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
from wendelin.bigarray import BigArray from wendelin.bigarray import BigArray
from wendelin.bigfile import BigFile from wendelin.bigfile import BigFile
from wendelin.lib.mem import memcpy from wendelin.lib.mem import memcpy
from numpy import ndarray, dtype, int32, uint32, uint8, all, zeros, arange, multiply, array_equal from numpy import ndarray, dtype, int32, uint32, uint8, all, zeros, arange, \
multiply, array_equal, asarray
from pytest import raises from pytest import raises
...@@ -422,3 +423,14 @@ def test_bigarray_list(): ...@@ -422,3 +423,14 @@ def test_bigarray_list():
l = list(A) l = list(A)
assert isinstance(l, list) assert isinstance(l, list)
assert l == [0]*10 assert l == [0]*10
def test_bigarray_to_ndarray():
Z = BigFile_Zero(PS)
Zh = Z.fileh_open()
A = BigArray((10,), uint8, Zh)
# without IndexError on out-of-bound scalar access, the following
# - would work with numpy-1.8
# - would loop forever eating memory with numpy-1.9
a = asarray(A)
# wendelin.core | tox setup # wendelin.core | tox setup
[tox] [tox]
envlist = py27-{ZODB3,ZODB4}, py34-ZODB4 envlist = py27-{ZODB3,ZODB4}-{numpy18,numpy19}, py34-ZODB4-{numpy18,numpy19}
# (NOTE ZODB3 does not work on python3) # (NOTE ZODB3 does not work on python3)
[testenv] [testenv]
...@@ -14,6 +14,9 @@ deps = ...@@ -14,6 +14,9 @@ deps =
# latest current ZODB _4_ # latest current ZODB _4_
ZODB4: ZODB3 >=3.11 ZODB4: ZODB3 >=3.11
numpy18: numpy >=1.8.2, <1.9.0
numpy19: numpy >=1.9.2, <1.10.0
commands= {envpython} setup.py test commands= {envpython} setup.py test
# XXX setenv = TMPDIR = ... ? (so that /tmp is not on tmpfs and we don't run out of memory on bench) # XXX setenv = TMPDIR = ... ? (so that /tmp is not on tmpfs and we don't run out of memory on bench)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment