diff options
author | Travis Oliphant <oliphant@enthought.com> | 2008-03-27 04:27:35 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2008-03-27 04:27:35 +0000 |
commit | 02ea9dd3d3a8f019dd15b103f5da4a870dc98158 (patch) | |
tree | 436bd981831dec2eabdfd6d3998216ff2fedf0c1 /numpy/core/src/arrayobject.c | |
parent | 620653b708d24c457256dc9c10996172cc4811d9 (diff) | |
download | numpy-02ea9dd3d3a8f019dd15b103f5da4a870dc98158.tar.gz |
Fix ticket #676: flattening in Fortran order for ndim > 2
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 461422325..d9b4c7b90 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -831,6 +831,7 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) */ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { PyArrayIterObject *it; + PyObject *orig_src; void (*myfunc)(char *, intp, char *, intp, intp, int); char *dptr; int axis; @@ -839,6 +840,7 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { NPY_BEGIN_THREADS_DEF + orig_src = src; if (PyArray_NDIM(src) == 0) { /* Refcount note: src and dst have the same size */ PyArray_INCREF((PyArrayObject *)src); @@ -850,15 +852,19 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { return 0; } + axis = PyArray_NDIM(src)-1; + if (order == PyArray_FORTRANORDER) { - axis = 0; - } - else { - axis = PyArray_NDIM(src)-1; + if (PyArray_NDIM(src) <= 2) axis = 0; + /* fall back to a more general method */ + else src = PyArray_Transpose((PyArrayObject *)orig_src, NULL); } it = (PyArrayIterObject *)PyArray_IterAllButAxis(src, &axis); - if (it == NULL) return -1; + if (it == NULL) { + if (src != orig_src) Py_DECREF(src); + return -1; + } if (PyArray_SAFEALIGNEDCOPY(src)) { myfunc = _strided_byte_copy; @@ -884,6 +890,7 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { } NPY_END_THREADS + if (src != orig_src) Py_DECREF(src); Py_DECREF(it); return 0; } |