[pypy-commit] pypy numpypy-nditer: cleanup

mattip noreply at buildbot.pypy.org
Fri Mar 7 15:51:47 CET 2014


Author: Matti Picus <matti.picus at gmail.com>
Branch: numpypy-nditer
Changeset: r69781:2b3b4c7e23b4
Date: 2014-03-07 14:53 +0200
http://bitbucket.org/pypy/pypy/changeset/2b3b4c7e23b4/

Log:	cleanup

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -22,7 +22,7 @@
 
         'set_string_function': 'appbridge.set_string_function',
         'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo',
-        'nditer': 'interp_nditer.nditer',
+        'nditer': 'nditer.nditer',
     }
 
 
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
@@ -139,50 +139,30 @@
     def setitem(self, elem):
         self.array.setitem(self.offset, elem)
 
-class SliceIterator(object):
+class SliceIterator(ArrayIter):
     def __init__(self, arr, strides, backstrides, shape, order="C",
                     backward=False, dtype=None):
-        self.indexes = [0] * (len(shape) - 1)
-        self.offset = 0
-        self.arr = arr
         if dtype is None:
             dtype = arr.implementation.dtype
+        self.dtype = dtype
         if backward:
             self.slicesize = shape[0]
             self.gap = [support.product(shape[1:]) * dtype.elsize]
-            self.strides = strides[1:]
-            self.backstrides = backstrides[1:]
-            self.shape = shape[1:]
-            self.strides.reverse()
-            self.backstrides.reverse()
-            self.shape.reverse()
-            self.shapelen = len(self.shape)
+            strides = strides[1:]
+            backstrides = backstrides[1:]
+            shape = shape[1:]
+            strides.reverse()
+            backstrides.reverse()
+            shape.reverse()
+            size = support.product(shape)
         else:
-            self.shape = [support.product(shape)]
-            self.strides, self.backstrides = calc_strides(shape, dtype, order)
+            shape = [support.product(shape)]
+            strides, backstrides = calc_strides(shape, dtype, order)
+            size = 0
             self.slicesize = support.product(shape)
-            self.shapelen = 0
-            self.gap = self.strides
-        self.dtype = dtype
-        self._done = False
+            self.gap = strides
 
-    def done(self):
-        return self._done
-
-    @jit.unroll_safe
-    def next(self):
-        offset = self.offset
-        for i in range(self.shapelen - 1, -1, -1):
-            if self.indexes[i] < self.shape[i] - 1:
-                self.indexes[i] += 1
-                offset += self.strides[i]
-                break
-            else:
-                self.indexes[i] = 0
-                offset -= self.backstrides[i]
-        else:
-            self._done = True
-        self.offset = offset
+        ArrayIter.__init__(self, arr.implementation, size, shape, strides, backstrides)
 
     def getslice(self):
         from pypy.module.micronumpy.concrete import SliceArray
diff --git a/pypy/module/micronumpy/interp_nditer.py b/pypy/module/micronumpy/nditer.py
rename from pypy/module/micronumpy/interp_nditer.py
rename to pypy/module/micronumpy/nditer.py


More information about the pypy-commit mailing list