diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-09-28 17:46:22 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-09-28 17:46:22 +0000 |
commit | b821b5c6c5337fdec5d108182de36facbc4ee039 (patch) | |
tree | 772784828cab567842bd0c6bd137ccadc21a672c /numpy/core/src/arrayobject.c | |
parent | c9eba748246a0f1d1e93c587eb4d62c185cdc20a (diff) | |
download | numpy-b821b5c6c5337fdec5d108182de36facbc4ee039.tar.gz |
Create PyArray_HasArrayInterface macro to simplify getting an array from the array interface.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index f3ce7680c..a96a310b9 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -1158,7 +1158,7 @@ static int PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) { PyArrayObject *src; - PyArray_Descr* dtype; + PyObject *r; int ret; /* Special code to mimic Numeric behavior for @@ -1184,17 +1184,24 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) } if (PyArray_Check(src_object)) { - dtype = NULL; + src = (PyArrayObject *)src_object; + Py_INCREF(src); + } + else if (!PyArray_IsScalar(src_object, Generic) && + PyArray_HasArrayInterface(src_object, r)) { + src = (PyArrayObject *)r; } else { + PyArray_Descr* dtype; dtype = dest->descr; Py_INCREF(dtype); + src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0, + dest->nd, + FORTRAN_IF(dest), + NULL); } - src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0, - dest->nd, - FORTRAN_IF(dest), NULL); if (src == NULL) return -1; - + ret = PyArray_MoveInto(dest, src); Py_DECREF(src); return ret; @@ -8253,10 +8260,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, if (flags & UPDATEIFCOPY) goto err; r = Array_FromPyScalar(op, newtype); } - else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \ - ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \ - ((r = PyArray_FromArrayAttr(op, newtype, context)) \ - != Py_NotImplemented)) { + else if (PyArray_HasArrayInterfaceType(op, newtype, context, r)) { PyObject *new; if (r == NULL) {Py_XDECREF(newtype); return NULL;} if (newtype != NULL || flags != 0) { |