RFC: add take_along_axis
to take values along a specified dimension
#808
Labels
API extension
Adds new functions or objects to the API.
Needs Discussion
Needs further discussion.
RFC
Request for comments. Feature requests and proposed changes.
topic: Indexing
Array indexing.
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: