You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array API specification for creating and operating on sets.
5
+
6
+
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
7
+
8
+
- 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.
9
+
- Optional parameters must be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments.
10
+
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
11
+
12
+
Objects in API
13
+
--------------
14
+
15
+
.. currentmodule:: signatures.set_functions
16
+
17
+
..
18
+
NOTE: please keep the functions in alphabetical order
Returns the unique elements of an input array ``x``, the first occurring indices for each unique element in ``x``, the indices from the set of unique elements that reconstruct ``x``, and the corresponding counts for each unique element in ``x``.
6
+
7
+
.. admonition:: Data-dependent output shape
8
+
:class: important
9
+
10
+
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.
11
+
12
+
.. note::
13
+
Uniqueness should be determined based on value equality (i.e., ``x_i == x_j``). For input arrays having floating-point data types, value-based equality implies the following behavior.
14
+
15
+
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
16
+
17
+
- 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``).
18
+
19
+
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.
20
+
21
+
Each ``nan`` value should have a count of one, while the counts for signed zeros should be aggregated as a single count.
22
+
23
+
Parameters
24
+
----------
25
+
x: array
26
+
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
27
+
28
+
Returns
29
+
-------
30
+
out: Tuple[array, array, array, array]
31
+
a namedtuple ``(values, indices, inverse_indices, counts)`` whose
32
+
33
+
- first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``.
34
+
- second element must have the field name ``indices`` and must be an array containing the indices (first occurrences) of ``x`` that result in ``values``. The array must have the same shape as ``values`` and must have the default array index data type.
35
+
- 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.
36
+
- 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 returned array must have same shape as ``values`` and must have the default array index data type.
37
+
38
+
.. note::
39
+
The order of unique elements is not specified and may vary between implementations.
Returns the unique elements of an input array ``x`` and the corresponding counts for each unique element in ``x``.
45
+
46
+
.. admonition:: Data-dependent output shape
47
+
:class: important
48
+
49
+
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.
50
+
51
+
.. note::
52
+
Uniqueness should be determined based on value equality (i.e., ``x_i == x_j``). For input arrays having floating-point data types, value-based equality implies the following behavior.
53
+
54
+
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
55
+
- 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``).
56
+
57
+
Each ``nan`` value should have a count of one, while the counts for signed zeros should be aggregated as a single count.
58
+
59
+
Parameters
60
+
----------
61
+
x: array
62
+
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
63
+
64
+
Returns
65
+
-------
66
+
out: Tuple[array, array]
67
+
a namedtuple `(values, counts)` whose
68
+
69
+
- first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``.
70
+
- 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 returned array must have same shape as ``values`` and must have the default array index data type.
71
+
72
+
.. note::
73
+
The order of unique elements is not specified and may vary between implementations.
Returns the unique elements of an input array ``x`` and the indices from the set of unique elements that reconstruct ``x``.
79
+
80
+
.. admonition:: Data-dependent output shape
81
+
:class: important
82
+
83
+
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.
84
+
85
+
.. note::
86
+
Uniqueness should be determined based on value equality (i.e., ``x_i == x_j``). For input arrays having floating-point data types, value-based equality implies the following behavior.
87
+
88
+
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
89
+
- 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``).
90
+
91
+
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.
92
+
93
+
Parameters
94
+
----------
95
+
x: array
96
+
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
97
+
98
+
Returns
99
+
-------
100
+
out: Tuple[array, array]
101
+
a namedtuple ``(values, inverse_indices)`` whose
102
+
103
+
- first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``.
104
+
- 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.
105
+
106
+
.. note::
107
+
The order of unique elements is not specified and may vary between implementations.
108
+
"""
109
+
110
+
defunique_values(x: array, /) ->array:
111
+
"""
112
+
Returns the unique elements of an input array ``x``.
113
+
114
+
.. admonition:: Data-dependent output shape
115
+
:class: important
116
+
117
+
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.
118
+
119
+
.. note::
120
+
Uniqueness should be determined based on value equality (i.e., ``x_i == x_j``). For input arrays having floating-point data types, value-based equality implies the following behavior.
121
+
122
+
- As ``nan`` values compare as ``False``, ``nan`` values should be considered distinct.
123
+
- 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``).
124
+
125
+
Parameters
126
+
----------
127
+
x: array
128
+
input array. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array.
129
+
130
+
Returns
131
+
-------
132
+
out: array
133
+
an array containing the set of unique elements in ``x``. The returned array must have the same data type as ``x``.
134
+
135
+
.. note::
136
+
The order of unique elements is not specified and may vary between implementations.
0 commit comments