Commits

Antonio Cuni committed 54f55ff

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

  • Participants
  • Parent commits 85218b7

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_numarray.py

         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
 
     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),

File pypy/module/micronumpy/test/test_numarray.py

         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))