diff options
author | Travis E. Oliphant <teoliphant@gmail.com> | 2012-10-09 22:23:39 -0700 |
---|---|---|
committer | Travis E. Oliphant <teoliphant@gmail.com> | 2012-10-09 22:23:39 -0700 |
commit | 96abba1a14db89b933f1a4514c48c3e25af019a1 (patch) | |
tree | db73de914d30bf950764fbcd7194d4da43070975 | |
parent | ca27396b2f32befb7465c4a245329716cb212b80 (diff) | |
parent | 622045abdc567ae3f4995ed355f3fc690533621e (diff) | |
download | numpy-96abba1a14db89b933f1a4514c48c3e25af019a1.tar.gz |
Merge pull request #454 from seberg/issue380
FIX: Issue #380
-rw-r--r-- | numpy/core/src/multiarray/shape.c | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c index 684d42713..2dcf53d55 100644 --- a/numpy/core/src/multiarray/shape.c +++ b/numpy/core/src/multiarray/shape.c @@ -273,21 +273,21 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, * appropriate value to preserve contiguousness */ if (order == NPY_FORTRANORDER) { - if (strides[0] == 0) { + if (dimensions[0] == 1) { strides[0] = PyArray_DESCR(self)->elsize; } for (i = 1; i < ndim; i++) { - if (strides[i] == 0) { + if (dimensions[i] == 1) { strides[i] = strides[i-1] * dimensions[i-1]; } } } else { - if (strides[ndim-1] == 0) { + if (dimensions[ndim-1] == 1) { strides[ndim-1] = PyArray_DESCR(self)->elsize; } for (i = ndim - 2; i > -1; i--) { - if (strides[i] == 0) { + if (dimensions[i] == 1) { strides[i] = strides[i+1] * dimensions[i+1]; } } diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 1620f2024..3bc7204cd 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -498,6 +498,12 @@ class TestRegression(TestCase): b = a[:,1] assert_equal(b.reshape(2,2,order='F'), [[2,6],[4,8]]) + def test_reshape_zero_strides(self, level=rlevel): + """Issue #380, test reshaping of zero strided arrays""" + a = np.ones(1) + a = np.lib.stride_tricks.as_strided(a, shape=(5,), strides=(0,)) + assert_(a.reshape(5,1).strides[0] == 0) + def test_repeat_discont(self, level=rlevel): """Ticket #352""" a = np.arange(12).reshape(4,3)[:,2] |