Commits

mattip committed 5c0ec11

update test, fix implementation of reduce

  • Participants
  • Parent commits 4c78008
  • Branches numpypy-array_prepare_-array_wrap

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_ufuncs.py

         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):

File pypy/module/micronumpy/test/test_subtype.py

         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):
                 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)