[pypy-commit] pypy numpypy-axisops: fixed mean, added funky tests in ReduceSignature

mattip noreply at buildbot.pypy.org
Tue Jan 10 21:51:17 CET 2012


Author: mattip
Branch: numpypy-axisops
Changeset: r51217:20bbff5d323d
Date: 2012-01-10 22:49 +0200
http://bitbucket.org/pypy/pypy/changeset/20bbff5d323d/

Log:	fixed mean, added funky tests in ReduceSignature

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
@@ -575,8 +575,12 @@
     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:
@@ -777,7 +781,7 @@
         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):
diff --git a/pypy/module/micronumpy/signature.py b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -147,6 +147,7 @@
         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):
@@ -168,6 +169,7 @@
 
     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):
@@ -346,10 +348,20 @@
         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(),


More information about the pypy-commit mailing list