[pypy-commit] pypy numpypy-out: more tests, start to think about intermediaries

mattip noreply at buildbot.pypy.org
Mon Feb 6 23:25:00 CET 2012


Author: mattip
Branch: numpypy-out
Changeset: r52152:5bdd210811e1
Date: 2012-02-06 09:08 +0200
http://bitbucket.org/pypy/pypy/changeset/5bdd210811e1/

Log:	more tests, start to think about intermediaries

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
@@ -155,8 +155,20 @@
                 shape = obj.shape[:axis] + obj.shape[axis + 1:]
             if out:
                 #Test for shape agreement
+                if len(out.shape) > len(shape):
+                    raise operationerrfmt(space.w_ValueError,
+                        'output parameter for reduction operation %s' +
+                        ' has too many dimensions', self.name)
+                elif len(out.shape) < len(shape):
+                    raise operationerrfmt(space.w_ValueError,
+                        'output parameter for reduction operation %s' +
+                        ' does not have enough dimensions', self.name)
+                elif out.shape != shape:
+                    raise operationerrfmt(space.w_ValueError,
+                        'output parameter shape mismatch, expecting %s' +
+                        ' , got %s', str(shape), str(out.shape))
                 #Test for dtype agreement, perhaps create an itermediate
-                if out.dtype != dtype:
+                if out.dtype != dtype
                     raise OperationError(space.w_TypeError, space.wrap(
                         "mismatched  dtypes"))
                 return self.do_axis_reduce(obj, dtype, axis, out)
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
@@ -832,7 +832,10 @@
         c = a.sum(0, out=b[1])
         assert (c == [30, 35, 40]).all()
         assert (c == b[1]).all()
-        raises(ValueError, 'a.prod(0, out=arange(10, dtype=float))')
+        raises(ValueError, 'a.prod(0, out=arange(10))')
+        a=arange(12).reshape(3,2,2)
+        raises(ValueError, 'a.sum(0, out=arange(12).reshape(3,2,2))')
+        raises(ValueError, 'a.sum(0, out=arange(3))')
 
     def test_reduce_intermediary(self):
         from numpypy import arange, array


More information about the pypy-commit mailing list