8000 fixup! MAINT: Overhaul function to try and increase speed · numpy/numpy@9832f05 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9832f05

Browse files
committed
fixup! MAINT: Overhaul function to try and increase speed
Improve comments [ci skip]
1 parent 966b2c7 commit 9832f05

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

numpy/core/src/multiarray/mapping.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,21 @@ multi_DECREF(PyObject **objects, npy_intp n)
164164
* > or the newaxis object, but not for integer arrays or other embedded
165165
* > sequences.
166166
*
167+
* The rationale for only unpacking `2*NPY_MAXDIMS` items is the assumption
168+
* that the longest possible index that is allowed to produce a result is
169+
* `(0,)*np.MAXDIMS + (None,)*np.MAXDIMS`. This assumption turns out to be
170+
* wrong (we could add one more item, an Ellipsis), but we keep it for
171+
* compatibility.
172+
*
167173
* @param index The index object, which may or may not be a tuple. This is a
168174
* borrowed reference.
169175
* @param result An empty buffer of 2*NPY_MAXDIMS PyObject* to write each
170-
* index component to. The references written are new..
171-
* This function will in some cases clobber the array beyond
172-
* the last item unpacked.
176+
* index component to. The references written are new.
173177
*
174178
* @returns The number of items in `result`, or -1 if an error occured.
179+
* The entries in `result` at and beyond this index should be
180+
* assumed to contain garbage, even if they were initialized
181+
* to NULL, so are not safe to Py_XDECREF.
175182
*/
176183
NPY_NO_EXPORT npy_intp
177184
unpack_indices(PyObject *index, PyObject *result[2*NPY_MAXDIMS])
@@ -234,7 +241,9 @@ unpack_indices(PyObject *index, PyObject *result[2*NPY_MAXDIMS])
234241

235242
/*
236243
* At this point, we're left with a non-tuple, non-array, sequence:
237-
* typically, a list
244+
* typically, a list. We use some somewhat-arbirary heuristics from here
245+
* onwards to decided whether to treat that list as a single index, or a
246+
* list of indices. It might be worth deprecating this behaviour (gh-4434).
238247
*
239248
* Sequences < NPY_MAXDIMS with any slice objects
240249
* or newaxis, Ellipsis or other arrays or sequences

0 commit comments

Comments
 (0)
0