[pypy-commit] pypy default: Fill more values in array.__array_interface__
amauryfa
noreply at buildbot.pypy.org
Fri Jun 14 00:37:53 CEST 2013
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r64879:2ebf68f7c7be
Date: 2013-06-14 00:12 +0200
http://bitbucket.org/pypy/pypy/changeset/2ebf68f7c7be/
Log: Fill more values in array.__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
@@ -418,8 +418,16 @@
addr = self.implementation.get_storage_as_int(space)
# will explode if it can't
w_d = space.newdict()
- space.setitem_str(w_d, 'data', space.newtuple([space.wrap(addr),
- space.w_False]))
+ space.setitem_str(w_d, 'data',
+ space.newtuple([space.wrap(addr), space.w_False]))
+ space.setitem_str(w_d, 'shape', self.descr_get_shape(space))
+ space.setitem_str(w_d, 'typestr', self.get_dtype().descr_get_str(space))
+ if self.implementation.order == 'C':
+ # Array is contiguous, no strides in the interface.
+ strides = space.w_None
+ else:
+ strides = self.descr_get_strides(space)
+ space.setitem_str(w_d, 'strides', strides)
return w_d
w_pypy_data = None
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
@@ -2138,6 +2138,9 @@
a = array([1, 2, 3])
i = a.__array_interface__
assert isinstance(i['data'][0], int)
+ assert i['shape'] == (3,)
+ assert i['strides'] == None # Because array is in C order
+ assert i['typestr'] == a.dtype.str
a = a[::2]
i = a.__array_interface__
assert isinstance(i['data'][0], int)
More information about the pypy-commit
mailing list