8000 ENH: Suggest "ignore" mode for ravel_multi_index · Issue #15475 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Suggest "ignore" mode for ravel_multi_index #15475

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
lagru opened this issue Jan 30, 2020 · 3 comments
Open

ENH: Suggest "ignore" mode for ravel_multi_index #15475

lagru opened this issue Jan 30, 2020 · 3 comments

Comments

@lagru
Copy link
Contributor
lagru commented Jan 30, 2020

I'd like to suggest a new mode (maybe named "ignore") which treats multi_index as index offsets rather than direct positional indices meaning: out-of-bounds indices would be calculated as normal indices, neither wrapped nor clipped and returned without raising an exception.

Over at scikit-image/scikit-image#4209 (comment) we would have liked to use np.ravel_multi_index for a use case which is not (yet) supported. The new mode would have allowed us to adjust the multi_index corresponding to a structuring element by its center index and simply pass the result into ravel_multi_index to compute the offsets in question.

I am willing to give this a try myself but first wanted to check in with you. I haven't looked to deeply at the code dealing with this yet but my current understanding is that it may be enough to simply add a case that ignores j < 0 || j >= m to this switch statement.

@lagru
Copy link
Contributor Author
lagru commented Jan 31, 2020

Okay, I got it to work for ravel_multi_index by simply adding a new value NPY_IGNORE to the NPY_CLIPMODE enum. Unfortunately that enum is used elsewhere as well (e.g. numpy.take) where indices are actually used for indexing and out-of-bounds indices can't simply be treated as normal ones.

I'm not sure how to address this. Ideally the change would only affect ravel_multi_index. I doubt you'd be okay with adding another enum just for that function. The other option I see is to raise "clipmode not understood" for those functions if NPY_IGNORE is provided.

@eric-wieser
Copy link
Member

The other option I see is to raise "clipmode not understood" for those functions if NPY_IGNORE is provided.

I think "forbidden" would be more accurate than "not understood", but this approach (and the overall idea) seems fine to me.

@madphysicist
Copy link
Contributor
madphysicist commented Oct 16, 2022

Another mode which is missing is normal "indexing" mode: a mixture of wrap and raise that wraps negative indices up to -N and raises on anything outside [-N, N). There should be no issue with this given that the shape is known. @eric-wieser If you feel that this is worth a separate issue, I would be happy to open one. "indexing" mode might be useful for other functions that use he NPY_CLIPMODE enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0