[pypy-commit] pypy default: redo empty array fix more cleanly
mattip
noreply at buildbot.pypy.org
Fri Mar 16 15:58:19 CET 2012
Author: mattip
Branch:
Changeset: r53726:fd29efd4c701
Date: 2012-03-16 16:57 +0200
http://bitbucket.org/pypy/pypy/changeset/fd29efd4c701/
Log: redo empty array fix more cleanly
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,9 +256,6 @@
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):
@@ -476,16 +473,14 @@
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):
concrete = self.get_concrete()
# Since we got to here, prod(new_shape) == self.size
- new_strides = calc_new_strides(new_shape, concrete.shape,
+ new_strides = None
+ if self.size > 0:
+ new_strides = calc_new_strides(new_shape, concrete.shape,
concrete.strides, concrete.order)
if new_strides:
# We can create a view, strides somehow match up.
@@ -1038,7 +1033,7 @@
def setshape(self, space, new_shape):
if len(self.shape) < 1:
return
- elif len(self.shape) < 2:
+ elif len(self.shape) < 2 or self.size < 1:
# TODO: this code could be refactored into calc_strides
# but then calc_strides would have to accept a stepping factor
strides = []
@@ -1049,7 +1044,7 @@
for sh in new_shape:
strides.append(s)
backstrides.append(s * (sh - 1))
- s *= sh
+ s *= max(1, sh)
if self.order == 'C':
strides.reverse()
backstrides.reverse()
More information about the pypy-commit
mailing list