Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: numpy-multidim
Changeset: r48503:6fd1b6212a20
Date: 2011-10-27 12:50 +0200
http://bitbucket.org/pypy/pypy/changeset/6fd1b6212a20/

Log:    few small fixes, start working on NDimSlice

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
@@ -260,22 +260,24 @@
                 return False
         return True
 
+    def _create_slice(self, space, w_idx):
+        new_sig = signature.Signature.find_sig([
+            NDimSlice.signature, self.signature
+        ])
+        if (space.isinstance_w(w_idx, space.w_int) or
+            space.isinstance_w(w_idx, space.w_slice)):
+            chunks = [space.decode_index4(w_idx, self.shape[0])]
+        else:
+            chunks = []
+            for i, w_item in enumerate(space.fixedview(w_idx)):
+                chunks.append(space.decode_index4(w_item, self.shape[i]))
+        return NDimSlice(self, new_sig, chunks)
+
     def descr_getitem(self, space, w_idx):
         if self._single_item_result(space, w_idx):
             item = self._single_item_at_index(space, w_idx)
             return self.get_concrete().eval(item).wrap(space)
-        xxx
-        start, stop, step, slice_length = space.decode_index4(w_idx, 
self.shape[0])
-        if step == 0:
-            # Single index
-            return self.get_concrete().eval(start).wrap(space)
-        else:
-            # Slice
-            new_sig = signature.Signature.find_sig([
-                SingleDimSlice.signature, self.signature
-            ])
-            res = SingleDimSlice(start, stop, step, slice_length, self, 
new_sig)
-            return space.wrap(res)
+        return space.wrap(self._create_slice(space, w_idx))
 
     def descr_setitem(self, space, w_idx, w_value):
         self.invalidated()
@@ -514,18 +516,10 @@
 class NDimSlice(ViewArray):
     signature = signature.BaseSignature()
 
-    def __init__(self, start, stop, step, slice_length, parent, signature):
+    def __init__(self, parent, signature, chunks):
         ViewArray.__init__(self, parent, signature)
-        if isinstance(parent, NDimSlice):
-            self.start = parent.calc_index(start)
-            self.stop = parent.calc_index(stop)
-            self.step = parent.step * step
-            self.parent = parent.parent
-        else:
-            self.start = start
-            self.stop = stop
-            self.step = step
-            self.parent = parent
+        self.chunks = chunks
+        xxxx
         self.size = slice_length
 
     def get_root_storage(self):
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -624,6 +624,14 @@
         assert a[1, 2, 0] == 3
         assert a[1, 1, 0] == 0
 
+    def test_slices(self):
+        import numpy
+        a = numpy.zeros((4, 3, 2))
+        raises(IndexError, a.__getitem__, (4,))
+        raises(IndexError, a.__getitem__, (3, 3))
+        raises(IndexError, a.__getitem__, (:, 3))
+        
+
 class AppTestSupport(object):
     def setup_class(cls):
         import struct
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to