[pypy-commit] pypy default: allow 0 in shape for concatenate
mattip
noreply at buildbot.pypy.org
Mon Feb 11 19:53:30 CET 2013
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r61098:5401a6758467
Date: 2013-02-11 20:37 +0200
http://bitbucket.org/pypy/pypy/changeset/5401a6758467/
Log: allow 0 in shape for concatenate
diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -123,6 +123,8 @@
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)
diff --git a/pypy/module/micronumpy/iter.py b/pypy/module/micronumpy/iter.py
--- a/pypy/module/micronumpy/iter.py
+++ b/pypy/module/micronumpy/iter.py
@@ -4,7 +4,7 @@
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]:
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -28,7 +28,7 @@
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
diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -23,9 +23,10 @@
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()
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
@@ -51,7 +51,7 @@
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')
More information about the pypy-commit
mailing list