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

Function array_argsort

numpy/core/src/multiarray/methods.c:1479–1534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1477}
1478
1479static PyObject *
1480array_argsort(PyArrayObject *self,
1481 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1482{
1483 int axis = -1;
1484 NPY_SORTKIND sortkind = NPY_QUICKSORT;
1485 PyObject *order = NULL, *res;
1486 PyArray_Descr *newd, *saved=NULL;
1487 NPY_PREPARE_ARGPARSER;
1488
1489 if (npy_parse_arguments("argsort", args, len_args, kwnames,
1490 "|axis", &PyArray_AxisConverter, &axis,
1491 "|kind", &PyArray_SortkindConverter, &sortkind,
1492 "|order", NULL, &order,
1493 NULL, NULL, NULL) < 0) {
1494 return NULL;
1495 }
1496 if (order == Py_None) {
1497 order = NULL;
1498 }
1499 if (order != NULL) {
1500 PyObject *new_name;
1501 PyObject *_numpy_internal;
1502 saved = PyArray_DESCR(self);
1503 if (!PyDataType_HASFIELDS(saved)) {
1504 PyErr_SetString(PyExc_ValueError, "Cannot specify "
1505 "order when the array has no fields.");
1506 return NULL;
1507 }
1508 _numpy_internal = PyImport_ImportModule("numpy.core._internal");
1509 if (_numpy_internal == NULL) {
1510 return NULL;
1511 }
1512 new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
1513 "OO", saved, order);
1514 Py_DECREF(_numpy_internal);
1515 if (new_name == NULL) {
1516 return NULL;
1517 }
1518 newd = PyArray_DescrNew(saved);
1519 if (newd == NULL) {
1520 Py_DECREF(new_name);
1521 return NULL;
1522 }
1523 Py_DECREF(newd->names);
1524 newd->names = new_name;
1525 ((PyArrayObject_fields *)self)->descr = newd;
1526 }
1527
1528 res = PyArray_ArgSort(self, axis, sortkind);
1529 if (order != NULL) {
1530 Py_XDECREF(PyArray_DESCR(self));
1531 ((PyArrayObject_fields *)self)->descr = saved;
1532 }
1533 return PyArray_Return((PyArrayObject *)res);
1534}
1535
1536

Callers

nothing calls this directly

Calls 4

PyArray_DESCRFunction · 0.85
PyArray_DescrNewFunction · 0.85
PyArray_ArgSortFunction · 0.85
PyArray_ReturnFunction · 0.85

Tested by

no test coverage detected