From 02ea9dd3d3a8f019dd15b103f5da4a870dc98158 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Thu, 27 Mar 2008 04:27:35 +0000 Subject: Fix ticket #676: flattening in Fortran order for ndim > 2 --- numpy/core/src/arrayobject.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'numpy/core/src/arrayobject.c') 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; } -- cgit v1.2.1