Skip to content

Commit 533e693

Browse files
steff456kgryte
andauthored
PR: Transform searching functions md to rst (#368)
* Transform searching functions md to rst * Fix typo * Lowercase first sentence to ensure consistency with rest of spec This commit addresses an oversight in the specification prior to Markdown to rST conversion. Co-authored-by: Athan <[email protected]>
1 parent 36c6b75 commit 533e693

File tree

3 files changed

+110
-115
lines changed

3 files changed

+110
-115
lines changed

spec/API_specification/searching_functions.md

-115
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _searching-functions:
2+
3+
Searching Functions
4+
===================
5+
6+
Array API specification for functions for searching 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:: signatures.searching_functions
20+
21+
..
22+
NOTE: please keep the functions in alphabetical order
23+
24+
.. autosummary::
25+
:toctree: generated
26+
27+
argmax
28+
argmin
29+
nonzero
30+
where
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from ._types import Optional, Tuple, array
2+
3+
def argmax(x: array, /, *, axis: Optional[int] = None, keepdims: bool = False) -> array:
4+
"""
5+
Returns the indices of the maximum values along a specified axis. When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
6+
7+
Parameters
8+
----------
9+
x: array
10+
input array. Should have a numeric data type.
11+
axis: Optional[int]
12+
axis along which to search. If ``None``, the function must return the index of the maximum value of the flattened array. Default: ``None``.
13+
keepdims: bool
14+
if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``.
15+
16+
Returns
17+
-------
18+
out: array
19+
if ``axis`` is ``None``, a zero-dimensional array containing the index of the first occurrence of the maximum value; otherwise, a non-zero-dimensional array containing the indices of the maximum values. The returned array must have be the default array index data type.
20+
"""
21+
22+
def argmin(x: array, /, *, axis: Optional[int] = None, keepdims: bool = False) -> array:
23+
"""
24+
Returns the indices of the minimum values along a specified axis. When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
25+
26+
Parameters
27+
----------
28+
x: array
29+
input array. Should have a numeric data type.
30+
axis: Optional[int]
31+
axis along which to search. If ``None``, the function must return the index of the minimum value of the flattened array. Default: ``None``.
32+
keepdims: bool
33+
if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``.
34+
35+
Returns
36+
-------
37+
out: array
38+
if ``axis`` is ``None``, a zero-dimensional array containing the index of the first occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. The returned array must have the default array index data type.
39+
"""
40+
41+
def nonzero(x: array, /) -> Tuple[array, ...]:
42+
"""
43+
Returns the indices of the array elements which are non-zero.
44+
45+
.. admonition:: Data-dependent output shape
46+
:class: admonition important
47+
48+
The shape of the output array for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See :ref:`data-dependent-output-shapes` section for more details.
49+
50+
Parameters
51+
----------
52+
x: array
53+
input array. Must have a positive rank. If ``x`` is zero-dimensional, the function must raise an exception.
54+
55+
Returns
56+
-------
57+
out: Typle[array, ...]
58+
a tuple of ``k`` arrays, one for each dimension of ``x`` and each of size ``n`` (where ``n`` is the total number of non-zero elements), containing the indices of the non-zero elements in that dimension. The indices must be returned in row-major, C-style order. The returned array must have the default array index data type.
59+
"""
60+
61+
def where(condition: array, x1: array, x2: array, /) -> array:
62+
"""
63+
Returns elements chosen from ``x1`` or ``x2`` depending on ``condition``.
64+
65+
Parameters
66+
----------
67+
condition: array
68+
when ``True``, yield ``x1_i``; otherwise, yield ``x2_i``. Must be compatible with ``x1`` and ``x2`` (see :ref:`broadcasting`).
69+
x1: array
70+
first input array. Must be compatible with ``condition`` and ``x2`` (see :ref:`broadcasting`).
71+
x2: array
72+
second input array. Must be compatible with ``condition`` and ``x1`` (see :ref:`broadcasting`).
73+
74+
Returns
75+
-------
76+
out: array
77+
an array with elements from ``x1`` where ``condition`` is ``True``, and elements from ``x2`` elsewhere. The returned array must have a data type determined by :ref:`type-promotion` rules with the arrays ``x1`` and ``x2``.
78+
"""
79+
80+
__all__ = ['argmax', 'argmin', 'nonzero', 'where']

0 commit comments

Comments
 (0)