Author: Antonio Cuni <[email protected]>
Branch: 
Changeset: r60257:54f55ff51273
Date: 2013-01-20 16:16 +0100
http://bitbucket.org/pypy/pypy/changeset/54f55ff51273/

Log:    expose the .strides attribute at applevel (read-only for now)

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
@@ -40,6 +40,10 @@
         self.implementation = self.implementation.set_shape(space,
             get_shape_from_iterable(space, self.get_size(), w_new_shape))
 
+    def descr_get_strides(self, space):
+        strides = self.implementation.get_strides()
+        return space.newtuple([space.wrap(i) for i in strides])
+
     def get_dtype(self):
         return self.implementation.dtype
 
@@ -645,6 +649,7 @@
     dtype = GetSetProperty(W_NDimArray.descr_get_dtype),
     shape = GetSetProperty(W_NDimArray.descr_get_shape,
                            W_NDimArray.descr_set_shape),
+    strides = GetSetProperty(W_NDimArray.descr_get_strides),
     ndim = GetSetProperty(W_NDimArray.descr_get_ndim),
     size = GetSetProperty(W_NDimArray.descr_get_size),
     itemsize = GetSetProperty(W_NDimArray.descr_get_itemsize),
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
@@ -684,6 +684,12 @@
         assert a.reshape([1]).shape == (1,)
         raises(ValueError, "a.reshape(3)")
 
+    def test_strides(self):
+        from _numpypy import array
+        a = array([[1.0, 2.0],
+                   [3.0, 4.0]])
+        assert a.strides == (16, 8)
+
     def test_add(self):
         from _numpypy import array
         a = array(range(5))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to