Skip to content

Commit e3e1a46

Browse files
authored
Require that NaNs be considered distinct when returning unique elements (#310)
* Require that NaNs be considered distinct * Update copy
1 parent d7df6ae commit e3e1a46

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

spec/API_specification/set_functions.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ The shapes of two of the output arrays for this function depend on the data valu
2323

2424
Returns the unique elements of an input array `x`.
2525

26+
```{note}
27+
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.
28+
29+
- As `nan` values compare as `False`, `nan` values should be considered distinct.
30+
- 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`).
31+
32+
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.
33+
34+
Each `nan` value should have a count of one, while the counts for signed zeros should be aggregated as a single count.
35+
```
36+
2637
#### Parameters
2738

2839
- **x**: _<array>_
@@ -47,14 +58,23 @@ Returns the unique elements of an input array `x`.
4758
(function-unique-inverse)=
4859
### unique_inverse(x, /)
4960
50-
Returns the unique elements of an input array `x` and the indices from the set of unique elements that reconstruct `x`.
51-
5261
:::{admonition} Data-dependent output shape
5362
:class: important
5463
5564
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.
5665
:::
5766
67+
Returns the unique elements of an input array `x` and the indices from the set of unique elements that reconstruct `x`.
68+
69+
```{note}
70+
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.
71+
72+
- As `nan` values compare as `False`, `nan` values should be considered distinct.
73+
- 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`).
74+
75+
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.
76+
```
77+
5878
#### Parameters
5979

6080
- **x**: _<array>_
@@ -85,6 +105,13 @@ The shape of the output array for this function depends on the data values in th
85105
86106
Returns the unique elements of an input array `x`.
87107
108+
```{note}
109+
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.
110+
111+
- As `nan` values compare as `False`, `nan` values should be considered distinct.
112+
- 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`).
113+
```
114+
88115
#### Parameters
89116

90117
- **x**: _<array>_

0 commit comments

Comments
 (0)