[pypy-commit] pypy numpy-multidim: fix test_zjit until test_slice

fijal noreply at buildbot.pypy.org
Wed Nov 23 10:45:18 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-multidim
Changeset: r49684:b56fd5dc80b5
Date: 2011-11-23 11:44 +0200
http://bitbucket.org/pypy/pypy/changeset/b56fd5dc80b5/

Log:	fix test_zjit until test_slice

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
@@ -7,6 +7,7 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.rstring import StringBuilder
+from pypy.rlib.objectmodel import instantiate
 
 numpy_driver = jit.JitDriver(greens=['signature'],
                              reds=['result_size', 'i', 'ri', 'self',
@@ -122,7 +123,7 @@
     for i in range(len(elems_w)):
         w_elem = elems_w[i]
         dtype.setitem_w(space, arr.storage, arr_iter.offset, w_elem)
-        arr_iter.next()
+        arr_iter = arr_iter.next()
     return arr
 
 class BaseIterator(object):
@@ -141,7 +142,10 @@
         self.size = size
 
     def next(self):
-        self.offset += 1
+        arr = instantiate(ArrayIterator)
+        arr.size = self.size
+        arr.offset = self.offset + 1
+        return arr
 
     def done(self):
         return self.offset >= self.size
@@ -170,6 +174,7 @@
                 self.offset -= self.arr.backstrides[i]
         else:
             self._done = True
+        return self
 
     def done(self):
         return self._done
@@ -215,6 +220,7 @@
                 self.offset -= self.backstrides[i]
         else:
             self._done = True
+        return self
 
     def done(self):
         return self._done
@@ -228,11 +234,12 @@
         self.right = right
 
     def next(self):
-        self.left.next()
-        self.right.next()
+        return Call2Iterator(self.left.next(), self.right.next())
 
     def done(self):
-        return self.left.done() or self.right.done()
+        if isinstance(self.left, ConstantIterator):
+            return self.right.done()
+        return self.left.done()
 
     def get_offset(self):
         if isinstance(self.left, ConstantIterator):
@@ -244,7 +251,7 @@
         self.child = child
 
     def next(self):
-        self.child.next()
+        return Call1Iterator(self.child.next())
 
     def done(self):
         return self.child.done()
@@ -254,7 +261,7 @@
 
 class ConstantIterator(BaseIterator):
     def next(self):
-        pass
+        return self
 
     def done(self):
         return False
@@ -377,7 +384,7 @@
                 if dtype.ne(new_best, cur_best):
                     result = i.get_offset()
                     cur_best = new_best
-                i.next()
+                i = i.next()
             return result
         def impl(self, space):
             size = self.find_size()
@@ -395,7 +402,7 @@
             all_driver.jit_merge_point(signature=self.signature, self=self, dtype=dtype, i=i)
             if not dtype.bool(self.eval(i)):
                 return False
-            i.next()
+            i = i.next()
         return True
     def descr_all(self, space):
         return space.wrap(self._all())
@@ -408,7 +415,7 @@
                                        dtype=dtype, i=i)
             if dtype.bool(self.eval(i)):
                 return True
-            i.next()
+            i = i.next()
         return False
     def descr_any(self, space):
         return space.wrap(self._any())
@@ -787,8 +794,8 @@
                                          result_size=result_size, i=i, ri=ri,
                                          self=self, result=result)
             result.dtype.setitem(result.storage, ri.offset, self.eval(i))
-            i.next()
-            ri.next()
+            i = i.next()
+            ri = ri.next()
         return result
 
     def force_if_needed(self):
@@ -967,8 +974,8 @@
                                          source_iter=source_iter)
             self.setitem(res_iter.offset, source.eval(source_iter).convert_to(
                 self.find_dtype()))
-            source_iter.next()
-            res_iter.next()
+            source_iter = source_iter.next()
+            res_iter = res_iter.next()
 
     def start_iter(self, res_shape=None):
         if res_shape is not None and res_shape != self.shape:
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
@@ -68,7 +68,7 @@
                 raise operationerrfmt(space.w_ValueError, "zero-size array to "
                     "%s.reduce without identity", self.name)
             value = obj.eval(start).convert_to(dtype)
