summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-07-11 09:43:16 -0600
committerGitHub <noreply@github.com>2016-07-11 09:43:16 -0600
commit08fc49e1b33e4da9e14e375f399ba92c615eb569 (patch)
tree41e843fbfcff3d0424d4becdb3966be84345cd75
parent6685ee897f5321de1d26a54d1028776b07fadf8d (diff)
parent3e396148edfe91214c7baa03492f523ca53680e8 (diff)
downloadnumpy-08fc49e1b33e4da9e14e375f399ba92c615eb569.tar.gz
Merge pull request #7820 from charris/fix-empty-array-allocation-size
MAINT: Allocate fewer bytes for empty arrays.
-rw-r--r--numpy/core/src/multiarray/ctors.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index a03bacceb..b2ef0c451 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -902,7 +902,7 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
int allow_emptystring)
{
PyArrayObject_fields *fa;
- int i;
+ int i, is_empty;
npy_intp nbytes;
if (descr->subarray) {
@@ -953,6 +953,7 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
}
/* Check dimensions and multiply them to nbytes */
+ is_empty = 0;
for (i = 0; i < nd; i++) {
npy_intp dim = dims[i];
@@ -961,13 +962,13 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
* Compare to PyArray_OverflowMultiplyList that
* returns 0 in this case.
*/
+ is_empty = 1;
continue;
}
if (dim < 0) {
PyErr_SetString(PyExc_ValueError,
- "negative dimensions " \
- "are not allowed");
+ "negative dimensions are not allowed");
Py_DECREF(descr);
return NULL;
}
@@ -1041,8 +1042,9 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
* Allocate something even for zero-space arrays
* e.g. shape=(0,) -- otherwise buffer exposure
* (a.data) doesn't work as it should.
+ * Could probably just allocate a few bytes here. -- Chuck
*/
- if (nbytes == 0) {
+ if (is_empty) {
nbytes = descr->elsize;
}
/*