[pypy-commit] pypy numpy-data-buffer: implement buffers of slice-views.
timo_jbo
noreply at buildbot.pypy.org
Mon Oct 3 05:39:56 CEST 2011
Author: Timo Paulssen <timonator at perpetuum-immobile.de>
Branch: numpy-data-buffer
Changeset: r47775:04889b07a351
Date: 2011-10-03 05:29 +0200
http://bitbucket.org/pypy/pypy/changeset/04889b07a351/
Log: implement buffers of slice-views.
diff --git a/pypy/module/_numpy/interp_buffer.py b/pypy/module/_numpy/interp_buffer.py
--- a/pypy/module/_numpy/interp_buffer.py
+++ b/pypy/module/_numpy/interp_buffer.py
@@ -16,5 +16,12 @@
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
+
diff --git a/pypy/module/_numpy/interp_numarray.py b/pypy/module/_numpy/interp_numarray.py
--- a/pypy/module/_numpy/interp_numarray.py
+++ b/pypy/module/_numpy/interp_numarray.py
@@ -7,7 +7,7 @@
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'])
@@ -17,6 +17,7 @@
class BaseArray(Wrappable):
_attrs_ = ["invalidates", "signature"]
+ BufferClass = NumpyBuffer
def __init__(self):
self.invalidates = []
@@ -296,7 +297,7 @@
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):
@@ -450,11 +451,15 @@
Class for representing views of arrays, they will reflect changes of parent
arrays. Example: slices
"""
+
+ BufferClass = NumpyViewBuffer
+
def __init__(self, parent, signature):
BaseArray.__init__(self)
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.
diff --git a/pypy/module/_numpy/test/test_buffer.py b/pypy/module/_numpy/test/test_buffer.py
--- a/pypy/module/_numpy/test/test_buffer.py
+++ b/pypy/module/_numpy/test/test_buffer.py
@@ -23,7 +23,6 @@
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"))
More information about the pypy-commit
mailing list