[pypy-commit] pypy numppy-flatitter: just reuse what we have (evil laugh)

fijal noreply at buildbot.pypy.org
Thu Jan 19 17:45:00 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numppy-flatitter
Changeset: r51489:e7ccfba90d71
Date: 2012-01-19 18:44 +0200
http://bitbucket.org/pypy/pypy/changeset/e7ccfba90d71/

Log:	just reuse what we have (evil laugh)

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
@@ -1310,6 +1310,7 @@
         self.shapelen = len(arr.shape)
         self.iter = OneDimIterator(arr.start, self.strides[0],
                                    self.shape[0])
+        self.start = arr.start
         self.base = arr
 
     def descr_next(self, space):
@@ -1322,42 +1323,11 @@
     def descr_iter(self):
         return self
 
-    def descr_getitem(self, space, w_idx):
-        if not space.isinstance_w(w_idx, space.w_int):
-            raise OperationError(space.w_ValueError, space.wrap(
-                        "non-integer indexing not supported yet"))
-        _i = space.int_w(w_idx)
-        if _i<0:
-            i = self.size + _i
-        else:
-            i = _i
-        if i >= self.size or i < 0:
-            raise operationerrfmt(space.w_IndexError,
-                            "index (%d) out of range (%d<=index<%d", 
-                                _i, -self.size, self.size)
-        result = self.getitem(self.base.start + i * self.strides[0])
-        return result
-
-    def descr_setitem(self, space, w_idx, w_value):
-        if not space.isinstance_w(w_idx, space.w_int):
-            raise OperationError(space.w_ValueError, space.wrap(
-                        "non-integer indexing not supported yet"))
-        _i = space.int_w(w_idx)
-        if _i<0:
-            i = self.size + _i
-        else:
-            i = _i
-        if i >= self.size or i < 0:
-            raise operationerrfmt(space.w_IndexError,
-                            "index (%d) out of range (%d<=index<%d", 
-                                _i, -self.size, self.size)
-        self.setitem(self.base.start + i * self.strides[0], w_value)
-
 W_FlatIterator.typedef = TypeDef(
     'flatiter',
     next = interp2app(W_FlatIterator.descr_next),
     __iter__ = interp2app(W_FlatIterator.descr_iter),
-    __getitem__ = interp2app(W_FlatIterator.descr_getitem),
-    __setitem__ = interp2app(W_FlatIterator.descr_setitem),
+    __getitem__ = interp2app(BaseArray.descr_getitem),
+    __setitem__ = interp2app(BaseArray.descr_setitem),
 )
 W_FlatIterator.acceptable_as_base_class = False


More information about the pypy-commit mailing list