Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r73848:1feef8dd0fb2
Date: 2014-10-08 17:52 -0400
http://bitbucket.org/pypy/pypy/changeset/1feef8dd0fb2/

Log:    allow iterator reset to use existing state

diff --git a/pypy/module/micronumpy/iterators.py 
b/pypy/module/micronumpy/iterators.py
--- a/pypy/module/micronumpy/iterators.py
+++ b/pypy/module/micronumpy/iterators.py
@@ -80,7 +80,7 @@
 
 
 class IterState(object):
-    _immutable_fields_ = ['iterator', 'index', 'indices[*]', 'offset']
+    _immutable_fields_ = ['iterator', 'index', 'indices', 'offset']
 
     def __init__(self, iterator, index, indices, offset):
         self.iterator = iterator
@@ -102,8 +102,16 @@
         self.strides = strides
         self.backstrides = backstrides
 
-    def reset(self):
-        return IterState(self, 0, [0] * len(self.shape_m1), self.array.start)
+    @jit.unroll_safe
+    def reset(self, state=None):
+        if state is None:
+            indices = [0] * len(self.shape_m1)
+        else:
+            assert state.iterator is self
+            indices = state.indices
+            for i in xrange(self.ndim_m1, -1, -1):
+                indices[i] = 0
+        return IterState(self, 0, indices, self.array.start)
 
     @jit.unroll_safe
     def next(self, state):
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -322,7 +322,7 @@
             outi.setitem(outs, oval)
             outs = outi.next(outs)
             rights = righti.next(rights)
-        rights = righti.reset()
+        rights = righti.reset(rights)
         lefts = lefti.next(lefts)
     return result
 
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
@@ -605,7 +605,6 @@
             'raw_load': 2,
         })
         self.check_resops({
-            'arraylen_gc': 1,
             'float_add': 2,
             'float_mul': 2,
             'getarrayitem_gc': 7,
@@ -621,12 +620,11 @@
             'int_lt': 11,
             'int_sub': 4,
             'jump': 3,
-            'new_array': 1,
             'new_with_vtable': 7,
             'raw_load': 6,
             'raw_store': 1,
             'same_as': 2,
-            'setarrayitem_gc': 8,
+            'setarrayitem_gc': 10,
             'setfield_gc': 22,
         })
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to