Commits

Anonymous committed 20bbff5

fixed mean, added funky tests in ReduceSignature

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_numarray.py

     def descr_mean(self, space, w_dim=None):
         if space.is_w(w_dim, space.w_None):
             w_dim = space.wrap(-1)
-        return space.div(self.descr_sum_promote(space, w_dim),
-                                                      space.wrap(self.size))
+        dim = space.int_w(w_dim)
+        if dim < 0:
+            w_denom = space.wrap(self.size)
+        else:
+            w_denom = space.wrap(self.shape[dim])
+        return space.div(self.descr_sum_promote(space, w_dim), w_denom)
 
     def descr_nonzero(self, space):
         if self.size > 1:
         if self.forced_result is not None:
             return self.forced_result.create_sig(res_shape)
         return signature.ReduceSignature(self.binfunc, self.name, self.dtype,
-                                        signature.ScalarSignature(self.dtype),
+                                        signature.ViewSignature(self.dtype),
                                         self.values.create_sig(res_shape))
 
     def get_identity(self, sig, frame, shapelen):

pypy/module/micronumpy/signature.py

         from pypy.module.micronumpy.interp_numarray import ConcreteArray
         concr = arr.get_concrete()
         assert isinstance(concr, ConcreteArray)
+        assert concr.dtype is self.dtype
         self.array_no = _add_ptr_to_cache(concr.storage, cache)
 
     def _create_iter(self, iterlist, arraylist, arr, res_shape, chunklist, dim):
 
     def eval(self, frame, arr):
         iter = frame.iterators[self.iter_no]
+        assert arr.dtype is self.dtype
         return self.dtype.getitem(frame.arrays[self.array_no], iter.offset)
 
 class ScalarSignature(ConcreteSignature):
         self.right._invent_numbering(cache, allnumbers)
 
     def _invent_array_numbering(self, arr, cache):
-        self.right._invent_array_numbering(arr, cache)
+        #Could be called with arr as output or arr as input.
+        from pypy.module.micronumpy.interp_numarray import Reduce
+        if isinstance(arr, Reduce):
+            self.left._invent_array_numbering(arr, cache)
+        else:
+            self.right._invent_array_numbering(arr, cache)
 
     def eval(self, frame, arr):
-        return self.right.eval(frame, arr)
+        #Could be called with arr as output or arr as input.
+        from pypy.module.micronumpy.interp_numarray import Reduce
+        if isinstance(arr, Reduce):
+            return self.left.eval(frame, arr)
+        else: 
+            return self.right.eval(frame, arr)
 
     def debug_repr(self):
         return 'ReduceSig(%s, %s, %s)' % (self.name, self.left.debug_repr(),