[pypy-commit] pypy default: test, fix? nditer for negative strides

mattip noreply at buildbot.pypy.org
Thu May 14 15:48:44 CEST 2015


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r77320:0fdc72f5d9ac
Date: 2015-05-14 16:46 +0300
http://bitbucket.org/pypy/pypy/changeset/0fdc72f5d9ac/

Log:	test, fix? nditer for negative strides

diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -217,8 +217,8 @@
     backward = is_backward(imp, order)
     if arr.is_scalar():
         return ConcreteIter(imp, 1, [], [], [], op_flags, base)
-    if (imp.strides[0] < imp.strides[-1] and not backward) or \
-       (imp.strides[0] > imp.strides[-1] and backward):
+    if (abs(imp.strides[0]) < abs(imp.strides[-1]) and not backward) or \
+       (abs(imp.strides[0]) > abs(imp.strides[-1]) and backward):
         # flip the strides. Is this always true for multidimension?
         strides = imp.strides[:]
         backstrides = imp.backstrides[:]
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -1834,6 +1834,13 @@
         v = s.view(y.__class__)
         assert v.strides == (4, 24)
 
+        x = empty([12, 8, 8], 'float64')
+        y = x[::-4, :, :]
+        assert y.base is x
+        assert y.strides == (-2048, 64, 8)
+        y[:] = 1000
+        assert x[-1, 0, 0] == 1000 
+
         a = empty([3, 2, 1], dtype='float64')
         b = a.view(dtype('uint32'))
         assert b.strides == (16, 8, 4)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -246,12 +246,17 @@
                             dtypes=[dtype(int), dtype(int)],
                             stack_inputs=True,
                           )
-        ai = arange(18, dtype=int).reshape(2,3,3)
+        ai = arange(12*3*3, dtype=int).reshape(12,3,3)
         exc = raises(ValueError, ufunc, ai[:,:,0])
         assert "perand 0 has a mismatch in its core dimension 1" in exc.value.message
         ai3 = ufunc(ai[0,:,:])
         ai2 = ufunc(ai)
         assert (ai2 == ai * 2).all()
+        # view
+        aiV = ai[::-2, :, :]
+        assert aiV.strides == (-144, 24, 8)
+        ai2 = ufunc(aiV)
+        assert (ai2 == aiV * 2).all()
 
     def test_frompyfunc_needs_nditer(self):
         def summer(in0):


More information about the pypy-commit mailing list