From 959e147a8a41c37bc3b9d1f11d89449cb4cc9882 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Wed, 19 Apr 2006 02:26:34 +0000 Subject: Speed up copying code a bit for well-behaved cases. --- numpy/core/src/arrayobject.c | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'numpy/core/src/arrayobject.c') diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 4d0c12f18..8a8c55837 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -621,6 +621,23 @@ PyArray_Size(PyObject *op) } } + +static void +_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, + intp N, int elsize) +{ + intp i, j; + char *tout = dst; + char *tin = src; + for (i=0; ind) == src->nd && (nd > 0) && + PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) { + int maxaxis=0, maxdim=dest->dimensions[0]; + int i; + for (i=1; idimensions[i] > maxdim) { + maxaxis = i; + maxdim = dest->dimensions[i]; + } + } + + dit = (PyArrayIterObject *) \ + PyArray_IterAllButAxis((PyObject *)dest, maxaxis); + sit = (PyArrayIterObject *) \ + PyArray_IterAllButAxis((PyObject *)src, maxaxis); + + if ((dit == NULL) || (sit == NULL)) { + Py_XDECREF(dit); + Py_XDECREF(sit); + return -1; + } + + PyArray_XDECREF(dest); + index = dit->size; + while(index--) { + /* strided copy of elsize bytes */ + _strided_byte_copy(dit->dataptr, dest->strides[maxaxis], + sit->dataptr, src->strides[maxaxis], + maxdim, elsize); + PyArray_ITER_NEXT(dit); + PyArray_ITER_NEXT(sit); + } + PyArray_INCREF(dest); + Py_DECREF(dit); + Py_DECREF(sit); + return 0; + } dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest); sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src); -- cgit v1.2.1