summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c14
-rw-r--r--numpy/core/src/multiarray/shape.c31
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);
}