Author: Antonio Cuni <[email protected]>
Branch: ndarray-buffer
Changeset: r68242:2187c37bb8b0
Date: 2013-11-19 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/2187c37bb8b0/
Log: implement the offset param
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
@@ -1067,15 +1067,15 @@
offset=0, w_strides=None, order='C'):
from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray
from pypy.module.micronumpy.support import calc_strides
- if (offset != 0 or not space.is_none(w_strides)):
- raise OperationError(space.w_NotImplementedError,
- space.wrap("unsupported param"))
-
dtype = space.interp_w(interp_dtype.W_Dtype,
space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
shape = _find_shape(space, w_shape, dtype)
if not space.is_none(w_buffer):
+ if (not space.is_none(w_strides)):
+ raise OperationError(space.w_NotImplementedError,
+ space.wrap("unsupported param"))
+
buf = space.buffer_w(w_buffer)
try:
raw_ptr = buf.get_raw_address()
@@ -1086,6 +1086,7 @@
raise OperationError(space.w_TypeError, space.wrap(
"numpy scalars from buffers not supported yet"))
storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
+ storage = rffi.ptradd(storage, offset)
return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype,
w_base=w_buffer)
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
@@ -2098,6 +2098,17 @@
assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
assert a.base is buf
+ def test_ndarray_from_buffer_and_offset(self):
+ import numpypy as np
+ import array
+ buf = array.array('c', ['\x00']*7)
+ buf[0] = 'X'
+ a = np.ndarray((3,), buffer=buf, offset=1, dtype='i2')
+ a[0] = ord('b')
+ a[1] = ord('a')
+ a[2] = ord('r')
+ assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00']
+
class AppTestMultiDim(BaseNumpyAppTest):
def test_init(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit