MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_Sort

Function PyArray_Sort

numpy/core/src/multiarray/item_selection.c:1496–1540  ·  view source on GitHub ↗

NUMPY_API * Sort an array in-place */

Source from the content-addressed store, hash-verified

1494 * Sort an array in-place
1495 */
1496NPY_NO_EXPORT int
1497PyArray_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/*

Callers 2

array_sortFunction · 0.85
partition_prep_kth_arrayFunction · 0.85

Calls 5

PyArray_NDIMFunction · 0.85
check_and_adjust_axisFunction · 0.85
PyArray_DESCRFunction · 0.85
_new_sortlikeFunction · 0.85

Tested by

no test coverage detected