Skip to content

Commit d5d7c6c

Browse files
authored
Add take specification for returning elements of an array along a specified axis (#416)
1 parent 7a92139 commit d5d7c6c

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

spec/API_specification/array_api/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .data_type_functions import *
55
import array_api.data_types as dtype
66
from .elementwise_functions import *
7+
from .indexing_functions import *
78
from .linear_algebra_functions import *
89
from .manipulation_functions import *
910
from .searching_functions import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from ._types import Union, array
2+
3+
def take(x: array, indices: array, /, *, axis: int) -> array:
4+
"""
5+
Returns elements of an array along an axis.
6+
7+
.. note::
8+
Conceptually, ``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.
9+
10+
Parameters
11+
----------
12+
x: array
13+
input array.
14+
indices: array
15+
array indices. The array must be one-dimensional and have an integer data type.
16+
axis: int
17+
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.
18+
19+
If ``x`` is a one-dimensional array, providing an ``axis`` is optional; however, if ``x`` has more than one dimension, providing an ``axis`` is required.
20+
21+
Returns
22+
-------
23+
out: array
24+
an array having the same data type as ``x``. 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``.
25+
"""
26+
27+
__all__ = ['take']

spec/API_specification/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ API specification
1616
elementwise_functions
1717
function_and_method_signatures
1818
indexing
19+
indexing_functions
1920
linear_algebra_functions
2021
manipulation_functions
2122
searching_functions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _indexing-functions:
2+
3+
Indexing Functions
4+
===================
5+
6+
Array API specification for functions for indexing arrays.
7+
8+
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
9+
10+
- 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.
11+
- Optional parameters must be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments.
12+
- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
13+
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
14+
- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
15+
16+
Objects in API
17+
--------------
18+
19+
.. currentmodule:: array_api
20+
21+
..
22+
NOTE: please keep the functions in alphabetical order
23+
24+
.. autosummary::
25+
:toctree: generated
26+
:template: method.rst
27+
28+
take

0 commit comments

Comments
 (0)