summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristolph Gohlke <cgohlke@uci.edu>2011-04-23 16:52:18 -0600
committerCharles Harris <charlesr.harris@gmail.com>2011-04-23 16:52:18 -0600
commita2e81731463448d87fb8c4282595a386532f3aee (patch)
tree3bbb3e2b74819c3b782a86fdb74b9e9f5a851ad3
parentad76bb546940dfd4f95adb3d01e6742a34fb1de1 (diff)
downloadnumpy-a2e81731463448d87fb8c4282595a386532f3aee.tar.gz
BUG: Fix regression in checking array size from dimensions.
-rw-r--r--numpy/core/src/multiarray/ctors.c6
-rw-r--r--numpy/core/tests/test_regression.py3
2 files changed, 5 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 261e6754b..a026ecb4d 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -978,14 +978,14 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
return NULL;
}
- size *= dim;
-
- if (size > largest) {
+ if (dim > largest) {
PyErr_SetString(PyExc_ValueError,
"array is too big.");
Py_DECREF(descr);
return NULL;
}
+ size *= dim;
+ largest /= dim;
}
self = (PyArrayObject *) subtype->tp_alloc(subtype, 0);
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index cb65c8cef..281342bbf 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1152,7 +1152,8 @@ class TestRegression(TestCase):
def test_array_too_big(self):
"""Ticket #1080."""
- assert_raises(ValueError, np.zeros, [2**10]*10)
+ assert_raises(ValueError, np.zeros, [2**10]*10, np.int8)
+ assert_raises(MemoryError, np.zeros, [2**30]*2, np.int8)
def test_dtype_keyerrors_(self):
"""Ticket #1106."""