summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2012-10-21 18:53:23 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2012-10-21 18:53:23 +0200
commit8daf1443eae7e35bc8b6349e5304bd9bf2142ae7 (patch)
tree028b2a25843427f85df74dd60863ca29b1e59160
parentc48156dfdc408f0a1e59ef54ac490cccbd6b8d73 (diff)
downloadnumpy-8daf1443eae7e35bc8b6349e5304bd9bf2142ae7.tar.gz
API: ctors changed so that contiguous flags ignore 1-dim axis
This changes ctors.c so that new arrays are created in such a way that they are both C- and F-contiguous if possible. Also fixes some corner cases for 0-sized arrays.
-rw-r--r--numpy/core/src/multiarray/ctors.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 934f9198f..0c5062720 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1825,9 +1825,6 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
}
arrflags = PyArray_FLAGS(arr);
- if (PyArray_NDIM(arr) <= 1 && (flags & NPY_ARRAY_F_CONTIGUOUS)) {
- flags |= NPY_ARRAY_C_CONTIGUOUS;
- }
/* If a guaranteed copy was requested */
copy = (flags & NPY_ARRAY_ENSURECOPY) ||
/* If C contiguous was requested, and arr is not */
@@ -1837,9 +1834,8 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
((flags & NPY_ARRAY_ALIGNED) &&
(!(arrflags & NPY_ARRAY_ALIGNED))) ||
/* If a Fortran contiguous array was requested, and arr is not */
- (PyArray_NDIM(arr) > 1 &&
- ((flags & NPY_ARRAY_F_CONTIGUOUS) &&
- (!(arrflags & NPY_ARRAY_F_CONTIGUOUS)))) ||
+ ((flags & NPY_ARRAY_F_CONTIGUOUS) &&
+ (!(arrflags & NPY_ARRAY_F_CONTIGUOUS))) ||
/* If a writeable array was requested, and arr is not */
((flags & NPY_ARRAY_WRITEABLE) &&
(!(arrflags & NPY_ARRAY_WRITEABLE))) ||
@@ -3570,14 +3566,33 @@ _array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize,
int inflag, int *objflags)
{
int i;
+ npy_bool not_cf_contig = 0;
+ npy_bool nod = 0; /* A dim != 1 was found */
+
+ /* Check if new array is both F- and C-contiguous */
+ for (i = 0; i < nd; i++) {
+ if (dims[i] != 1) {
+ if (nod) {
+ not_cf_contig = 1;
+ break;
+ }
+ nod = 1;
+ }
+ }
+
/* Only make Fortran strides if not contiguous as well */
if ((inflag & (NPY_ARRAY_F_CONTIGUOUS|NPY_ARRAY_C_CONTIGUOUS)) ==
NPY_ARRAY_F_CONTIGUOUS) {
for (i = 0; i < nd; i++) {
strides[i] = itemsize;
- itemsize *= dims[i] ? dims[i] : 1;
+ if (dims[i]) {
+ itemsize *= dims[i];
+ }
+ else {
+ not_cf_contig = 0;
+ }
}
- if (nd > 1) {
+ if (not_cf_contig) {
*objflags = ((*objflags)|NPY_ARRAY_F_CONTIGUOUS) &
~NPY_ARRAY_C_CONTIGUOUS;
}
@@ -3588,9 +3603,14 @@ _array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize,
else {
for (i = nd - 1; i >= 0; i--) {
strides[i] = itemsize;
- itemsize *= dims[i] ? dims[i] : 1;
+ if (dims[i]) {
+ itemsize *= dims[i];
+ }
+ else {
+ not_cf_contig = 0;
+ }
}
- if (nd > 1) {
+ if (not_cf_contig) {
*objflags = ((*objflags)|NPY_ARRAY_C_CONTIGUOUS) &
~NPY_ARRAY_F_CONTIGUOUS;
}