Skip to content

Commit 25200b6

Browse files
authored
docs: move notes below the fold and highlight RFC 2119 keywords
PR-URL: #952 Ref: #397 Reviewed-by: Ralf Gommers <[email protected]>
1 parent 3267c18 commit 25200b6

File tree

1 file changed

+57
-65
lines changed

1 file changed

+57
-65
lines changed

src/array_api_stubs/_draft/set_functions.py

Lines changed: 57 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,38 @@ def unique_all(x: array, /) -> Tuple[array, array, array, array]:
1111
.. admonition:: Data-dependent output shape
1212
:class: important
1313
14-
The shapes of two of the output arrays for this function depend 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.
15-
16-
.. note::
17-
Uniqueness should be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
18-
19-
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
20-
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components should be considered distinct.
21-
- As ``-0`` and ``+0`` compare as ``True``, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return ``-0`` if ``-0`` occurs before ``+0``).
22-
23-
As signed zeros are not distinct, using ``inverse_indices`` to reconstruct the input array is not guaranteed to return an array having the exact same values.
24-
25-
Each ``nan`` value and each complex floating-point value having a ``nan`` component should have a count of one, while the counts for signed zeros should be aggregated as a single count.
14+
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, et cetera) can 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.
2615
2716
Parameters
2817
----------
2918
x: array
30-
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
19+
input array. If ``x`` has more than one dimension, the function **must** flatten ``x`` and return the unique elements of the flattened array.
3120
3221
Returns
3322
-------
3423
out: Tuple[array, array, array, array]
3524
a namedtuple ``(values, indices, inverse_indices, counts)`` whose
3625
37-
- first element must have the field name ``values`` and must be a one-dimensional array containing the unique elements of ``x``. The array must have the same data type as ``x``.
38-
- second element must have the field name ``indices`` and must be an array containing the indices (first occurrences) of a flattened ``x`` that result in ``values``. The array must have the same shape as ``values`` and must have the default array index data type.
39-
- third element must have the field name ``inverse_indices`` and must be an array containing the indices of ``values`` that reconstruct ``x``. The array must have the same shape as ``x`` and must have the default array index data type.
40-
- fourth element must have the field name ``counts`` and must be an array containing the number of times each unique element occurs in ``x``. The order of the returned counts must match the order of ``values``, such that a specific element in ``counts`` corresponds to the respective unique element in ``values``. The returned array must have same shape as ``values`` and must have the default array index data type.
41-
42-
.. note::
43-
The order of unique elements is not specified and may vary between implementations.
26+
- first element **must** have the field name ``values`` and **must** be a one-dimensional array containing the unique elements of ``x``. The array **must** have the same data type as ``x``.
27+
- second element **must** have the field name ``indices`` and **must** be an array containing the indices (first occurrences) of a flattened ``x`` that result in ``values``. The array **must** have the same shape as ``values`` and **must** have the default array index data type.
28+
- third element **must** have the field name ``inverse_indices`` and **must** be an array containing the indices of ``values`` that reconstruct ``x``. The array **must** have the same shape as ``x`` and **must** have the default array index data type.
29+
- fourth element **must** have the field name ``counts`` and **must** be an array containing the number of times each unique element occurs in ``x``. The order of the returned counts **must** match the order of ``values``, such that a specific element in ``counts`` corresponds to the respective unique element in ``values``. The returned array **must** have same shape as ``values`` and **must** have the default array index data type.
4430
4531
Notes
4632
-----
4733
34+
- The order of unique elements returned by this function is unspecified and thus implementation-defined. As a consequence, element order **may** vary between implementations.
35+
36+
- Uniqueness **should** be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
37+
38+
- As ``nan`` values compare as ``False``, ``nan`` values **should** be considered distinct.
39+
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components **should** be considered distinct.
40+
- As ``-0`` and ``+0`` compare as ``True``, signed zeros **should not** be considered distinct, and the corresponding unique element **may** be implementation-defined (e.g., an implementation **may** choose to return ``-0`` if ``-0`` occurs before ``+0``).
41+
42+
As signed zeros are not distinct, using ``inverse_indices`` to reconstruct the input array is not guaranteed to return an array having the exact same values.
43+
44+
Each ``nan`` value and each complex floating-point value having a ``nan`` component **should** have a count of one, while the counts for signed zeros **should** be aggregated as a single count.
45+
4846
.. versionchanged:: 2022.12
4947
Added complex data type support.
5048
@@ -60,36 +58,34 @@ def unique_counts(x: array, /) -> Tuple[array, array]:
6058
.. admonition:: Data-dependent output shape
6159
:class: important
6260
63-
The shapes of two of the output arrays for this function depend 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.
64-
65-
.. note::
66-
Uniqueness should be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
67-
68-
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
69-
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components should be considered distinct.
70-
- As ``-0`` and ``+0`` compare as ``True``, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return ``-0`` if ``-0`` occurs before ``+0``).
71-
72-
Each ``nan`` value and each complex floating-point value having a ``nan`` component should have a count of one, while the counts for signed zeros should be aggregated as a single count.
61+
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) can 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.
7362
7463
Parameters
7564
----------
7665
x: array
77-
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
66+
input array. If ``x`` has more than one dimension, the function **must** flatten ``x`` and return the unique elements of the flattened array.
7867
7968
Returns
8069
-------
8170
out: Tuple[array, array]
8271
a namedtuple `(values, counts)` whose
8372
84-
- first element must have the field name ``values`` and must be a one-dimensional array containing the unique elements of ``x``. The array must have the same data type as ``x``.
85-
- second element must have the field name `counts` and must be an array containing the number of times each unique element occurs in ``x``. The order of the returned counts must match the order of ``values``, such that a specific element in ``counts`` corresponds to the respective unique element in ``values``. The returned array must have same shape as ``values`` and must have the default array index data type.
86-
87-
.. note::
88-
The order of unique elements is not specified and may vary between implementations.
73+
- first element **must** have the field name ``values`` and **must** be a one-dimensional array containing the unique elements of ``x``. The array **must** have the same data type as ``x``.
74+
- second element **must** have the field name `counts` and **must** be an array containing the number of times each unique element occurs in ``x``. The order of the returned counts **must** match the order of ``values``, such that a specific element in ``counts`` corresponds to the respective unique element in ``values``. The returned array **must** have same shape as ``values`` and **must** have the default array index data type.
8975
9076
Notes
9177
-----
9278
79+
- The order of unique elements returned by this function is unspecified and thus implementation-defined. As a consequence, element order **may** vary between implementations.
80+
81+
- Uniqueness **should** be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
82+
83+
- As ``nan`` values compare as ``False``, ``nan`` values **should** be considered distinct.
84+
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components **should** be considered distinct.
85+
- As ``-0`` and ``+0`` compare as ``True``, signed zeros **should not** be considered distinct, and the corresponding unique element **may** be implementation-defined (e.g., an implementation **may** choose to return ``-0`` if ``-0`` occurs before ``+0``).
86+
87+
Each ``nan`` value and each complex floating-point value having a ``nan`` component **should** have a count of one, while the counts for signed zeros **should** be aggregated as a single count.
88+
9389
.. versionchanged:: 2022.12
9490
Added complex data type support.
9591
@@ -105,36 +101,34 @@ def unique_inverse(x: array, /) -> Tuple[array, array]:
105101
.. admonition:: Data-dependent output shape
106102
:class: important
107103
108-
The shapes of two of the output arrays for this function depend 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.
109-
110-
.. note::
111-
Uniqueness should be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
112-
113-
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
114-
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components should be considered distinct.
115-
- As ``-0`` and ``+0`` compare as ``True``, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return ``-0`` if ``-0`` occurs before ``+0``).
116-
117-
As signed zeros are not distinct, using ``inverse_indices`` to reconstruct the input array is not guaranteed to return an array having the exact same values.
104+
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) can 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.
118105
119106
Parameters
120107
----------
121108
x: array
122-
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
109+
input array. If ``x`` has more than one dimension, the function **must** flatten ``x`` and return the unique elements of the flattened array.
123110
124111
Returns
125112
-------
126113
out: Tuple[array, array]
127114
a namedtuple ``(values, inverse_indices)`` whose
128115
129-
- first element must have the field name ``values`` and must be a one-dimensional array containing the unique elements of ``x``. The array must have the same data type as ``x``.
130-
- second element must have the field name ``inverse_indices`` and must be an array containing the indices of ``values`` that reconstruct ``x``. The array must have the same shape as ``x`` and have the default array index data type.
131-
132-
.. note::
133-
The order of unique elements is not specified and may vary between implementations.
116+
- first element **must** have the field name ``values`` and **must** be a one-dimensional array containing the unique elements of ``x``. The array **must** have the same data type as ``x``.
117+
- second element **must** have the field name ``inverse_indices`` and **must** be an array containing the indices of ``values`` that reconstruct ``x``. The array **must** have the same shape as ``x`` and have the default array index data type.
134118
135119
Notes
136120
-----
137121
122+
- The order of unique elements returned by this function is unspecified and thus implementation-defined. As a consequence, element order **may** vary between implementations.
123+
124+
- Uniqueness **should** be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
125+
126+
- As ``nan`` values compare as ``False``, ``nan`` values **should** be considered distinct.
127+
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components **should** be considered distinct.
128+
- As ``-0`` and ``+0`` compare as ``True``, signed zeros **should not** be considered distinct, and the corresponding unique element **may** be implementation-defined (e.g., an implementation **may** choose to return ``-0`` if ``-0`` occurs before ``+0``).
129+
130+
As signed zeros are not distinct, using ``inverse_indices`` to reconstruct the input array is not guaranteed to return an array having the exact same values.
131+
138132
.. versionchanged:: 2022.12
139133
Added complex data type support.
140134
@@ -150,31 +144,29 @@ def unique_values(x: array, /) -> array:
150144
.. admonition:: Data-dependent output shape
151145
:class: important
152146
153-
The shapes of two of the output arrays for this function depend 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.
154-
155-
.. note::
156-
Uniqueness should be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
157-
158-
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
159-
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components should be considered distinct.
160-
- As ``-0`` and ``+0`` compare as ``True``, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return ``-0`` if ``-0`` occurs before ``+0``).
147+
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) can 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.
161148
162149
Parameters
163150
----------
164151
x: array
165-
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
152+
input array. If ``x`` has more than one dimension, the function **must** flatten ``x`` and return the unique elements of the flattened array.
166153
167154
Returns
168155
-------
169156
out: array
170-
a one-dimensional array containing the set of unique elements in ``x``. The returned array must have the same data type as ``x``.
171-
172-
.. note::
173-
The order of unique elements is not specified and may vary between implementations.
157+
a one-dimensional array containing the set of unique elements in ``x``. The returned array **must** have the same data type as ``x``.
174158
175159
Notes
176160
-----
177161
162+
- The order of unique elements returned by this function is unspecified and thus implementation-defined. As a consequence, element order **may** vary between implementations.
163+
164+
- Uniqueness **should** be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior.
165+
166+
- As ``nan`` values compare as ``False``, ``nan`` values **should** be considered distinct.
167+
- As complex floating-point values having at least one ``nan`` component compare as ``False``, complex floating-point values having ``nan`` components **should** be considered distinct.
168+
- As ``-0`` and ``+0`` compare as ``True``, signed zeros **should not** be considered distinct, and the corresponding unique element **may** be implementation-defined (e.g., an implementation **may** choose to return ``-0`` if ``-0`` occurs before ``+0``).
169+
178170
.. versionchanged:: 2022.12
179171
Added complex data type support.
180172

0 commit comments

Comments
 (0)