[pypy-commit] pypy numpypy-axisops: test for sum_promote fails miserably, signature.dtype is not arr.dtype

mattip noreply at buildbot.pypy.org
Tue Jan 10 00:05:48 CET 2012


Author: mattip
Branch: numpypy-axisops
Changeset: r51190:e00f14813b9e
Date: 2012-01-10 01:04 +0200
http://bitbucket.org/pypy/pypy/changeset/e00f14813b9e/

Log:	test for sum_promote fails miserably, signature.dtype is not
	arr.dtype

diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -19,12 +19,12 @@
         a[i][i] = 1
     return a
 
-def mean(a):
+def mean(a, axis=None):
     if not hasattr(a, "mean"):
         a = numpypy.array(a)
-    return a.mean()
+    return a.mean(axis)
 
-def sum(a):
+def sum(a,axis=None):
     '''sum(a, axis=None)
     Sum of array elements over a given axis.
     
@@ -51,12 +51,12 @@
     # TODO: add to doc (once it's implemented): cumsum : Cumulative sum of array elements.
     if not hasattr(a, "sum"):
         a = numpypy.array(a)
-    return a.sum()
+    return a.sum(axis)
 
-def min(a):
+def min(a, axis=None):
     if not hasattr(a, "min"):
         a = numpypy.array(a)
-    return a.min()
+    return a.min(axis)
 
 def max(a, axis=None):
     if not hasattr(a, "max"):
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
@@ -724,10 +724,13 @@
         assert d[1] == 12
 
     def test_mean(self):
-        from numpypy import array
+        from numpypy import array,mean
         a = array(range(5))
         assert a.mean() == 2.0
         assert a[:4].mean() == 1.5
+        a = array(range(105)).reshape(3, 5, 7)
+        assert (mean(a, axis=0) == array(range(35, 70)).reshape(5, 7)).all()
+        assert (mean(a, 2) == array(range(0, 15)).reshape(3, 5) * 7 + 3).all()
 
     def test_sum(self):
         from numpypy import array, arange


More information about the pypy-commit mailing list