summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-10-25 06:15:40 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-10-25 06:15:40 +0000
commit24b485da911fa5b5fe9036ad0b3db341267aee80 (patch)
tree05f027fd454bcbecfa02414a36a379dde7edbef1 /numpy/core/src/arrayobject.c
parent1e25ae2b885ed6cd5b087f013bd3c61d4c80a1e4 (diff)
downloadnumpy-24b485da911fa5b5fe9036ad0b3db341267aee80.tar.gz
Fix optimization so that array's of 1-element are not interpeted as integers.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index c283c3eb7..4230eeef0 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -2793,6 +2793,28 @@ array_ass_sub_simple(PyArrayObject *self, PyObject *index, PyObject *op)
}
+/* return -1 if tuple-object seq is not a tuple of integers.
+ otherwise fill vals with converted integers
+*/
+static int
+_tuple_of_integers(PyObject *seq, intp *vals, int maxvals)
+{
+ int i;
+ PyObject *obj;
+ intp temp;
+
+ for (i=0; i<maxvals; i++) {
+ obj = PyTuple_GET_ITEM(seq, i);
+ if ((PyArray_Check(obj) && PyArray_NDIM(obj) > 0) ||
+ PyList_Check(obj)) return -1;
+ temp = PyArray_PyIntAsIntp(obj);
+ if (error_converting(temp)) return -1;
+ vals[i] = temp;
+ }
+ return 0;
+}
+
+
static int
array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
{
@@ -2857,9 +2879,9 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
}
/* optimization for integer-tuple */
- if (self->nd > 1 &&
+ if (self->nd > 1 &&
(PyTuple_Check(index) && (PyTuple_GET_SIZE(index) == self->nd))
- && PyArray_IntpFromSequence(index, vals, self->nd) == self->nd) {
+ && (_tuple_of_integers(index, vals, self->nd) >= 0)) {
int i;
char *item;
for (i=0; i<self->nd; i++) {
@@ -2934,7 +2956,7 @@ array_subscript_nice(PyArrayObject *self, PyObject *op)
/* optimization for a tuple of integers */
if (self->nd > 1 && PyTuple_Check(op) &&
(PyTuple_GET_SIZE(op) == self->nd)
- && PyArray_IntpFromSequence(op, vals, self->nd) == self->nd) {
+ && (_tuple_of_integers(op, vals, self->nd) >= 0)) {
int i;
char *item;
for (i=0; i<self->nd; i++) {
@@ -4862,6 +4884,7 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
}
+
/* Check whether the given array is stored contiguously (row-wise) in
memory. */