Skip to content

ENH: Use array indexing preparation routines for flatiter objects #28590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bc55a60
[ENH] Use array indexing preparation routines for flatiter objects
lysnikolaou Mar 25, 2025
f19745e
Fix assign subscript and add tests for it
lysnikolaou Mar 26, 2025
a563242
Fix regression test
lysnikolaou Mar 26, 2025
9f2d51f
Remove unnecessary dims array
lysnikolaou Mar 26, 2025
33109dd
Add release note
lysnikolaou Mar 28, 2025
dc362b4
Remove unnecessary branch from iter_subscript
lysnikolaou Mar 28, 2025
8255e5a
Add more benchmarks
lysnikolaou Mar 28, 2025
cfcdabf
Merge branch 'main' into use-prepare-index-flatiter
lysnikolaou Mar 28, 2025
368b404
Merge branch 'main' into use-prepare-index-flatiter
lysnikolaou Apr 23, 2025
ae101a5
Add special cases to fix performance regression
lysnikolaou Apr 23, 2025
e567311
Merge branch 'main' into use-prepare-index-flatiter
lysnikolaou Jul 16, 2025
3aa21b6
Address some feedback
lysnikolaou Jul 16, 2025
149dadd
Address more feedback
lysnikolaou Jul 16, 2025
4028768
Address more feedback; raise error on non-array index
lysnikolaou Jul 17, 2025
5319889
Fix linting errors
lysnikolaou Jul 17, 2025
50a6045
Update changelog item
lysnikolaou Jul 17, 2025
0aea49e
Fix tests
lysnikolaou Jul 17, 2025
8f87da2
Fix typing tests
lysnikolaou Jul 17, 2025
fa1540b
Address review feedback
lysnikolaou Jul 29, 2025
080d24d
Fix linter errors
lysnikolaou Jul 29, 2025
2559633
Address feedback
lysnikolaou Aug 6, 2025
e3630eb
Remove wrong comments
lysnikolaou Aug 6, 2025
4443708
Fix linting errors
lysnikolaou Aug 6, 2025
564f086
Fix test_deprecations
lysnikolaou Aug 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add special cases to fix performance regression
  • Loading branch information
lysnikolaou committed Apr 23, 2025
commit ae101a535e44d4cffa961b9251d4e21002dd21b0
43 changes: 25 additions & 18 deletions numpy/_core/src/multiarray/iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,31 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
npy_intp dtype_size = dtype->elsize;
NPY_cast_info cast_info = {.func = NULL};

if (PyTuple_Check(ind) && PyTuple_GET_SIZE(ind) == 0) {
Py_INCREF(self->ao);
return (PyObject *)self->ao;
}

if (PyBool_Check(ind)) {
int istrue = PyObject_IsTrue(ind);
if (istrue < 0) {
return NULL;
}

if (istrue) {
return PyArray_ToScalar(self->dataptr, self->ao);
}

npy_intp ii = 0;
Py_INCREF(dtype);
ret = PyArray_NewFromDescr(Py_TYPE(self->ao),
dtype,
1, &ii,
NULL, NULL, 0,
(PyObject *)self->ao);
return ret;
}

/* Prepare the indices */
index_type = prepare_index_noarray(1, &self->size, ind, indices, &index_num,
&ndim, &fancy_ndim, 1, 1);
Expand Down Expand Up @@ -601,24 +626,6 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
goto finish;
}

// Single boolean index
else if (indices[0].type == HAS_0D_BOOL) {
if (indices[0].value) {
ret = PyArray_ToScalar(self->dataptr, self->ao);
goto finish;
}
else { /* empty array */
npy_intp ii = 0;
Py_INCREF(dtype);
ret = PyArray_NewFromDescr(Py_TYPE(self->ao),
dtype,
1, &ii,
NULL, NULL, 0,
(PyObject *)self->ao);
goto finish;
}
}

PyArray_ITER_RESET(self);

if (index_type == HAS_INTEGER) {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy