diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-10-18 04:44:28 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-10-18 04:44:28 +0000 |
commit | 4590e9bba04cae1c989c7d16da3dffdffb375561 (patch) | |
tree | 87d25ab4d7b5fab436111cfa7467c674445884f8 /numpy/core/src | |
parent | 0e70085a1e01b853739ab7c8160ae05f6560db03 (diff) | |
download | numpy-4590e9bba04cae1c989c7d16da3dffdffb375561.tar.gz |
Fix so that reshape copies fewer times. Fix so that arr.ctypes.data returns the integer and arr.ctypes._as_parameter_ returns the c_void_p type
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/arrayobject.c | 5 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 31 |
2 files changed, 30 insertions, 6 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index ededf70a0..30a791029 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -7819,7 +7819,8 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) count and return the input */ else { Py_DECREF(newtype); - if ((flags & ENSUREARRAY) && !PyArray_CheckExact(arr)) { + if ((flags & ENSUREARRAY) && + !PyArray_CheckExact(arr)) { Py_INCREF(arr->descr); ret = (PyArrayObject *) \ PyArray_NewFromDescr(&PyArray_Type, @@ -7840,7 +7841,7 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) } /* The desired output type is different than the input - array type */ + array type and copy was not specified */ else { if ((flags & UPDATEIFCOPY) && \ (!PyArray_ISWRITEABLE(arr))) { diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index eba18e3d3..128e548f4 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -454,6 +454,25 @@ _fix_unknown_dimension(PyArray_Dims *newshape, intp s_original) return 0; } +/* returns True if self->nd > 1 and all + there is more than one dimension filled with 1. + */ +static int +_nd_bigger_than_one(PyArrayObject *arr) +{ + int i, nd; + int count=0; + nd = arr->nd; + if (nd > 1) { + for (i=0; i<nd; i++) { + if (arr->dimensions[i] > 1) + count++; + if (count > 1) return 1; + } + } + return 0; +} + /* Returns a new array with the new shape from the data in the old array --- order-perspective depends on fortran argument. @@ -514,12 +533,16 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, return NULL; /* sometimes we have to create a new copy of the array - in order to get the right orientation + in order to get the right orientation and + because we can't just re-use the buffer with the + data in the order it is in. */ if (!(PyArray_ISONESEGMENT(self)) || - ((self->nd > 1) && - ((PyArray_ISCONTIGUOUS(self) && fortran == NPY_FORTRANORDER) - || (PyArray_ISFORTRAN(self) && fortran == NPY_CORDER)))) { + (((PyArray_CHKFLAGS(self, NPY_CONTIGUOUS) && + fortran == NPY_FORTRANORDER) + || (PyArray_CHKFLAGS(self, NPY_FORTRAN) && + fortran == NPY_CORDER)) && + _nd_bigger_than_one(self))) { PyObject *new; new = PyArray_NewCopy(self, fortran); if (new == NULL) return NULL; |