Commits

mattip committed 5401a67

allow 0 in shape for concatenate

Comments (0)

Files changed (5)

pypy/module/micronumpy/interp_arrayops.py

     chunks = [Chunk(0, i, 1, i) for i in shape]
     axis_start = 0
     for arr in args_w:
+        if arr.get_shape()[axis] == 0:
+            continue
         chunks[axis] = Chunk(axis_start, axis_start + arr.get_shape()[axis], 1,
                              arr.get_shape()[axis])
         Chunks(chunks).apply(res).implementation.setslice(space, arr)

pypy/module/micronumpy/iter.py

 http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html
 for a more gentle introduction.
 
-Given an array x: x.shape == [5,6],
+Given an array x: x.shape == [5,6], where each element occupies one byte
 
 At which byte in x.data does the item x[3,4] begin?
 if x.strides==[1,5]:

pypy/module/micronumpy/strides.py

     for i, chunk in enumerate_chunks(chunks):
         if chunk.step != 0:
             rstrides[j] = strides[i] * chunk.step
-            rbackstrides[j] = strides[i] * (chunk.lgt - 1) * chunk.step
+            rbackstrides[j] = strides[i] * max(0, chunk.lgt - 1) * chunk.step
             rshape[j] = chunk.lgt
             j += 1
         rstart += strides[i] * chunk.start

pypy/module/micronumpy/support.py

     if order == 'C':
         shape_rev.reverse()
     for sh in shape_rev:
+        slimit = max(sh, 1)
         strides.append(s * dtype.get_size())
-        backstrides.append(s * (sh - 1) * dtype.get_size())
-        s *= sh
+        backstrides.append(s * (slimit - 1) * dtype.get_size())
+        s *= slimit
     if order == 'C':
         strides.reverse()
         backstrides.reverse()

pypy/module/micronumpy/test/test_numarray.py

         assert a.backstrides == [135, 12, 2]
         a = create_array([1, 0, 7], MockDtype(), order='C')
         assert a.strides == [7, 7, 1]
-        assert a.backstrides == [-7, -7, 6]
+        assert a.backstrides == [0, 0, 6]
 
     def test_create_slice_f(self):
         a = create_array([10, 5, 3], MockDtype(), order='F')