Skip to content

Commit eb0a991

Browse files
authored
Add specifications for sorting functions (#19)
1 parent 7d96766 commit eb0a991

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

spec/API_specification/index.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ API specification
2020
statistical_functions
2121
linear_algebra_functions
2222
searching_functions
23-
linear_algebra_functions
23+
sorting_functions
2424
set_functions
2525
utility_functions
26-
constants
27-
26+
constants
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Sorting Functions
2+
3+
> Array API specification for sorting functions.
4+
5+
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
6+
7+
- 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.
8+
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
9+
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
10+
11+
<!-- NOTE: please keep the functions in alphabetical order -->
12+
13+
### <a name="argsort" href="#argsort">#</a> argsort(x, /, *, axis=-1, descending=False, stable=True)
14+
15+
Returns the indices that sort an array `x` along a specified axis.
16+
17+
#### Parameters
18+
19+
- **x**: _&lt;array&gt;_
20+
21+
- input array.
22+
23+
- **axis**: _int_
24+
25+
- axis along which to sort. If set to `-1`, the function sorts along the last axis. Default: `-1`.
26+
27+
- **descending**: _bool_
28+
29+
- sort order. If `True`, the returned indices sort `x` in descending order (by value). If `False`, the returned indices sort `x` in ascending order (by value). Default: `False`.
30+
31+
- **stable**: _bool_
32+
33+
- sort stability. If `True`, the returned indices must maintain the relative order of `x` values which compare as equal. If `False`, the returned indices may or may not maintain the relative order of `x` values which compare as equal (i.e., the relative order of `x` values which compare as equal is implementation-dependent). Default: `True`.
34+
35+
#### Returns
36+
37+
- **out**: _&lt;array&gt;_
38+
39+
- an array of indices. The returned array must have the same shape as `x`. The returned array must have the default array index data type.
40+
41+
### <a name="sort" href="#sort">#</a> sort(x, /, *, axis=-1, descending=False, stable=True)
42+
43+
Returns a sorted copy of an input array `x`.
44+
45+
#### Parameters
46+
47+
- **x**: _&lt;array&gt;_
48+
49+
- input array.
50+
51+
- **axis**: _int_
52+
53+
- axis along which to sort. If set to `-1`, the function sorts along the last axis. Default: `-1`.
54+
55+
- **descending**: _bool_
56+
57+
- sort order. If `True`, the array is sorted in descending order (by value). If `False`, the array is sorted in ascending order (by value). Default: `False`.
58+
59+
- **stable**: _bool_
60+
61+
- sort stability. If `True`, the returned array must maintain the relative order of `x` values which compare as equal. If `False`, the returned array may or may not maintain the relative order of `x` values which compare as equal (i.e., the relative order of `x` values which compare as equal is implementation-dependent). Default: `True`.
62+
63+
#### Returns
64+
65+
- **out**: _&lt;array&gt;_
66+
67+
- a sorted array. The returned array must have the same data type and shape as `x`.

0 commit comments

Comments
 (0)