[pypy-commit] pypy default: add test for empty arrays in reshape (MBlume), add fix
mattip
noreply at buildbot.pypy.org
Fri Mar 16 15:42:10 CET 2012
Author: mattip
Branch:
Changeset: r53719:f73499617673
Date: 2012-03-16 16:16 +0200
http://bitbucket.org/pypy/pypy/changeset/f73499617673/
Log: add test for empty arrays in reshape (MBlume), add fix
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -256,6 +256,9 @@
self.size, w_iterable)
if isinstance(self, Scalar):
return
+ if self.size < 1:
+ self.shape = new_shape[:]
+ return
self.get_concrete().setshape(space, new_shape)
def descr_get_size(self, space):
@@ -473,6 +476,10 @@
else:
w_shape = space.newtuple(args_w)
new_shape = get_shape_from_iterable(space, self.size, w_shape)
+ if self.size < 1:
+ arr = self.get_concrete().copy(space)
+ arr.shape = new_shape[:]
+ return arr
return self.reshape(space, new_shape)
def reshape(self, space, new_shape):
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -434,6 +434,8 @@
a = zeros((4, 2, 3))
a.shape = (12, 2)
(a + a).reshape(2, 12) # assert did not explode
+ a = array([[[[]]]])
+ assert a.reshape((0,)).shape == (0,)
def test_slice_reshape(self):
from _numpypy import zeros, arange
More information about the pypy-commit
mailing list