Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r50249:591be18ef52c
Date: 2011-12-07 16:42 +0200
http://bitbucket.org/pypy/pypy/changeset/591be18ef52c/
Log: implement some rudimentary __array_interface__
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
@@ -916,6 +916,14 @@
def descr_debug_repr(self, space):
return space.wrap(self.debug_repr())
+ def descr_array_iface(self, space):
+ concrete = self.get_concrete()
+ addr = rffi.cast(lltype.Signed, concrete.storage)
+ w_d = space.newdict()
+ space.setitem_str(w_d, 'data', space.newtuple([space.wrap(addr),
+ space.w_False]))
+ return w_d
+
def convert_to_array(space, w_obj):
if isinstance(w_obj, BaseArray):
return w_obj
@@ -1444,6 +1452,7 @@
__repr__ = interp2app(BaseArray.descr_repr),
__str__ = interp2app(BaseArray.descr_str),
__debug_repr__ = interp2app(BaseArray.descr_debug_repr),
+ __array_interface__ = GetSetProperty(BaseArray.descr_array_iface),
dtype = GetSetProperty(BaseArray.descr_get_dtype),
shape = GetSetProperty(BaseArray.descr_get_shape,
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
@@ -1114,6 +1114,12 @@
b = a[0].copy()
assert (b == zeros(10)).all()
+ def test_array_interface(self):
+ from numpypy import array
+ a = array([1, 2, 3])
+ i = a.__array_interface__
+ assert isinstance(i['data'][0], int)
+
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
import struct
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit