diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-21 19:03:35 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-21 19:20:05 +0200 |
commit | a0891abcd7deea0af6f1e7b91e59d1da2101bdff (patch) | |
tree | 690ee3c1c31e5acdb919a78b5b7020a87fdd6298 | |
parent | 8daf1443eae7e35bc8b6349e5304bd9bf2142ae7 (diff) | |
download | numpy-a0891abcd7deea0af6f1e7b91e59d1da2101bdff.tar.gz |
MNT: Remove unnecessary stride/flags cleanup.
This code is unnecessary with changed flags behavior. It would
only serve the purpose of making strides look nicer for the
user.
The UpdateFlags was only required since 1-dim axis being removed
might change contiguous flags. But this cannot happen now.
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 14 | ||||
-rw-r--r-- | numpy/core/src/multiarray/shape.c | 31 |
2 files changed, 5 insertions, 40 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 133652a90..1f455f528 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1517,26 +1517,18 @@ PyArray_EquivTypenums(int typenum1, int typenum2) /*** END C-API FUNCTIONS **/ static PyObject * -_prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order) +_prepend_ones(PyArrayObject *arr, int nd, int ndmin) { npy_intp newdims[NPY_MAXDIMS]; npy_intp newstrides[NPY_MAXDIMS]; - npy_intp newstride; int i, k, num; PyArrayObject *ret; PyArray_Descr *dtype; - if (order == NPY_FORTRANORDER || PyArray_ISFORTRAN(arr) || PyArray_NDIM(arr) == 0) { - newstride = PyArray_DESCR(arr)->elsize; - } - else { - newstride = PyArray_STRIDES(arr)[0] * PyArray_DIMS(arr)[0]; - } - num = ndmin - nd; for (i = 0; i < num; i++) { newdims[i] = 1; - newstrides[i] = newstride; + newstrides[i] = PyArray_DESCR(arr)->elsize; } for (i = num; i < ndmin; i++) { k = i - num; @@ -1677,7 +1669,7 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws) * create a new array from the same data with ones in the shape * steals a reference to ret */ - return _prepend_ones(ret, nd, ndmin, order); + return _prepend_ones(ret, nd, ndmin); clean_type: Py_XDECREF(type); diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c index 33ec6a629..91d18474c 100644 --- a/numpy/core/src/multiarray/shape.c +++ b/numpy/core/src/multiarray/shape.c @@ -267,32 +267,6 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, } } } - else if (ndim > 0) { - /* - * replace any 0-valued strides with - * appropriate value to preserve contiguousness - */ - if (order == NPY_FORTRANORDER) { - if (dimensions[0] == 1) { - strides[0] = PyArray_DESCR(self)->elsize; - } - for (i = 1; i < ndim; i++) { - if (dimensions[i] == 1) { - strides[i] = strides[i-1] * dimensions[i-1]; - } - } - } - else { - if (dimensions[ndim-1] == 1) { - strides[ndim-1] = PyArray_DESCR(self)->elsize; - } - for (i = ndim - 2; i > -1; i--) { - if (dimensions[i] == 1) { - strides[i] = strides[i+1] * dimensions[i+1]; - } - } - } - } Py_INCREF(PyArray_DESCR(self)); ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self), @@ -1164,6 +1138,8 @@ build_shape_string(npy_intp n, npy_intp *vals) * WARNING: If an axis flagged for removal has a shape equal to zero, * the array will point to invalid memory. The caller must * validate this! + * If an axis flagged for removal has a shape larger then one, + * the arrays contiguous flags may require updating. * * For example, this can be used to remove the reduction axes * from a reduction result once its computation is complete. @@ -1186,7 +1162,4 @@ PyArray_RemoveAxesInPlace(PyArrayObject *arr, npy_bool *flags) /* The final number of dimensions */ fa->nd = idim_out; - - /* Update contiguous flags */ - PyArray_UpdateFlags(arr, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS); } |