diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-10-04 06:47:28 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-10-04 06:47:28 +0000 |
commit | 3dfcce10e11af18c659812a4b93130b004f1535d (patch) | |
tree | 60495ba742d0bcc44955c0127cce47248fe4d5b8 /scipy/base/src/arrayobject.c | |
parent | 118022b553e5c0e878b09916af5cb7a1a950a19f (diff) | |
download | numpy-3dfcce10e11af18c659812a4b93130b004f1535d.tar.gz |
Made sure that arbitrary sequences (smaller than MAX_DIMS) with slice objects in them use standard indexing.
Diffstat (limited to 'scipy/base/src/arrayobject.c')
-rw-r--r-- | scipy/base/src/arrayobject.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index f126ba1a1..7d29360cb 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -6179,7 +6179,7 @@ fancy_indexing_check(PyObject *args) if (PyTuple_Check(args)) { n = PyTuple_GET_SIZE(args); - if (n > MAX_DIMS) return 3; + if (n >= MAX_DIMS) return 3; for (i=0; i<n; i++) { obj = PyTuple_GET_ITEM(args,i); if (PyArray_Check(obj)) { @@ -6200,8 +6200,23 @@ fancy_indexing_check(PyObject *args) else return 2; } - else if (PySequence_Check(args)) - return 1; + else if (PySequence_Check(args)) { + /* Sequences < MAX_DMS with any slice objects + or NewAxis, or Ellipsis is considered standard + */ + n = PySequence_Size(args); + if (n<0 || n>=MAX_DIMS) return 1; + for (i=0; i<n; i++) { + obj = PySequence_GetItem(args, i); + if (obj == NULL) return 1; + if (PySlice_Check(obj) || obj == Py_Ellipsis || \ + obj == Py_None) { + retval = 0; + } + Py_DECREF(obj); + if (retval == 0) return retval; + } + } return retval; } |