summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2012-11-01 23:42:55 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2012-11-01 23:42:55 +0100
commit237e816e203a2a5a190e23e28d945e0f089663ed (patch)
treef576be214d1324f31f172627c84129fda0fc2bcf
parenta890a8584319c2978735eef96ecaefefacad6346 (diff)
downloadnumpy-237e816e203a2a5a190e23e28d945e0f089663ed.tar.gz
BUG: Reshape of 0-sized arrays failed to work without copy
This also adds a check for order=Keeporder which is not supported. "closes Issue #2700"
-rw-r--r--numpy/core/src/multiarray/shape.c12
-rw-r--r--numpy/core/tests/test_regression.py5
2 files changed, 12 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 6da07e4cd..7abe48891 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -187,6 +187,11 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
if (order == NPY_ANYORDER) {
order = PyArray_ISFORTRAN(self);
}
+ else if (order == NPY_KEEPORDER) {
+ PyErr_SetString(PyExc_ValueError,
+ "order 'K' is not permitted for reshaping");
+ return NULL;
+ }
/* Quick check to make sure anything actually needs to be done */
if (ndim == PyArray_NDIM(self)) {
same = NPY_TRUE;
@@ -230,11 +235,8 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
* because we can't just re-use the buffer with the
* data in the order it is in.
*/
- if (!(PyArray_ISONESEGMENT(self)) ||
- (((PyArray_CHKFLAGS(self, NPY_ARRAY_C_CONTIGUOUS) &&
- order == NPY_FORTRANORDER) ||
- (PyArray_CHKFLAGS(self, NPY_ARRAY_F_CONTIGUOUS) &&
- order == NPY_CORDER)) && (PyArray_NDIM(self) > 1))) {
+ if ((order == NPY_CORDER && !PyArray_IS_C_CONTIGUOUS(self)) ||
+ (order == NPY_FORTRANORDER && !PyArray_IS_F_CONTIGUOUS(self))) {
int success = 0;
success = _attempt_nocopy_reshape(self, ndim, dimensions,
newstrides, order);
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index f46a7ddcf..0f268fce8 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -521,6 +521,11 @@ class TestRegression(TestCase):
a = np.lib.stride_tricks.as_strided(a, shape=(5,), strides=(0,))
assert_(a.reshape(5,1).strides[0] == 0)
+ def test_reshape_zero_size(self, level=rlevel):
+ """Github Issue #2700, setting shape failed for 0-sized arrays"""
+ a = np.ones((0,2))
+ a.shape = (-1,2)
+
def test_repeat_discont(self, level=rlevel):
"""Ticket #352"""
a = np.arange(12).reshape(4,3)[:,2]