[pypy-commit] pypy default: numpypy: rename kwarg 'dim' to 'axis'

mattip noreply at buildbot.pypy.org
Sat Jan 14 22:35:58 CET 2012


Author: mattip
Branch: 
Changeset: r51333:eb0269c21eec
Date: 2012-01-14 23:25 +0200
http://bitbucket.org/pypy/pypy/changeset/eb0269c21eec/

Log:	numpypy: rename kwarg 'dim' to 'axis'

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
@@ -287,11 +287,11 @@
     descr_rmod = _binop_right_impl("mod")
 
     def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
-        def impl(self, space, w_dim=None):
-            if space.is_w(w_dim, space.w_None):
-                w_dim = space.wrap(-1)
+        def impl(self, space, w_axis=None):
+            if space.is_w(w_axis, space.w_None):
+                w_axis = space.wrap(-1)
             return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
-                                        self, True, promote_to_largest, w_dim)
+                                        self, True, promote_to_largest, w_axis)
         return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
 
     descr_sum = _reduce_ufunc_impl("add")
@@ -569,14 +569,14 @@
             )
         return w_result
 
-    def descr_mean(self, space, w_dim=None):
-        if space.is_w(w_dim, space.w_None):
-            w_dim = space.wrap(-1)
+    def descr_mean(self, space, w_axis=None):
+        if space.is_w(w_axis, space.w_None):
+            w_axis = space.wrap(-1)
             w_denom = space.wrap(self.size)
         else:
-            dim = space.int_w(w_dim)
+            dim = space.int_w(w_axis)
             w_denom = space.wrap(self.shape[dim])
-        return space.div(self.descr_sum_promote(space, w_dim), w_denom)
+        return space.div(self.descr_sum_promote(space, w_axis), w_denom)
 
     def descr_var(self, space):
         # var = mean((values - mean(values)) ** 2)
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
@@ -733,6 +733,7 @@
         a = array(range(105)).reshape(3, 5, 7)
         b = mean(a, axis=0)
         b[0,0]==35.
+        assert a.mean(axis=0)[0, 0] == 35
         assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all()
         assert (mean(a, 2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
 
@@ -755,6 +756,7 @@
         assert array([]).sum() == 0.0
         raises(ValueError, 'array([]).max()')
         assert (a.sum(0) == [30, 35, 40]).all()
+        assert (a.sum(axis=0) == [30, 35, 40]).all()
         assert (a.sum(1) == [3, 12, 21, 30, 39]).all()
         assert (a.max(0) == [12, 13, 14]).all()
         assert (a.max(1) == [2, 5, 8, 11, 14]).all()


More information about the pypy-commit mailing list