Skip to content

Commit e906ba8

Browse files
authored
docs: move notes below the fold and highlight RFC 2119 keywords
PR-URL: #942 Ref: #397
1 parent e52f6ba commit e906ba8

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

src/array_api_stubs/_draft/searching_functions.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ def argmax(x: array, /, *, axis: Optional[int] = None, keepdims: bool = False) -
1010
1111
When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
1212
13-
.. note::
14-
For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
15-
1613
Parameters
1714
----------
1815
x: array
19-
input array. Should have a real-valued data type.
16+
input array. **Should** have a real-valued data type.
2017
axis: Optional[int]
21-
axis along which to search. If ``None``, the function must return the index of the maximum value of the flattened array. Default: ``None``.
18+
axis along which to search. If ``None``, the function **must** return the index of the maximum value of the flattened array. If not ``None``, a valid axis **must** be an integer on the interval ``[-N, N)``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the function **must** determine the axis along which to perform the operation by counting backward from the last axis (where ``-1`` refers to the last axis). If provided an invalid axis, the function **must** raise an exception. Default: ``None``.
2219
keepdims: bool
23-
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``.
20+
if ``True``, the reduced axes **must** be included in the result as singleton dimensions, and, accordingly, the result **must** be broadcast-compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes **must not** be included in the result. Default: ``False``.
2421
2522
Returns
2623
-------
2724
out: array
28-
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.
25+
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.
26+
27+
Notes
28+
-----
29+
30+
- For backward compatibility, conforming implementations **may** support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
2931
"""
3032

3133

@@ -35,22 +37,24 @@ def argmin(x: array, /, *, axis: Optional[int] = None, keepdims: bool = False) -
3537
3638
When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
3739
38-
.. note::
39-
For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
40-
4140
Parameters
4241
----------
4342
x: array
44-
input array. Should have a real-valued data type.
43+
input array. **Should** have a real-valued data type.
4544
axis: Optional[int]
46-
axis along which to search. If ``None``, the function must return the index of the minimum value of the flattened array. Default: ``None``.
45+
axis along which to search. If ``None``, the function **must** return the index of the minimum value of the flattened array. If not ``None``, a valid axis **must** be an integer on the interval ``[-N, N)``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the function **must** determine the axis along which to perform the operation by counting backward from the last axis (where ``-1`` refers to the last axis). If provided an invalid axis, the function **must** raise an exception. Default: ``None``.
4746
keepdims: bool
48-
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``.
47+
if ``True``, the reduced axes **must** be included in the result as singleton dimensions, and, accordingly, the result **must** be broadcast-compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes **must not** be included in the result. Default: ``False``.
4948
5049
Returns
5150
-------
5251
out: array
53-
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.
52+
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.
53+
54+
Notes
55+
-----
56+
57+
- For backward compatibility, conforming implementations **may** support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
5458
"""
5559

5660

