summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-04-22 18:53:42 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-10-01 16:46:21 -0700
commit81f8667dfaa9361a2ecf00c199a7e38c4d502901 (patch)
treeb0c24c0e943d375048e77ff10ebcc4595bd2e207
parent0ad1ab9dc7da9c1d187b6f2a823adb1806e5b096 (diff)
downloadnumpy-81f8667dfaa9361a2ecf00c199a7e38c4d502901.tar.gz
BUG: Allow array with 0 dims to be resized
-rw-r--r--numpy/core/src/multiarray/shape.c1
-rw-r--r--numpy/core/tests/test_multiarray.py8
2 files changed, 9 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index dac3c960a..40925d8b9 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -61,6 +61,7 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
newsize = 1;
for(k = 0; k < new_nd; k++) {
if (new_dimensions[k] == 0) {
+ newsize = 0;
break;
}
if (new_dimensions[k] < 0) {
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 9cad2e9db..204285a4e 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -4542,6 +4542,14 @@ class TestResize(object):
assert_array_equal(a['k'][-5:], 0)
assert_array_equal(a['k'][:-5], 1)
+ def test_empty_view(self):
+ # check that sizes containing a zero don't trigger a reallocate for
+ # already empty arrays
+ x = np.zeros((10, 0), int)
+ x_view = x[...]
+ x_view.resize((0, 10))
+ x_view.resize((0, 100))
+
class TestRecord(object):
def test_field_rename(self):