Timo Paulssen committed 04889b0

implement buffers of slice-views.

Comments (0)

Files changed (3)


             raise IndexError("Index out of bounds (0<=index<%d)" % self.getlength())
         storage = self.array.get_concrete().get_root_storage()
         char_data = rffi.cast(CHAR_TP, storage)
-        return char_data[index]
+        return char_data[self.calc_index(index)]
+    def calc_index(self, index):
+        return index
+class NumpyViewBuffer(NumpyBuffer):
+    def calc_index(self, index):
+        return self.array.calc_index(index) * self.array.find_dtype().num_bytes


 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.sourcetools import func_with_new_name
-from pypy.module._numpy.interp_buffer import NumpyBuffer
+from pypy.module._numpy.interp_buffer import NumpyBuffer, NumpyViewBuffer
 numpy_driver = jit.JitDriver(greens = ['signature'],
                              reds = ['result_size', 'i', 'self', 'result'])
 class BaseArray(Wrappable):
     _attrs_ = ["invalidates", "signature"]
+    BufferClass = NumpyBuffer
     def __init__(self):
         self.invalidates = []
     def descr_get_data(self, space):
         if self._buffer is None:
-            self._buffer = NumpyBuffer(self)
+            self._buffer = self.BufferClass(self)
         return space.wrap(self._buffer)
 def convert_to_array(space, w_obj):
     Class for representing views of arrays, they will reflect changes of parent
     arrays. Example: slices
+    BufferClass = NumpyViewBuffer
     def __init__(self, parent, signature):
         self.signature = signature
         self.parent = parent
         self.invalidates = parent.invalidates
+        self._buffer = None
     def get_concrete(self):
         # in fact, ViewArray never gets "concrete" as it never stores data.


         assert buf[0] == "\5"
     def test_slice_view(self):
-        skip("buffers on slicing views doesn't work yet")
         from _numpy import array
         from _numpy import dtype
         ar = array(range(5), dtype=dtype("int8"))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.