summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/arrayobject.c1
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src2
-rw-r--r--numpy/core/src/multiarray/ctors.c1
-rw-r--r--numpy/core/src/multiarray/einsum.c.src21
-rw-r--r--numpy/core/src/multiarray/getset.c1
-rw-r--r--numpy/core/src/multiarray/shape.c17
-rw-r--r--numpy/core/tests/test_multiarray.py16
7 files changed, 20 insertions, 39 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 6f4d3d349..e1db4d6f6 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -1663,7 +1663,6 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
descr = NULL;
goto fail;
}
- PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
Py_INCREF(buffer.base);
if (PyArray_SetBaseObject(ret, buffer.base) < 0) {
Py_DECREF(ret);
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 972147bb0..48003e6a3 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -736,7 +736,6 @@ VOID_getitem(void *input, void *vap)
Py_DECREF(ret);
return NULL;
}
- PyArray_UpdateFlags((PyArrayObject *)ret, NPY_ARRAY_UPDATE_ALL);
return (PyObject *)ret;
}
@@ -936,7 +935,6 @@ VOID_setitem(PyObject *op, void *input, void *vap)
Py_DECREF(ret);
return -1;
}
- PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
res = PyArray_CopyObject(ret, op);
Py_DECREF(ret);
return res;
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 60b48350c..70f5c72aa 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -3684,7 +3684,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
Py_DECREF(ret);
return NULL;
}
- PyArray_UpdateFlags(ret, NPY_ARRAY_ALIGNED);
return (PyObject *)ret;
}
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
index 0eab25299..3c086351f 100644
--- a/numpy/core/src/multiarray/einsum.c.src
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -2078,17 +2078,6 @@ get_single_op_view(PyArrayObject *op, int iop, char *labels,
if (*ret == NULL) {
return -1;
}
- if (!PyArray_Check(*ret)) {
- Py_DECREF(*ret);
- *ret = NULL;
- PyErr_SetString(PyExc_RuntimeError,
- "NewFromDescr failed to return an array");
- return -1;
- }
- PyArray_UpdateFlags(*ret,
- NPY_ARRAY_C_CONTIGUOUS|
- NPY_ARRAY_ALIGNED|
- NPY_ARRAY_F_CONTIGUOUS);
Py_INCREF(op);
if (PyArray_SetBaseObject(*ret, (PyObject *)op) < 0) {
Py_DECREF(*ret);
@@ -2183,16 +2172,6 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
if (ret == NULL) {
return NULL;
}
- if (!PyArray_Check(ret)) {
- Py_DECREF(ret);
- PyErr_SetString(PyExc_RuntimeError,
- "NewFromDescr failed to return an array");
- return NULL;
- }
- PyArray_UpdateFlags(ret,
- NPY_ARRAY_C_CONTIGUOUS|
- NPY_ARRAY_ALIGNED|
- NPY_ARRAY_F_CONTIGUOUS);
Py_INCREF(op);
if (PyArray_SetBaseObject(ret, (PyObject *)op) < 0) {
Py_DECREF(ret);
diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c
index 86e6e7a2f..d86f90a53 100644
--- a/numpy/core/src/multiarray/getset.c
+++ b/numpy/core/src/multiarray/getset.c
@@ -758,7 +758,6 @@ _get_part(PyArrayObject *self, int imag)
Py_DECREF(ret);
return NULL;
}
- PyArray_CLEARFLAGS(ret, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
return ret;
}
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 05c24d6da..1424a69f3 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -189,7 +189,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
npy_intp *dimensions = newdims->ptr;
PyArrayObject *ret;
int ndim = newdims->len;
- npy_bool same, incref = NPY_TRUE;
+ npy_bool same;
npy_intp *strides = NULL;
npy_intp newstrides[NPY_MAXDIMS];
int flags;
@@ -230,6 +230,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
* data in the order it is in.
* NPY_RELAXED_STRIDES_CHECKING: size check is unnecessary when set.
*/
+ Py_INCREF(self);
if ((PyArray_SIZE(self) > 1) &&
((order == NPY_CORDER && !PyArray_IS_C_CONTIGUOUS(self)) ||
(order == NPY_FORTRANORDER && !PyArray_IS_F_CONTIGUOUS(self)))) {
@@ -243,10 +244,10 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
else {
PyObject *newcopy;
newcopy = PyArray_NewCopy(self, order);
+ Py_DECREF(self);
if (newcopy == NULL) {
return NULL;
}
- incref = NPY_FALSE;
self = (PyArrayObject *)newcopy;
}
}
@@ -277,21 +278,14 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims,
goto fail;
}
- if (incref) {
- Py_INCREF(self);
- }
if (PyArray_SetBaseObject(ret, (PyObject *)self)) {
Py_DECREF(ret);
return NULL;
}
-
- PyArray_UpdateFlags(ret, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
return (PyObject *)ret;
fail:
- if (!incref) {
- Py_DECREF(self);
- }
+ Py_DECREF(self);
return NULL;
}
@@ -970,9 +964,6 @@ PyArray_Ravel(PyArrayObject *arr, NPY_ORDER order)
if (ret == NULL) {
return NULL;
}
-
- PyArray_UpdateFlags(ret,
- NPY_ARRAY_C_CONTIGUOUS|NPY_ARRAY_F_CONTIGUOUS);
Py_INCREF(arr);
if (PyArray_SetBaseObject(ret, (PyObject *)arr) < 0) {
Py_DECREF(ret);
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index a60f2cd92..3bc7e92c1 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -573,6 +573,22 @@ class TestZeroRank(object):
x = np.array(2)
assert_raises(ValueError, np.add, x, [1], x)
+ def test_real_imag(self):
+ # contiguity checks are for gh-11245
+ x = np.array(1j)
+ xr = x.real
+ xi = x.imag
+
+ assert_equal(xr, np.array(0))
+ assert_(type(xr) is np.ndarray)
+ assert_equal(xr.flags.contiguous, True)
+ assert_equal(xr.flags.f_contiguous, True)
+
+ assert_equal(xi, np.array(1))
+ assert_(type(xi) is np.ndarray)
+ assert_equal(xi.flags.contiguous, True)
+ assert_equal(xi.flags.f_contiguous, True)
+
class TestScalarIndexing(object):
def setup(self):