@@ -69,14 +73,14 @@ def count_nonzero(
6973
x: array
7074
input array.
7175
axis: Optional[Union[int, Tuple[int, ...]]]
72-
axis or axes along which to count non-zero values. By default, the number of non-zero values must be computed over the entire array. If a tuple of integers, the number of non-zero values must be computed over multiple axes. Default: ``None``.
76+
axis or axes along which to count non-zero values. By default, the number of non-zero values must be computed over the entire array. If a tuple of integers, the number of non-zero values must be computed over multiple axes. A valid axis **must** be an integer on the interval ``[-N, N)``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the function **must** determine the axis along which to perform the operation by counting backward from the last axis (where ``-1`` refers to the last axis). If provided an invalid axis, the function **must** raise an exception. Default: ``None``.
7377
keepdims: bool
74-
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``.
78+
if ``True``, the reduced axes **must** be included in the result as singleton dimensions, and, accordingly, the result **must** be broadcast-compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes **must not** be included in the result. Default: ``False``.
7579
7680
Returns
7781
-------
7882
out: array
79-
if the number of non-zeros values was computed over the entire array, a zero-dimensional array containing the total number of non-zero values; otherwise, a non-zero-dimensional array containing the counts along the specified axes. The returned array must have the default array index data type.
83+
if the number of non-zeros values was computed over the entire array, a zero-dimensional array containing the total number of non-zero values; otherwise, a non-zero-dimensional array containing the counts along the specified axes. The returned array **must** have the default array index data type.
8084
8185
Notes
8286
-----
@@ -100,12 +104,12 @@ def nonzero(x: array, /) -> Tuple[array, ...]:
100104
Parameters
101105
----------
102106
x: array
103-
input array. Must have a positive rank. If ``x`` is zero-dimensional, the function must raise an exception.
107+
input array. **Must** have one or more dimensions. If ``x`` is zero-dimensional, the function **must** raise an exception.
104108
105109
Returns
106110
-------
107111
out: Tuple[array, ...]
108-
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.
112+
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.
109113
110114
Notes
111115
-----
@@ -132,36 +136,35 @@ def searchsorted(
132136
Parameters
133137
----------
134138
x1: array
135-
input array. Must be a one-dimensional array. Should have a real-valued data type. If ``sorter`` is ``None``, must be sorted in ascending order; otherwise, ``sorter`` must be an array of indices that sort ``x1`` in ascending order.
139+
input array. **Must** be a one-dimensional array. **Should** have a real-valued data type. If ``sorter`` is ``None``, **must** be sorted in ascending order; otherwise, ``sorter`` **must** be an array of indices that sort ``x1`` in ascending order.
136140
x2: array
137-
array containing search values. Should have a real-valued data type.
141+
array containing search values. **Should** have a real-valued data type.
138142
side: Literal['left', 'right']
139143
argument controlling which index is returned if a value lands exactly on an edge.
140144
141145
Let ``v`` be an element of ``x2`` given by ``v = x2[j]``, where ``j`` refers to a valid index (see :ref:`indexing`).
142146
143-
- If ``v`` is less than all elements in ``x1``, then ``out[j]`` must be ``0``.
144-
- If ``v`` is greater than all elements in ``x1``, then ``out[j]`` must be ``M``, where ``M`` is the number of elements in ``x1``.
145-
- Otherwise, each returned index ``i = out[j]`` must satisfy an index condition:
147+
- If ``v`` is less than all elements in ``x1``, then ``out[j]`` **must** be ``0``.
148+
- If ``v`` is greater than all elements in ``x1``, then ``out[j]`` **must** be ``M``, where ``M`` is the number of elements in ``x1``.
149+
- Otherwise, each returned index ``i = out[j]`` **must** satisfy an index condition:
146150
147151
- If ``side == 'left'``, then ``x1[i-1] < v <= x1[i]``.
148152
- If ``side == 'right'``, then ``x1[i-1] <= v < x1[i]``.
149153
150154
Default: ``'left'``.
151155
sorter: Optional[array]
152-
array of indices that sort ``x1`` in ascending order. The array must have the same shape as ``x1`` and have an integer data type. Default: ``None``.
156+
array of indices that sort ``x1`` in ascending order. The array **must** have the same shape as ``x1`` and have an integer data type. Default: ``None``.
153157
154158
Returns
155159
-------
156160
out: array
157-
an array of indices with the same shape as ``x2``. The returned array must have the default array index data type.
161+
an array of indices with the same shape as ``x2``. The returned array **must** have the default array index data type.
158162
159163
Notes
160164
-----
161165
162-
For real-valued floating-point arrays, the sort order of NaNs and signed zeros is unspecified and thus implementation-dependent. Accordingly, when a real-valued floating-point array contains NaNs and signed zeros, what constitutes ascending order may vary among specification-conforming array libraries.
163-
164-
While behavior for arrays containing NaNs and signed zeros is implementation-dependent, specification-conforming libraries should, however, ensure consistency with ``sort`` and ``argsort`` (i.e., if a value in ``x2`` is inserted into ``x1`` according to the corresponding index in the output array and ``sort`` is invoked on the resultant array, the sorted result should be an array in the same order).
166+
- For real-valued floating-point arrays, the sort order of NaNs and signed zeros is unspecified and thus implementation-dependent. Accordingly, when a real-valued floating-point array contains NaNs and signed zeros, what constitutes ascending order **may** vary among specification-conforming array libraries.
167+
- While behavior for arrays containing NaNs and signed zeros is implementation-dependent, specification-conforming libraries **should**, however, ensure consistency with ``sort`` and ``argsort`` (i.e., if a value in ``x2`` is inserted into ``x1`` according to the corresponding index in the output array and ``sort`` is invoked on the resultant array, the sorted result **should** be an array in the same order).
165168
166169
.. versionadded:: 2023.12
167170
@@ -182,22 +185,22 @@ def where(
182185
Parameters
183186
----------
184187
condition: array
185-
when ``True``, yield ``x1_i``; otherwise, yield ``x2_i``. Should have a boolean data type. Must be compatible with ``x1`` and ``x2`` (see :ref:`broadcasting`).
188+
when ``True``, yield ``x1_i``; otherwise, yield ``x2_i``. **Should** have a boolean data type. **Must** be broadcast-compatible with ``x1`` and ``x2`` (see :ref:`broadcasting`).
186189
x1: Union[array, int, float, complex, bool]
187-
first input array. Must be compatible with ``condition`` and ``x2`` (see :ref:`broadcasting`).
190+
first input array. **Must** be broadcast-compatible with ``condition`` and ``x2`` (see :ref:`broadcasting`).
188191
x2: Union[array, int, float, complex, bool]
189-
second input array. Must be compatible with ``condition`` and ``x1`` (see :ref:`broadcasting`).
192+
second input array. **Must** be broadcast-compatible with ``condition`` and ``x1`` (see :ref:`broadcasting`).
190193
191194
Returns
192195
-------
193196
out: array
194-
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``.
197+
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``.
195198
196199
Notes
197200
-----
198201
199-
- At least one of ``x1`` and ``x2`` must be an array.
200-
- If either ``x1`` or ``x2`` is a scalar value, the returned array must have a data type determined according to :ref:`mixing-scalars-and-arrays`.
202+
- At least one of ``x1`` and ``x2`` **must** be an array.
203+
- If either ``x1`` or ``x2`` is a scalar value, the returned array **must** have a data type determined according to :ref:`mixing-scalars-and-arrays`.
201204
202205
.. versionchanged:: 2024.12
203206
Added scalar argument support.

0 commit comments

Comments
 (0)