You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: Suggest "ignore" mode for ravel_multi_index #15475
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.
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.
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.
Activity
lagru commentedon Jan 31, 2020
Okay, I got it to work for
ravel_multi_indexby simply adding a new valueNPY_IGNOREto theNPY_CLIPMODEenum. 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 ifNPY_IGNOREis provided.eric-wieser commentedon Jan 31, 2020
I think "forbidden" would be more accurate than "not understood", but this approach (and the overall idea) seems fine to me.
madphysicist commentedon Oct 16, 2022
Another mode which is missing is normal "indexing" mode: a mixture of wrap and raise that wraps negative indices up to
-Nand 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 heNPY_CLIPMODEenum.