[pypy-commit] pypy default: fix behavior of numpypy reduce wrt zero-sized dims
bdkearns
noreply at buildbot.pypy.org
Tue Oct 15 09:14:42 CEST 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r67381:fee031ae7721
Date: 2013-10-15 02:40 -0400
http://bitbucket.org/pypy/pypy/changeset/fee031ae7721/
Log: fix behavior of numpypy reduce wrt zero-sized dims
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -76,7 +76,7 @@
return self.call(space, args_w)
def descr_accumulate(self, space, w_obj, w_axis=None, w_dtype=None, w_out=None):
- if space.is_none(w_axis) or w_axis is None:
+ if space.is_none(w_axis):
w_axis = space.wrap(0)
if space.is_none(w_out):
out = None
@@ -186,9 +186,12 @@
promote_to_largest=promote_to_largest,
promote_bools=True
)
- if self.identity is None and size == 0:
- raise operationerrfmt(space.w_ValueError, "zero-size array to "
- "%s.reduce without identity", self.name)
+ if self.identity is None:
+ for i in range(shapelen):
+ if space.is_none(w_axis) or i == axis:
+ if obj_shape[i] == 0:
+ raise operationerrfmt(space.w_ValueError, "zero-size array to "
+ "%s.reduce without identity", self.name)
if shapelen > 1 and axis < shapelen:
temp = None
if cumultative:
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -657,11 +657,15 @@
assert b[i] == math.degrees(a[i])
def test_reduce_errors(self):
- from numpypy import sin, add
+ from numpypy import sin, add, maximum, zeros
raises(ValueError, sin.reduce, [1, 2, 3])
assert add.reduce(1) == 1
+ assert list(maximum.reduce(zeros((2, 0)), axis=0)) == []
+ raises(ValueError, maximum.reduce, zeros((2, 0)), axis=None)
+ raises(ValueError, maximum.reduce, zeros((2, 0)), axis=1)
+
def test_reduce_1d(self):
from numpypy import add, maximum, less
More information about the pypy-commit
mailing list