summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wiebe <mwiebe@enthought.com>2011-06-09 10:01:35 -0500
committerMark Wiebe <mwiebe@enthought.com>2011-06-09 10:01:35 -0500
commita1e7be3cb49577d77831e2246f39bb80acd5a22f (patch)
tree017622abbbb6a7fa5c46941c4adc8ed551de5ced
parent76ca55f8f399a9eb8081b75c3c9c2ac075a4af9a (diff)
downloadnumpy-a1e7be3cb49577d77831e2246f39bb80acd5a22f.tar.gz
BUG: core: PyArray_NewFromDescr needs to update flags when strides != NULL (fixes #1863
This appears to have been a longstanding bug, but has come to the surface because PyArray_NewLikeArray uses the function with a non-NULL strides parameter and is used more frequently then other such uses.
-rw-r--r--numpy/core/src/multiarray/ctors.c15
-rw-r--r--numpy/core/tests/test_numeric.py2
2 files changed, 10 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index c4980d6c0..a292a1a82 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1083,6 +1083,14 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
self->data = data;
/*
+ * If the strides were provided to the function, need to
+ * update the flags to get the right CONTIGUOUS, ALIGN properties
+ */
+ if (strides != NULL) {
+ PyArray_UpdateFlags(self, UPDATE_ALL);
+ }
+
+ /*
* call the __array_finalize__
* method if a subtype.
* If obj is NULL, then call method with Py_None
@@ -1092,13 +1100,6 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
func = PyObject_GetAttrString((PyObject *)self, "__array_finalize__");
if (func && func != Py_None) {
- if (strides != NULL) {
- /*
- * did not allocate own data or funny strides
- * update flags before finalize function
- */
- PyArray_UpdateFlags(self, UPDATE_ALL);
- }
if (NpyCapsule_Check(func)) {
/* A C-function is stored here */
PyArray_FinalizeFunc *cfunc;
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 77d174425..945e05001 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1201,6 +1201,8 @@ class TestLikeFuncs(TestCase):
assert_equal(dz.shape, d.shape)
assert_equal(array(dz.strides)*d.dtype.itemsize,
array(d.strides)*dz.dtype.itemsize)
+ assert_equal(d.flags.c_contiguous, dz.flags.c_contiguous)
+ assert_equal(d.flags.f_contiguous, dz.flags.f_contiguous)
if dtype is None:
assert_equal(dz.dtype, d.dtype)
else: