Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r74799:1287046cabea
Date: 2014-12-03 17:38 -0500
http://bitbucket.org/pypy/pypy/changeset/1287046cabea/

Log:    rename iter.update to iter.indices for clarity

diff --git a/pypy/module/micronumpy/flatiter.py 
b/pypy/module/micronumpy/flatiter.py
--- a/pypy/module/micronumpy/flatiter.py
+++ b/pypy/module/micronumpy/flatiter.py
@@ -41,8 +41,8 @@
         return space.wrap(self.state.index)
 
     def descr_coords(self, space):
-        self.state = self.iter.update(self.state)
-        return space.newtuple([space.wrap(c) for c in self.state.indices])
+        coords = self.iter.indices(self.state)
+        return space.newtuple([space.wrap(c) for c in coords])
 
     def descr_iter(self):
         return self
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
@@ -87,12 +87,12 @@
 
 
 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
         self.index = index
-        self.indices = indices
+        self._indices = indices
         self.offset = offset
 
 
@@ -144,7 +144,7 @@
             indices = [0] * len(self.shape_m1)
         else:
             assert state.iterator is self
-            indices = state.indices
+            indices = state._indices
             for i in xrange(self.ndim_m1, -1, -1):
                 indices[i] = 0
         return IterState(self, 0, indices, self.array.start)
@@ -155,7 +155,7 @@
         index = state.index
         if self.track_index:
             index += 1
-        indices = state.indices
+        indices = state._indices
         offset = state.offset
         if self.contiguous:
             offset += self.array.dtype.elsize
@@ -184,20 +184,20 @@
         return IterState(self, index, None, offset)
 
     @jit.unroll_safe
-    def update(self, state):
+    def indices(self, state):
         assert state.iterator is self
         assert self.track_index
+        indices = state._indices
         if not self.contiguous:
-            return state
+            return indices
         current = state.index
-        indices = state.indices
         for i in xrange(len(self.shape_m1)):
             if self.factors[i] != 0:
                 indices[i] = current / self.factors[i]
                 current %= self.factors[i]
             else:
                 indices[i] = 0
-        return IterState(self, state.index, indices, state.offset)
+        return indices
 
     def done(self, state):
         assert state.iterator is self
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
@@ -247,8 +247,8 @@
                                             dtype=dtype)
         assert not arr_iter.done(arr_state)
         w_val = arr_iter.getitem(arr_state).convert_to(space, dtype)
-        out_state = out_iter.update(out_state)
-        if out_state.indices[axis] == 0:
+        out_indices = out_iter.indices(out_state)
+        if out_indices[axis] == 0:
             if identity is not None:
                 w_val = func(dtype, identity, w_val)
         else:
@@ -380,9 +380,9 @@
     while not arr_iter.done(arr_state):
         nonzero_driver.jit_merge_point(shapelen=shapelen, dims=dims, 
dtype=dtype)
         if arr_iter.getitem_bool(arr_state):
-            arr_state = arr_iter.update(arr_state)
+            arr_indices = arr_iter.indices(arr_state)
             for d in dims:
-                res_iter.setitem(res_state, box(arr_state.indices[d]))
+                res_iter.setitem(res_state, box(arr_indices[d]))
                 res_state = res_iter.next(res_state)
         arr_state = arr_iter.next(arr_state)
     return res
diff --git a/pypy/module/micronumpy/test/test_iterators.py 
b/pypy/module/micronumpy/test/test_iterators.py
--- a/pypy/module/micronumpy/test/test_iterators.py
+++ b/pypy/module/micronumpy/test/test_iterators.py
@@ -31,16 +31,14 @@
         s = i.next(s)
         assert s.offset == 3
         assert not i.done(s)
-        assert s.indices == [0,0]
-        s = i.update(s)
-        assert s.indices == [0,3]
+        assert s._indices == [0,0]
+        assert i.indices(s) == [0,3]
         #cause a dimension overflow
         s = i.next(s)
         s = i.next(s)
         assert s.offset == 5
-        assert s.indices == [0,3]
-        s = i.update(s)
-        assert s.indices == [1,0]
+        assert s._indices == [0,3]
+        assert i.indices(s) == [1,0]
 
         #Now what happens if the array is transposed? strides[-1] != 1
         # therefore layout is non-contiguous
@@ -56,12 +54,12 @@
         s = i.next(s)
         assert s.offset == 9
         assert not i.done(s)
-        assert s.indices == [0,3]
+        assert s._indices == [0,3]
         #cause a dimension overflow
         s = i.next(s)
         s = i.next(s)
         assert s.offset == 1
-        assert s.indices == [1,0]
+        assert s._indices == [1,0]
 
     def test_iterator_goto(self):
         shape = [3, 5]
@@ -74,9 +72,9 @@
         assert not i.contiguous
         s = i.reset()
         assert s.index == 0
-        assert s.indices == [0, 0]
+        assert s._indices == [0, 0]
         assert s.offset == a.start
         s = i.goto(11)
         assert s.index == 11
-        assert s.indices is None
+        assert s._indices is None
         assert s.offset == a.start + 5
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to