Array API compatible wrapper for :py:func:`np.sort `. See its docstring for more information.
(
x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
)
| 37 | |
| 38 | # Note: the descending keyword argument is new in this function |
| 39 | def sort( |
| 40 | x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True |
| 41 | ) -> Array: |
| 42 | """ |
| 43 | Array API compatible wrapper for :py:func:`np.sort <numpy.sort>`. |
| 44 | |
| 45 | See its docstring for more information. |
| 46 | """ |
| 47 | if x.dtype not in _real_numeric_dtypes: |
| 48 | raise TypeError("Only real numeric dtypes are allowed in sort") |
| 49 | # Note: this keyword argument is different, and the default is different. |
| 50 | kind = "stable" if stable else "quicksort" |
| 51 | res = np.sort(x._array, axis=axis, kind=kind) |
| 52 | if descending: |
| 53 | res = np.flip(res, axis=axis) |
| 54 | return Array._new(res) |