{{ message }}
Commit fe16eac
committed
ENH: Add extended sorting APIs
This PR adds new sorting APIs that can be used for extending our current
sort types. The new C-APIs do not have the *which* argument of the
legacy C-APIs, instead they have *flags* request flag API. In this
transition, heapsort can no longer be called directly, introsort
(quicksort) is called instead. The sort/argsort methods get new keyword
arguments used to set the flags when *kind* is not given, so *flags* is
invisible at the Python level. The new keywords are:
- stable -- whether the sort should stable, default is False,
- descending -- whether to sort in descending order, default is False,
- nanfirst -- whether NaNs sort to the last or first, default is False.
The main difference here is that the keywords select by functionality,
whereas *kind* selects by algorithm. Note that descending and nanfirst
are not yet implemented, so an error is raised if either is specified.
The added C-API functions are:
- (API)PyArray_SortEx,
- (API)PyArray_ArgSortEx,
Those are the two functions that need changes depending on how we want
to implement adding new sort algorithms. They should be pretty easy to
adapt to whatever we choose to do.
The legacy C-API functions, PyArray_Sort and PyArray_ArgSort, have been
modified to call through the new C-API functions. In order to do so
the *kind* function has been encoded in the *flags* like so:
- "quicksort" - default (0)
- "heapsort" - default (0)
- "mergesort" - stable (1)
I note that the partitioning/selection functions have not been modified,
we may want to do that a some point.1 parent bde097d commit fe16eac
9 files changed
Lines changed: 306 additions & 154 deletions
File tree
- doc
- release/upcoming_changes
- source/reference/c-api
- numpy/_core
- include/numpy
- src/multiarray
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2308 | 2308 | | |
2309 | 2309 | | |
2310 | 2310 | | |
2311 | | - | |
| 2311 | + | |
2312 | 2312 | | |
2313 | | - | |
| 2313 | + | |
2314 | 2314 | | |
2315 | 2315 | | |
2316 | 2316 | | |
| |||
4321 | 4321 | | |
4322 | 4322 | | |
4323 | 4323 | | |
4324 | | - | |
| 4324 | + | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
| 4328 | + | |
4325 | 4329 | | |
4326 | 4330 | | |
4327 | 4331 | | |
| |||
4335 | 4339 | | |
4336 | 4340 | | |
4337 | 4341 | | |
4338 | | - | |
4339 | | - | |
4340 | | - | |
4341 | | - | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
4342 | 4346 | | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + | |
| 4350 | + | |
| 4351 | + | |
| 4352 | + | |
| 4353 | + | |
| 4354 | + | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
| 4359 | + | |
| 4360 | + | |
| 4361 | + | |
| 4362 | + | |
| 4363 | + | |
| 4364 | + | |
| 4365 | + | |
| 4366 | + | |
| 4367 | + | |
| 4368 | + | |
| 4369 | + | |
| 4370 | + | |
| 4371 | + | |
| 4372 | + | |
| 4373 | + | |
| 4374 | + | |
| 4375 | + | |
| 4376 | + | |
4343 | 4377 | | |
4344 | 4378 | | |
4345 | 4379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
653 | | - | |
| 653 | + | |
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
| 662 | + | |
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
170 | 184 | | |
| 185 | + | |
171 | 186 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
177 | 198 | | |
178 | 199 | | |
179 | 200 | | |
| |||

0 commit comments