NUMPY_API * Sort an array in-place */
| 1494 | * Sort an array in-place |
| 1495 | */ |
| 1496 | NPY_NO_EXPORT int |
| 1497 | PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) |
| 1498 | { |
| 1499 | PyArray_SortFunc *sort = NULL; |
| 1500 | int n = PyArray_NDIM(op); |
| 1501 | |
| 1502 | if (check_and_adjust_axis(&axis, n) < 0) { |
| 1503 | return -1; |
| 1504 | } |
| 1505 | |
| 1506 | if (PyArray_FailUnlessWriteable(op, "sort array") < 0) { |
| 1507 | return -1; |
| 1508 | } |
| 1509 | |
| 1510 | if (which < 0 || which >= NPY_NSORTS) { |
| 1511 | PyErr_SetString(PyExc_ValueError, "not a valid sort kind"); |
| 1512 | return -1; |
| 1513 | } |
| 1514 | |
| 1515 | sort = PyArray_DESCR(op)->f->sort[which]; |
| 1516 | |
| 1517 | if (sort == NULL) { |
| 1518 | if (PyArray_DESCR(op)->f->compare) { |
| 1519 | switch (which) { |
| 1520 | default: |
| 1521 | case NPY_QUICKSORT: |
| 1522 | sort = npy_quicksort; |
| 1523 | break; |
| 1524 | case NPY_HEAPSORT: |
| 1525 | sort = npy_heapsort; |
| 1526 | break; |
| 1527 | case NPY_STABLESORT: |
| 1528 | sort = npy_timsort; |
| 1529 | break; |
| 1530 | } |
| 1531 | } |
| 1532 | else { |
| 1533 | PyErr_SetString(PyExc_TypeError, |
| 1534 | "type does not have compare function"); |
| 1535 | return -1; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | return _new_sortlike(op, axis, sort, NULL, NULL, 0); |
| 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | /* |
no test coverage detected