[pypy-commit] pypy numpypy-axisops: more finely distinguish between different 'promote_?' s

mattip noreply at buildbot.pypy.org
Wed Dec 28 02:59:47 CET 2011


Author: mattip
Branch: numpypy-axisops
Changeset: r50920:e3824eb2fc4c
Date: 2011-12-28 03:38 +0200
http://bitbucket.org/pypy/pypy/changeset/e3824eb2fc4c/

Log:	more finely distinguish between different 'promote_?' s

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
@@ -282,16 +282,17 @@
     descr_rpow = _binop_right_impl("power")
     descr_rmod = _binop_right_impl("mod")
     
-    def _reduce_ufunc_impl(ufunc_name):
+    def _reduce_ufunc_impl(ufunc_name, promote_to_largest = False):
         def impl(self, space, w_dim=None):
             if w_dim is None:
                 w_dim = space.wrap(w_dim)
             return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
-                                                       self, True, w_dim)
+                                        self, True, promote_to_largest, w_dim)
         return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
 
     descr_sum = _reduce_ufunc_impl("add")
-    descr_prod = _reduce_ufunc_impl("multiply")
+    descr_sum_promote = _reduce_ufunc_impl("add", True)
+    descr_prod = _reduce_ufunc_impl("multiply", True)
     descr_max = _reduce_ufunc_impl("maximum")
     descr_min = _reduce_ufunc_impl("minimum")
 
@@ -318,6 +319,7 @@
                                               idx=idx,
                                               cur_best=cur_best)
                 new_best = getattr(dtype.itemtype, op_name)(cur_best, sig.eval(frame, self))
+                print 'new_best',new_best.value,'cur_best',cur_best.value
                 if dtype.itemtype.ne(new_best, cur_best):
                     result = idx
                     cur_best = new_best
@@ -560,7 +562,7 @@
         return w_result
 
     def descr_mean(self, space):
-        return space.div(self.descr_sum(space), space.wrap(self.size))
+        return space.div(self.descr_sum_promote(space), space.wrap(self.size))
 
     def descr_nonzero(self, space):
         if self.size > 1:
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
@@ -101,9 +101,9 @@
     array([[ 1,  5],
            [ 9, 13]])
     '''
-        return self.reduce(space, w_obj, False, w_dim)
+        return self.reduce(space, w_obj, False, False, w_dim)
 
-    def reduce(self, space, w_obj, multidim, w_dim):
+    def reduce(self, space, w_obj, multidim, promote_to_largest, w_dim):
         from pypy.module.micronumpy.interp_numarray import convert_to_array, Scalar
         if self.argcount != 2:
             raise OperationError(space.w_ValueError, space.wrap("reduce only "
@@ -122,7 +122,9 @@
         size = obj.size
         dtype = find_unaryop_result_dtype(
             space, obj.find_dtype(),
-            promote_to_float=self.promote_to_float
+            promote_to_float=self.promote_to_float,
+            promote_to_largest = promote_to_largest,
+            promote_bools = True
         )
         shapelen = len(obj.shape)
         if self.identity is None and size == 0:
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
@@ -722,7 +722,7 @@
         raises(TypeError, 'a.sum(2, 3)')
 
     def test_sumND(self):
-        skip('Not finished yet')
+        from numpypy import arange
         a = arange(15).reshape(5, 3)
         assert (a.sum(0) == [30, 35, 40]).all()
         assert (a.sum(1) == [3, 12, 21, 30, 39]).all()


More information about the pypy-commit mailing list