[pypy-commit] pypy numpypy-axisops: merge

fijal noreply at buildbot.pypy.org
Wed Jan 11 21:37:47 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpypy-axisops
Changeset: r51250:9b14783334f5
Date: 2012-01-11 22:37 +0200
http://bitbucket.org/pypy/pypy/changeset/9b14783334f5/

Log:	merge

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,10 +575,9 @@
     def descr_mean(self, space, w_dim=None):
         if space.is_w(w_dim, space.w_None):
             w_dim = space.wrap(-1)
-        dim = space.int_w(w_dim)
-        if dim < 0:
             w_denom = space.wrap(self.size)
         else:
+            dim = space.int_w(w_dim)
             w_denom = space.wrap(self.shape[dim])
         return space.div(self.descr_sum_promote(space, w_dim), w_denom)
 
@@ -780,7 +779,7 @@
     def create_sig(self, res_shape):
         if self.forced_result is not None:
             return self.forced_result.create_sig(res_shape)
-        return signature.ReduceSignature(self.binfunc, self.name, self.dtype,
+        return signature.AxisReduceSignature(self.binfunc, self.name, self.dtype,
                                         signature.ViewSignature(self.dtype),
                                         self.values.create_sig(res_shape))
 
@@ -805,7 +804,7 @@
         ri = ArrayIterator(result.size)
         frame = sig.create_frame(self.values, dim=self.dim)
         value = self.get_identity(sig, frame, shapelen)
-        assert isinstance(sig, signature.ReduceSignature)
+        assert isinstance(sig, signature.AxisReduceSignature)
         while not frame.done():
             axisreduce_driver.jit_merge_point(frame=frame, self=self,
                                           value=value, sig=sig,
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
@@ -130,8 +130,9 @@
                     "%s.reduce without identity", self.name)
         if shapelen > 1 and dim >= 0:
             from pypy.module.micronumpy.interp_numarray import Reduce
-            return space.wrap(Reduce(self.func, self.name, dim, dtype,
-                                                        obj, self.identity))
+            res = Reduce(self.func, self.name, dim, dtype, obj, self.identity)
+            obj.add_invalidates(res)
+            return space.wrap(res)
         sig = find_sig(ReduceSignature(self.func, self.name, dtype,
                                        ScalarSignature(dtype),
                                        obj.create_sig(obj.shape)), obj)
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
@@ -169,7 +169,6 @@
 
     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):
@@ -326,43 +325,49 @@
         return 'Call2(%s, %s, %s)' % (self.name, self.left.debug_repr(),
                                       self.right.debug_repr())
 
+
 class ReduceSignature(Call2):
     def _create_iter(self, iterlist, arraylist, arr, res_shape, chunklist, dim):
-        if dim < 0:
-            self.right._create_iter(iterlist, arraylist, arr, res_shape,
+        self.right._create_iter(iterlist, arraylist, arr, res_shape,
                                     chunklist, dim)
-        else:
-            from pypy.module.micronumpy.interp_numarray import ConcreteArray
-            concr = arr.get_concrete()
-            assert isinstance(concr, ConcreteArray)
-            storage = concr.storage
-            if self.iter_no >= len(iterlist):
-                _iter = axis_iter_from_arr(concr, dim)
-                from interp_iter import AxisIterator
-                assert isinstance(_iter, AxisIterator)
-                iterlist.append(_iter)
-            if self.array_no >= len(arraylist):
-                arraylist.append(storage)
 
     def _invent_numbering(self, cache, allnumbers):
         self.right._invent_numbering(cache, allnumbers)
 
     def _invent_array_numbering(self, 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)
+        self.right._invent_array_numbering(arr, cache)
 
     def eval(self, 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)
+        return self.right.eval(frame, arr)
 
     def debug_repr(self):
         return 'ReduceSig(%s, %s, %s)' % (self.name, self.left.debug_repr(),
                                           self.right.debug_repr())
+
+class AxisReduceSignature(Call2):
+    def _create_iter(self, iterlist, arraylist, arr, res_shape, chunklist, dim):
+        from pypy.module.micronumpy.interp_numarray import ConcreteArray
+        concr = arr.get_concrete()
+        assert isinstance(concr, ConcreteArray)
+        storage = concr.storage
+        if self.iter_no >= len(iterlist):
+            _iter = axis_iter_from_arr(concr, dim)
+            from interp_iter import AxisIterator
+            assert isinstance(_iter, AxisIterator)
+            iterlist.append(_iter)
+        if self.array_no >= len(arraylist):
+            arraylist.append(storage)
+
+    def _invent_numbering(self, cache, allnumbers):
+        self.right._invent_numbering(cache, allnumbers)
+
+    def _invent_array_numbering(self, arr, cache):
+        self.right._invent_array_numbering(arr, cache)
+
+    def eval(self, frame, arr):
+        return self.right.eval(frame, arr)
+
+    def debug_repr(self):
+        return 'AxisReduceSig(%s, %s, %s)' % (self.name, self.left.debug_repr(),
+                                          self.right.debug_repr())
+
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
@@ -729,8 +729,10 @@
         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()
+        b = mean(a, axis=0)
+        b[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()
 
     def test_sum(self):
         from numpypy import array, arange


More information about the pypy-commit mailing list