Skip to content

Commit 527248c

Browse files
author
Raghuveer Devulapalli
authored
Merge pull request #73 from zbjornson/zb/nan-readme
Correct documentation on NaN behavior
2 parents 1b39637 + da2a84a commit 527248c

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,55 @@ relative to std::sort. The following API's are currently supported:
1010

1111
#### Quicksort
1212

13-
```
13+
```cpp
1414
void avx512_qsort<T>(T* arr, int64_t arrsize)
1515
```
16-
Supported datatypes: `uint16_t, int16_t, _Float16, uint32_t, int32_t, float,
17-
uint64_t, int64_t and double`
16+
Supported datatypes: `uint16_t`, `int16_t`, `_Float16`, `uint32_t`, `int32_t`,
17+
`float`, `uint64_t`, `int64_t` and `double`.
18+
19+
For floating-point types, if `arr` contains NaNs, they are moved to the end and
20+
replaced with a quiet NaN. That is, the original, bit-exact NaNs in the input
21+
are not preserved.
1822

1923
#### Argsort
2024

21-
```
25+
```cpp
2226
std::vector<int64_t> arg = avx512_argsort<T>(T* arr, int64_t arrsize)
2327
void avx512_argsort<T>(T* arr, int64_t *arg, int64_t arrsize)
2428
```
25-
Supported datatypes: `uint32_t, int32_t, float, uint64_t, int64_t and double`.
26-
The algorithm resorts to scalar `std::sort` if the array contains NAN.
29+
Supported datatypes: `uint32_t`, `int32_t`, `float`, `uint64_t`, `int64_t` and
30+
`double`.
31+
32+
The algorithm resorts to scalar `std::sort` if the array contains NaNs.
2733

2834
#### Quickselect
2935

30-
```
36+
```cpp
3137
void avx512_qselect<T>(T* arr, int64_t arrsize)
3238
void avx512_qselect<T>(T* arr, int64_t arrsize, bool hasnan)
3339
```
34-
Supported datatypes: `uint16_t, int16_t, _Float16 ,uint32_t, int32_t, float,
35-
uint64_t, int64_t and double`. Use an additional optional argument `bool
36-
hasnan` if you expect your arrays to contain nan.
40+
Supported datatypes: `uint16_t`, `int16_t`, `_Float16`, `uint32_t`, `int32_t`,
41+
`float`, `uint64_t`, `int64_t` and `double`.
42+
43+
For floating-point types, if `bool hasnan` is set, NaNs are moved to the end of
44+
the array, preserving the bit-exact NaNs in the input. If NaNs are present but
45+
`hasnan` is `false`, the behavior is undefined.
3746

3847
#### Partialsort
3948

40-
```
49+
```cpp
4150
void avx512_partial_qsort<T>(T* arr, int64_t arrsize)
4251
void avx512_partial_qsort<T>(T* arr, int64_t arrsize, bool hasnan)
4352
```
44-
Supported datatypes: `uint16_t, int16_t, _Float16 ,uint32_t, int32_t, float,
45-
uint64_t, int64_t and double`. Use an additional optional argument `bool
46-
hasnan` if you expect your arrays to contain nan.
53+
Supported datatypes: `uint16_t`, `int16_t`, `_Float16`, `uint32_t`, `int32_t`,
54+
`float`, `uint64_t`, `int64_t` and `double`.
55+
56+
For floating-point types, if `bool hasnan` is set, NaNs are moved to the end of
57+
the array, preserving the bit-exact NaNs in the input. If NaNs are present but
58+
`hasnan` is `false`, the behavior is undefined.
4759

4860
#### Key-value sort
49-
```
61+
```cpp
5062
void avx512_qsort_kv<T>(T* key, uint64_t* value , int64_t arrsize)
5163
```
5264
Supported datatypes: `uint64_t, int64_t and double`
@@ -64,15 +76,6 @@ network. The core implementations of the vectorized qsort functions
6476
`avx512_qsort<T>(T*, int64_t)` are modified versions of avx2 quicksort
6577
presented in the paper [2] and source code associated with that paper [3].
6678

67-
## A note on NAN in float and double arrays
68-
69-
If you expect your array to contain NANs, please be aware that the these
70-
routines **do not preserve your NANs as you pass them**. The quicksort,
71-
quickselect, partialsort and key-value sorting routines will sort NAN's to the
72-
end of the array and replace them with `std::nan("1")`. `avx512_argsort`
73-
routines will also resort to a scalar argsort that uses `std::sort` to sort array
74-
that contains NAN.
75-
7679
## Example to include and build this in a C++ code
7780

7881
### Sample code `main.cpp`

0 commit comments

Comments
 (0)