-
Notifications
You must be signed in to change notification settings - Fork 52
RFC: add take_along_axis
to take values along a specified dimension
#808
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
Comments
Thanks @kgryte
That makes perfect sense to me. The
Looks like a good choice to me.
That's consistent with the rest of the design, so I don't see a problem here. |
It's used quite rarely at least in SciPy and scikit-learn, and it's fairly new even in NumPy (1.15.0). It looks like there's enough justification for adding |
While Regardless, I've updated the OP with some additional justification. Namely, replicating |
@kgryte The documentation states that "The behavior for out-of-bounds indices is left unspecified.", but I do understand correctly that some negative indices are in bounds as described in Single-axis indexing?? |
@mdhaber Yes, we need to update the spec to explicitly include language for allowing negative indices, as done elsewhere for other APIs. |
This RFC proposes the addition of a new API in the array API specification for taking values from an input array by matching one-dimensional index and data slices.
Overview
Based on array comparison data, the API is available across most major array libraries in the PyData ecosystem.
take_along_axis
was previously discussed in #177 as a potential standardization candidate and has been mentioned in downstream usage. As indexing with multidimensional integer arrays (see #669) is not yet supported in the specification, the specification lacks a means to concisely select multiple values along multiple one-dimensional slices. This RFC aims to fill this gap.Additionally, even with advanced indexing, replicating
take_along_axis
is more verbose and trickier to get right. For example, considerTo replicate with advanced indexing,
where we need to create an integer index (with expanded dimensions) for the first dimension, which can then be broadcast against the integer index
indices
. Especially for higher order dimensions, replication oftake_along_axis
becomes even more verbose. E.g., for a 3-dimensional array,In general, while "advanced indexing" can be used for replicating
take_along_axis
, doing so is less ergonomic and has a higher likelihood of mistakes.Prior art
np.take_along_axis
in their documentation numpy/numpy#6078take_along_dim
, rather thantake_along_axis
mode
andfill
kwargsProposal
Notes
Questions
axis
to beNone
in order to indicate that the input arrayx
should be flattened prior to indexing. This allows consistency with NumPy'ssort
andargsort
functions. However, the specification forsort
andargsort
does not supportNone
(i.e., flattening). Accordingly, this RFC does not propose supportingaxis=None
. Are we okay with this?x
andindices
positional-only and allowsaxis
to be both positional or keyword. Any concerns?take_along_dim
astake_along_axis
anddim
asaxis
to ensure spec compliance?The text was updated successfully, but these errors were encountered: