-
Notifications
You must be signed in to change notification settings - Fork 53
Add take
specification for returning elements of an array along a specified axis
#416
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
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
250d38f
Add `take` specification
kgryte 2b9484b
Update copy
kgryte 5f09307
Update index
kgryte 370675b
Clarify behavior when provided a zero-dimensional array
kgryte 187af16
Merge branch 'main' of https://github.com/pydata-apis/array-api into …
kgryte 915c026
Rephrase description and add guidance concerning when `axis` is required
kgryte ff155cc
Fix module
kgryte 0024b6a
Fix missing import
kgryte b14151a
Remove support for providing an integer for the `indices` kwarg
kgryte 0c45cfd
Merge branch 'main' of https://github.com/pydata-apis/array-api into …
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. _indexing-functions: | ||
|
||
Indexing Functions | ||
=================== | ||
|
||
Array API specification for functions for indexing arrays. | ||
|
||
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions. | ||
|
||
- Positional parameters must be `positional-only <https://www.python.org/dev/peps/pep-0570/>`_ parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order. | ||
- Optional parameters must be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments. | ||
- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`. | ||
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`. | ||
- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`. | ||
|
||
Objects in API | ||
-------------- | ||
|
||
.. currentmodule:: signatures.indexing_functions | ||
|
||
.. | ||
NOTE: please keep the functions in alphabetical order | ||
|
||
.. autosummary:: | ||
:toctree: generated | ||
:template: method.rst | ||
|
||
take |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from ._types import Union, array | ||
|
||
def take(x: array, indices: Union[int, array], /, *, axis: int) -> array: | ||
""" | ||
Returns elements of an array along an axis. | ||
|
||
.. note:: | ||
Conceptually, the call ``take(x, indices, axis=3)`` is equivalent to ``x[:,:,:,indices,...]``; however, explicit indexing via arrays of indices is not currently supported in this specification due to concerns regarding ``__setitem__`` and array mutation semantics. | ||
|
||
Parameters | ||
---------- | ||
x: array | ||
input array. | ||
indices: Union[int, array] | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
array indices. If ``indices`` is an integer (or a zero-dimensional array satisfying ``operator.index``), the function must follow multi-axis indexing semantics when providing an integer for a single-axis index (see :ref:`indexing`). If ``indices`` is a non-zero-dimensional array, the array must be one-dimensional and have an integer data type. | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
axis: int | ||
axis over which to select values. If ``axis`` is negative, the function must determine the axis along which to select values by counting from the last dimension. | ||
|
||
Returns | ||
------- | ||
out: array | ||
an array having the same data type as ``x``. If ``indices`` is an array, the output array must have the same rank (i.e., number of dimensions) as ``x`` and must have the same shape as ``x``, except for the axis specified by ``axis`` whose size must equal the number of elements in ``indices``. If ``indices`` is an integer, the output array must have one less dimension than ``x`` (i.e., the array rank should decrease by one). In particular, if ``x`` has rank ``N``, when ``indices`` is an integer, this function must be equivalent to a selection tuple (e.g., ``x[:,:,3,:]``, ``x[0,:]``, et cetera) with the ``m``\th element an integer (and all other entries ``:``), thus indexing a sub-array with rank ``N-1``. | ||
|
||
.. note:: | ||
When ``indices`` is an integer and ``x`` is an array of rank ``1``, the returned array must be an array of rank ``0``, not a scalar. | ||
""" | ||
|
||
__all__ = ['take'] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.