Skip to content

Commit f9f9bc4

Browse files
authored
Split unique into separate functions (#275)
* Split `unique` into separate functions * Update copy * Fix shape guidance * Add notes * Rename function to avoid breaking backward compat * Specify the `values` array data type
1 parent e8fc612 commit f9f9bc4

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

spec/API_specification/set_functions.md

+56-22
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ A conforming implementation of the array API standard must provide and support t
1212

1313
<!-- NOTE: please keep the functions in alphabetical order -->
1414

15-
(function-unique)=
16-
### unique(x, /, *, return_counts=False, return_index=False, return_inverse=False)
15+
(function-unique-all)=
16+
### unique_all(x, /)
1717

1818
:::{admonition} Data-dependent output shape
1919
:class: important
2020

21-
The shapes of one or more of 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.
21+
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.
2222
:::
2323

2424
Returns the unique elements of an input array `x`.
@@ -29,40 +29,74 @@ Returns the unique elements of an input array `x`.
2929

3030
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
3131

32-
- **return_counts**: _bool_
32+
#### Returns
33+
34+
- **out**: _Tuple\[ &lt;array&gt;, &lt;array&gt;, &lt;array&gt;, &lt;array&gt; ]_
3335

34-
- If `True`, the function must also return the number of times each unique element occurs in `x`. Default: `False`.
36+
- a namedtuple `(values, indices, inverse_indices, counts)` whose
3537

36-
- **return_index**: _bool_
38+
- 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`.
39+
- 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 integer data type.
40+
- 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 integer data type.
41+
- 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 integer data type.
3742

38-
- If `True`, the function must also return the indices (first occurrences) of `x` that result in the unique array. Default: `False`.
43+
```{note}
44+
The order of unique elements is not specified and may vary between implementations.
45+
```
3946
40-
- **return_inverse**: _bool_
47+
(function-unique-inverse)=
48+
### unique_inverse(x, /)
4149
42-
- If `True`, the function must also return the indices of the unique array that reconstruct `x`. Default: `False`.
50+
Returns the unique elements of an input array `x` and the indices from the set of unique elements that reconstruct `x`.
51+
52+
:::{admonition} Data-dependent output shape
53+
:class: important
54+
55+
The shape of one of the output arrays 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.
56+
:::
57+
58+
#### Parameters
59+
60+
- **x**: _&lt;array&gt;_
61+
62+
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
4363
4464
#### Returns
4565
46-
- **out**: _Union\[ &lt;array&gt;, Tuple\[ &lt;array&gt;, ... ] ]_
66+
- **out**: _Tuple\[ &lt;array&gt;, &lt;array&gt; ]_
4767
48-
- if `return_counts`, `return_index`, and `return_inverse` are all `False`, an array containing the set of unique elements in `x`; otherwise, a tuple containing two or more of the following arrays (in order):
68+
- a namedtuple `(values, inverse_indices)` whose
4969
50-
- **unique**: _&lt;array&gt;_
70+
- 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`.
71+
- 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 integer data type.
5172
52-
- an array containing the set of unique elements in `x`. The returned array must have the same data type as `x`.
73+
```{note}
74+
The order of unique elements is not specified and may vary between implementations.
75+
```
5376
54-
```{note}
55-
The order of elements is not specified, and may vary between implementations.
56-
```
77+
(function-unique-values)=
78+
### unique_values(x, /)
5779
58-
- **indices**: _&lt;array&gt;_
80+
:::{admonition} Data-dependent output shape
81+
:class: important
82+
83+
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.
84+
:::
85+
86+
Returns the unique elements of an input array `x`.
5987
60-
- an array containing the indices (first occurrences) of `x` that result in `unique`. The returned array must have the default integer data type.
88+
#### Parameters
89+
90+
- **x**: _&lt;array&gt;_
6191
62-
- **inverse**: _&lt;array&gt;_
92+
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
93+
94+
#### Returns
6395
64-
- an array containing the indices of `unique` that reconstruct `x`. The returned array must have the default integer data type.
96+
- **out**: _&lt;array&gt;_
6597
66-
- **counts**: _&lt;array&gt;_
98+
- an array containing the set of unique elements in `x`. The returned array must have the same data type as `x`.
6799
68-
- an array containing the number of times each unique element occurs in `x`. The returned array must have the default integer data type.
100+
```{note}
101+
The order of unique elements is not specified and may vary between implementations.
102+
```

0 commit comments

Comments
 (0)