58
58
59
59
60
60
def _wrap_sort_argsort (
61
- a , _sorting_fn , axis = - 1 , kind = None , order = None , stable = True
61
+ a ,
62
+ _sorting_fn ,
63
+ axis = - 1 ,
64
+ kind = None ,
65
+ order = None ,
66
+ descending = False ,
67
+ stable = True ,
62
68
):
63
69
"""Wrap a sorting call from dpctl.tensor interface."""
64
70
@@ -83,11 +89,15 @@ def _wrap_sort_argsort(
83
89
axis = - 1
84
90
85
91
axis = normalize_axis_index (axis , ndim = usm_a .ndim )
86
- usm_res = _sorting_fn (usm_a , axis = axis , stable = stable , kind = kind )
92
+ usm_res = _sorting_fn (
93
+ usm_a , axis = axis , descending = descending , stable = stable , kind = kind
94
+ )
87
95
return dpnp_array ._create_from_usm_ndarray (usm_res )
88
96
89
97
90
- def argsort (a , axis = - 1 , kind = None , order = None , * , stable = None ):
98
+ def argsort (
99
+ a , axis = - 1 , kind = None , order = None , * , descending = False , stable = None
100
+ ):
91
101
"""
92
102
Returns the indices that would sort an array.
93
103
@@ -100,13 +110,21 @@ def argsort(a, axis=-1, kind=None, order=None, *, stable=None):
100
110
axis : {None, int}, optional
101
111
Axis along which to sort. If ``None``, the array is flattened before
102
112
sorting. The default is ``-1``, which sorts along the last axis.
113
+ Default: ``-1``.
103
114
kind : {None, "stable", "mergesort", "radixsort"}, optional
104
- Sorting algorithm. Default is ``None``, which is equivalent to
105
- ``"stable"``.
115
+ Sorting algorithm. The default is ``None``, which uses parallel
116
+ merge-sort or parallel radix-sort algorithms depending on the array
117
+ data type.
118
+ Default: ``None``.
119
+ descending : bool, optional
120
+ Sort order. If ``True``, the array must be sorted in descending order
121
+ (by value). If ``False``, the array must be sorted in ascending order
122
+ (by value).
123
+ Default: ``False``.
106
124
stable : {None, bool}, optional
107
- Sort stability. If ``True``, the returned array will maintain
108
- the relative order of ``a`` values which compare as equal.
109
- The same behavior applies when set to ``False`` or ``None``.
125
+ Sort stability. If ``True``, the returned array will maintain the
126
+ relative order of `a` values which compare as equal. The same behavior
127
+ applies when set to ``False`` or ``None``.
110
128
Internally, this option selects ``kind="stable"``.
111
129
Default: ``None``.
112
130
@@ -130,7 +148,6 @@ def argsort(a, axis=-1, kind=None, order=None, *, stable=None):
130
148
Otherwise ``NotImplementedError`` exception will be raised.
131
149
Sorting algorithms ``"quicksort"`` and ``"heapsort"`` are not supported.
132
150
133
-
134
151
See Also
135
152
--------
136
153
:obj:`dpnp.ndarray.argsort` : Equivalent method.
@@ -171,7 +188,13 @@ def argsort(a, axis=-1, kind=None, order=None, *, stable=None):
171
188
"""
172
189
173
190
return _wrap_sort_argsort (
174
- a , dpt .argsort , axis = axis , kind = kind , order = order , stable = stable
191
+ a ,
192
+ dpt .argsort ,
193
+ axis = axis ,
194
+ kind = kind ,
195
+ order = order ,
196
+ descending = descending ,
197
+ stable = stable ,
175
198
)
176
199
177
200
@@ -215,7 +238,7 @@ def partition(x1, kth, axis=-1, kind="introselect", order=None):
215
238
return call_origin (numpy .partition , x1 , kth , axis , kind , order )
216
239
217
240
218
- def sort (a , axis = - 1 , kind = None , order = None , * , stable = None ):
241
+ def sort (a , axis = - 1 , kind = None , order = None , * , descending = False , stable = None ):
219
242
"""
220
243
Return a sorted copy of an array.
221
244
@@ -228,13 +251,21 @@ def sort(a, axis=-1, kind=None, order=None, *, stable=None):
228
251
axis : {None, int}, optional
229
252
Axis along which to sort. If ``None``, the array is flattened before
230
253
sorting. The default is ``-1``, which sorts along the last axis.
254
+ Default: ``-1``.
231
255
kind : {None, "stable", "mergesort", "radixsort"}, optional
232
- Sorting algorithm. Default is ``None``, which is equivalent to
233
- ``"stable"``.
256
+ Sorting algorithm. The default is ``None``, which uses parallel
257
+ merge-sort or parallel radix-sort algorithms depending on the array
258
+ data type.
259
+ Default: ``None``.
260
+ descending : bool, optional
261
+ Sort order. If ``True``, the array must be sorted in descending order
262
+ (by value). If ``False``, the array must be sorted in ascending order
263
+ (by value).
264
+ Default: ``False``.
234
265
stable : {None, bool}, optional
235
- Sort stability. If ``True``, the returned array will maintain
236
- the relative order of ``a`` values which compare as equal.
237
- The same behavior applies when set to ``False`` or ``None``.
266
+ Sort stability. If ``True``, the returned array will maintain the
267
+ relative order of `a` values which compare as equal. The same behavior
268
+ applies when set to ``False`` or ``None``.
238
269
Internally, this option selects ``kind="stable"``.
239
270
Default: ``None``.
240
271
@@ -265,7 +296,7 @@ def sort(a, axis=-1, kind=None, order=None, *, stable=None):
265
296
Examples
266
297
--------
267
298
>>> import dpnp as np
268
- >>> a = np.array([[1,4],[3,1]])
299
+ >>> a = np.array([[1, 4], [3, 1]])
269
300
>>> np.sort(a) # sort along the last axis
270
301
array([[1, 4],
271
302
[1, 3]])
@@ -278,7 +309,13 @@ def sort(a, axis=-1, kind=None, order=None, *, stable=None):
278
309
"""
279
310
280
311
return _wrap_sort_argsort (
281
- a , dpt .sort , axis = axis , kind = kind , order = order , stable = stable
312
+ a ,
313
+ dpt .sort ,
314
+ axis = axis ,
315
+ kind = kind ,
316
+ order = order ,
317
+ descending = descending ,
318
+ stable = stable ,
282
319
)
283
320
284
321
0 commit comments