Author: Matti Picus <matti.pi...@gmail.com>
Branch: numpypy-array_prepare_-array_wrap
Changeset: r67042:5c0ec116cb8b
Date: 2013-09-21 22:37 +0300
http://bitbucket.org/pypy/pypy/changeset/5c0ec116cb8b/

Log:    update test, fix implementation of reduce

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
@@ -232,6 +232,9 @@
         if out:
             out.set_scalar_value(res)
             return out
+        if space.type(obj) != W_NDimArray:
+            #If obj is a subtype of W_NDimArray, return a empty-shape instance
+            return W_NDimArray.from_shape(space, [], dtype, w_instance=obj)
         return res
 
     def call_prepare(self, space, w_out, w_obj, w_result):
diff --git a/pypy/module/micronumpy/test/test_subtype.py 
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -314,7 +314,7 @@
         raises(TypeError, log, a, out=c)
 
 
-    def test___array_prepare__nocall(self):
+    def test___array_prepare__reduce(self):
         from numpypy import ndarray, array, sum, ones, add
         class with_prepare(ndarray):
             def __array_prepare__(self, arr, context):
@@ -323,10 +323,15 @@
                 print 'called_prepare',arr
                 return x
         a = ones(2).view(type=with_prepare)
-        x = sum(a, axis=0)
+        x = sum(a)
         assert type(x) == with_prepare
-        # reduce functions do not call prepare?
+        assert x.shape == ()
+        # reduce functions do not call prepare, is this a numpy 'feature'?
         assert not getattr(x, 'called_prepare',False)
         x = add.reduce(a)
         assert type(x) == with_prepare
         assert not getattr(x, 'called_prepare',False)
+        a = ones((2,3)).view(type=with_prepare)
+        x = sum(a, axis=0)
+        assert type(x) == with_prepare
+        assert not getattr(x, 'called_prepare',False)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to