Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r74816:e920a686f245
Date: 2014-12-04 14:32 -0500
http://bitbucket.org/pypy/pypy/changeset/e920a686f245/

Log:    support mutate flag to iterator next/reset

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
@@ -77,7 +77,7 @@
 
 
 class IterState(object):
-    _immutable_fields_ = ['iterator', 'index', '_indices', 'offset']
+    _immutable_fields_ = ['iterator', '_indices']
 
     def __init__(self, iterator, index, indices, offset):
         self.iterator = iterator
@@ -117,7 +117,8 @@
         self.factors = factors
 
     @jit.unroll_safe
-    def reset(self, state=None):
+    def reset(self, state=None, mutate=False):
+        index = 0
         if state is None:
             indices = [0] * len(self.shape_m1)
         else:
@@ -125,10 +126,14 @@
             indices = state._indices
             for i in xrange(self.ndim_m1, -1, -1):
                 indices[i] = 0
-        return IterState(self, 0, indices, self.array.start)
+        offset = self.array.start
+        if not mutate:
+            return IterState(self, index, indices, offset)
+        state.index = index
+        state.offset = offset
 
     @jit.unroll_safe
-    def next(self, state):
+    def next(self, state, mutate=False):
         assert state.iterator is self
         index = state.index
         if self.track_index:
@@ -149,7 +154,10 @@
                 else:
                     indices[i] = 0
                     offset -= self.backstrides[i]
-        return IterState(self, index, indices, offset)
+        if not mutate:
+            return IterState(self, index, indices, offset)
+        state.index = index
+        state.offset = offset
 
     @jit.unroll_safe
     def goto(self, index):
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
@@ -215,7 +215,8 @@
             'float_add': 2,
             'getarrayitem_gc': 5,
             'getarrayitem_gc_pure': 7,
-            'getfield_gc_pure': 56,
+            'getfield_gc': 5,
+            'getfield_gc_pure': 51,
             'guard_class': 3,
             'guard_false': 12,
             'guard_nonnull': 11,
@@ -309,7 +310,8 @@
         self.check_resops({
             'float_ge': 2,
             'float_ne': 2,
-            'getfield_gc_pure': 34,
+            'getfield_gc': 4,
+            'getfield_gc_pure': 30,
             'guard_class': 1,
             'guard_false': 8,
             'guard_nonnull': 2,
@@ -561,7 +563,8 @@
             'float_add': 3,
             'getarrayitem_gc': 7,
             'getarrayitem_gc_pure': 14,
-            'getfield_gc_pure': 69,
+            'getfield_gc': 6,
+            'getfield_gc_pure': 63,
             'guard_class': 5,
             'guard_false': 20,
             'guard_nonnull': 6,
@@ -612,7 +615,8 @@
             'float_add': 2,
             'getarrayitem_gc': 2,
             'getarrayitem_gc_pure': 2,
-            'getfield_gc_pure': 36,
+            'getfield_gc': 6,
+            'getfield_gc_pure': 30,
             'guard_class': 3,
             'guard_false': 7,
             'guard_nonnull': 2,
@@ -769,7 +773,8 @@
             'float_mul': 2,
             'getarrayitem_gc': 4,
             'getarrayitem_gc_pure': 9,
-            'getfield_gc_pure': 49,
+            'getfield_gc': 7,
+            'getfield_gc_pure': 42,
             'guard_class': 4,
             'guard_false': 15,
             'guard_not_invalidated': 2,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to