diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-04-24 20:44:33 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-04-24 20:44:33 +0000 |
commit | 448bb44cca09075c0281f0857109db3925908098 (patch) | |
tree | d840339bb1f55de400b89db0c5170ca86c53ff34 /numpy/core/src/arrayobject.c | |
parent | 9867cad08e60ed9232a721dc9a95b7951455bfc1 (diff) | |
download | numpy-448bb44cca09075c0281f0857109db3925908098.tar.gz |
Fix so USE_USE_DEFAULTS code works in multi-threaded case. Speed up 1-d array indexing by an integer.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 0bd14c251..d4b4bb83f 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -1468,10 +1468,22 @@ array_big_item(PyArrayObject *self, intp i) return (PyObject *)r; } +/* contains optimization for 1-d arrays */ static PyObject * array_item_nice(PyArrayObject *self, _int_or_ssize_t i) { - return PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i)); + if (self->nd == 1) { + char *item; + if (i < 0) { + i += self->dimensions[0]; + } + if ((item = index2ptr(self, i)) == NULL) return NULL; + return PyArray_Scalar(item, self->descr, (PyObject *)self); + } + else { + return PyArray_Return((PyArrayObject *)\ + array_big_item(self, (intp) i)); + } } static int @@ -2344,7 +2356,22 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) implementation may be possible by refactoring array_subscript */ - PyArrayObject *mp = (PyArrayObject *)array_subscript(self, op); + PyArrayObject *mp; + + /* optimization for integer select and 1-d */ + if (self->nd == 1 && (PyInt_Check(op) || PyLong_Check(op))) { + intp value; + char *item; + value = PyArray_PyIntAsIntp(op); + if (PyErr_Occurred()) + return NULL; + else if (value < 0) { + value += self->dimensions[0]; + } + if ((item = index2ptr(self, value)) == NULL) return NULL; + return PyArray_Scalar(item, self->descr, (PyObject *)self); + } + mp = (PyArrayObject *)array_subscript(self, op); if (mp == NULL) return NULL; |