-            start.next()
+            start = start.next()
         else:
             value = self.identity.convert_to(dtype)
         new_sig = signature.Signature.find_sig([
@@ -82,7 +82,7 @@
                                           value=value, obj=obj, i=i,
                                           dtype=dtype)
             value = self.func(dtype, value, obj.eval(i).convert_to(dtype))
-            i.next()
+            i = i.next()
         return value
 
 class W_Ufunc1(W_Ufunc):
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -78,8 +78,8 @@
     def test_add(self):
         result = self.run("add")
         self.check_loops({'getarrayitem_raw': 2, 'float_add': 1,
-                          'setarrayitem_raw': 1, 'int_add': 1,
-                          'int_lt': 1, 'guard_true': 1, 'jump': 1})
+                          'setarrayitem_raw': 1, 'int_add': 3,
+                          'int_ge': 1, 'guard_false': 1, 'jump': 1})
         assert result == 3 + 3
 
     def define_float_add():
@@ -92,8 +92,8 @@
         result = self.run("float_add")
         assert result == 3 + 3
         self.check_loops({"getarrayitem_raw": 1, "float_add": 1,
-                          "setarrayitem_raw": 1, "int_add": 1,
-                          "int_lt": 1, "guard_true": 1, "jump": 1})
+                          "setarrayitem_raw": 1, "int_add": 2,
+                          "int_ge": 1, "guard_false": 1, "jump": 1})
 
     def define_sum():
         return """
@@ -106,8 +106,8 @@
         result = self.run("sum")
         assert result == 2 * sum(range(30))
         self.check_loops({"getarrayitem_raw": 2, "float_add": 2,
-                          "int_add": 1,
-                          "int_lt": 1, "guard_true": 1, "jump": 1})
+                          "int_add": 2,
+                          "int_ge": 1, "guard_false": 1, "jump": 1})
 
     def define_prod():
         return """
@@ -123,8 +123,8 @@
             expected *= i * 2
         assert result == expected
         self.check_loops({"getarrayitem_raw": 2, "float_add": 1,
-                          "float_mul": 1, "int_add": 1,
-                          "int_lt": 1, "guard_true": 1, "jump": 1})
+                          "float_mul": 1, "int_add": 2,
+                          "int_ge": 1, "guard_false": 1, "jump": 1})
 
     def test_max(self):
         py.test.skip("broken, investigate")
@@ -164,9 +164,9 @@
         result = self.run("any")
         assert result == 1
         self.check_loops({"getarrayitem_raw": 2, "float_add": 1,
-                          "float_ne": 1, "int_add": 1,
-                          "int_lt": 1, "guard_true": 1, "jump": 1,
-                          "guard_false": 1})
+                          "float_ne": 1, "int_add": 2,
+                          "int_ge": 1, "jump": 1,
+                          "guard_false": 2})
 
     def define_already_forced():
         return """
@@ -184,8 +184,8 @@
         # optimization then you end up with 2 float_adds, so we can still be
         # sure it was optimized correctly.
         self.check_loops({"getarrayitem_raw": 2, "float_mul": 1, "float_add": 1,
-                           "setarrayitem_raw": 2, "int_add": 2,
-                           "int_lt": 2, "guard_true": 2, "jump": 2})
+                           "setarrayitem_raw": 2, "int_add": 4,
+                           "int_ge": 2, "guard_false": 2, "jump": 2})
 
     def define_ufunc():
         return """
@@ -199,8 +199,8 @@
         result = self.run("ufunc")
         assert result == -6
         self.check_loops({"getarrayitem_raw": 2, "float_add": 1, "float_neg": 1,
-                          "setarrayitem_raw": 1, "int_add": 1,
-                          "int_lt": 1, "guard_true": 1, "jump": 1,
+                          "setarrayitem_raw": 1, "int_add": 3,
+                          "int_ge": 1, "guard_false": 1, "jump": 1,
         })
 
     def define_specialization():


More information about the pypy-commit mailing list