[pypy-commit] pypy numpypy-axisops: a test and a fix

fijal noreply at buildbot.pypy.org
Sat Jan 14 15:04:24 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpypy-axisops
Changeset: r51304:16b16c97b7c1
Date: 2012-01-14 16:03 +0200
http://bitbucket.org/pypy/pypy/changeset/16b16c97b7c1/

Log:	a test and a fix

diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -135,7 +135,7 @@
         self.res_shape = shape[:]
         self.strides = strides[:dim] + [0] + strides[dim:]
         self.backstrides = backstrides[:dim] + [0] + backstrides[dim:]
-        self.first_line = False
+        self.first_line = True
         self.indices = [0] * len(shape)
         self._done = False
         self.offset = start
@@ -151,12 +151,12 @@
         done = False
         for i in range(shapelen - 1, -1, -1):
             if indices[i] < self.res_shape[i] - 1:
+                if i == self.dim:
+                    first_line = False
                 indices[i] += 1
                 offset += self.strides[i]
                 break
             else:
-                if i == self.dim:
-                    first_line = False
                 indices[i] = 0
                 offset -= self.backstrides[i]
         else:
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
@@ -176,7 +176,11 @@
         assert isinstance(sig, AxisReduceSignature)
         frame = sig.create_frame(arr)
         shapelen = len(obj.shape)
-        self.reduce_axis_loop(frame, sig, shapelen, arr, self.identity)
+        if self.identity is not None:
+            identity = self.identity.convert_to(dtype)
+        else:
+            identity = None
+        self.reduce_axis_loop(frame, sig, shapelen, arr, identity)
         return result
 
     def reduce_axis_loop(self, frame, sig, shapelen, arr, identity):
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
@@ -746,7 +746,7 @@
         raises(TypeError, 'a.sum(2, 3)')
 
     def test_reduce_nd(self):
-        from numpypy import arange, array
+        from numpypy import arange, array, multiply
         a = arange(15).reshape(5, 3)
         assert a.sum() == 105
         assert a.max() == 14
@@ -759,6 +759,7 @@
         assert ((a + a).max() == 28)
         assert ((a + a).max(0) == [24, 26, 28]).all()
         assert ((a + a).sum(1) == [6, 24, 42, 60, 78]).all()
+        assert (multiply.reduce(a) == array([0, 3640, 12320])).all()
         a = array(range(105)).reshape(3, 5, 7)
         assert (a[:, 1, :].sum(0) == [126, 129, 132, 135, 138, 141, 144]).all()
         assert (a[:, 1, :].sum(1) == [70, 315, 560]).all()


More information about the pypy-commit mailing list