[pypy-commit] pypy numpypy-out: more tests

mattip noreply at buildbot.pypy.org
Mon Feb 6 20:46:50 CET 2012


Author: mattip
Branch: numpypy-out
Changeset: r52146:3068735b0215
Date: 2012-02-06 21:44 +0200
http://bitbucket.org/pypy/pypy/changeset/3068735b0215/

Log:	more tests

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
@@ -138,7 +138,7 @@
                 axis = space.int_w(w_axis)
             if space.is_w(w_out, space.w_None):
                 out = None
-            elif not isinstance(w_out, W_NDimArray):
+            elif not isinstance(w_out, BaseArray):
                 raise OperationError(space.w_TypeError, space.wrap(
                                                     'output must be an array'))
             else:
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,6 +155,10 @@
                 shape = obj.shape[:axis] + obj.shape[axis + 1:]
             if out:
                 #Test for shape agreement
+                #Test for dtype agreement, perhaps create an itermediate
+                if out.dtype != dtype:
+                    raise OperationError(space.w_TypeError, space.wrap(
+                        "mismatched  dtypes"))
                 return self.do_axis_reduce(obj, dtype, axis, out)
             else:
                 result = W_NDimArray(support.product(shape), shape, dtype)
@@ -166,7 +170,7 @@
                 raise operationerrfmt(space.w_ValueError, "output parameter "
                               "for reduction operation %s has too many"
                               " dimensions",self.name)
-            out.setitem(0, out.dtype.coerce(space, val))
+            out.value = out.dtype.coerce(space, val)
             return out
         return val 
 
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
@@ -794,10 +794,10 @@
         assert a.sum() == 5
 
         raises(TypeError, 'a.sum(2, 3)')
-        skip('fails since Scalar is not a subclass of W_NDimArray')
-        d = zeros(())
+        d = array(0.)
         b = a.sum(out=d)
         assert b == d
+        assert b.dtype == d.dtype
 
     def test_reduce_nd(self):
         from numpypy import arange, array, multiply
@@ -826,12 +826,20 @@
         assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all()
 
     def test_reduce_out(self):
-        from numpypy import arange, array, multiply
+        from numpypy import arange, array
         a = arange(15).reshape(5, 3)
-        b = arange(3)
-        c = a.sum(0, out=b)
+        b = arange(12).reshape(4,3)
+        c = a.sum(0, out=b[1])
         assert (c == [30, 35, 40]).all()
-        assert (c == b).all()
+        assert (c == b[1]).all()
+        raises(ValueError, 'a.prod(0, out=arange(10, dtype=float))')
+
+    def test_reduce_intermediary(self):
+        from numpypy import arange, array
+        a = arange(15).reshape(5, 3)
+        b = array(range(3), dtype=bool)
+        c = a.prod(0, out=b)
+        assert(b == [False,  True,  True]).all()
 
     def test_identity(self):
         from _numpypy import identity, array


More information about the pypy-commit mailing list