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

Function array_sort

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

Source from the content-addressed store, hash-verified

1342}
1343
1344static PyObject *
1345array_sort(PyArrayObject *self,
1346 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1347{
1348 int axis=-1;
1349 int val;
1350 NPY_SORTKIND sortkind = NPY_QUICKSORT;
1351 PyObject *order = NULL;
1352 PyArray_Descr *saved = NULL;
1353 PyArray_Descr *newd;
1354 NPY_PREPARE_ARGPARSER;
1355
1356 if (npy_parse_arguments("sort", args, len_args, kwnames,
1357 "|axis", &PyArray_PythonPyIntFromInt, &axis,
1358 "|kind", &PyArray_SortkindConverter, &sortkind,
1359 "|order", NULL, &order,
1360 NULL, NULL, NULL) < 0) {
1361 return NULL;
1362 }
1363 if (order == Py_None) {
1364 order = NULL;
1365 }
1366 if (order != NULL) {
1367 PyObject *new_name;
1368 PyObject *_numpy_internal;
1369 saved = PyArray_DESCR(self);
1370 if (!PyDataType_HASFIELDS(saved)) {
1371 PyErr_SetString(PyExc_ValueError, "Cannot specify " \
1372 "order when the array has no fields.");
1373 return NULL;
1374 }
1375 _numpy_internal = PyImport_ImportModule("numpy.core._internal");
1376 if (_numpy_internal == NULL) {
1377 return NULL;
1378 }
1379 new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
1380 "OO", saved, order);
1381 Py_DECREF(_numpy_internal);
1382 if (new_name == NULL) {
1383 return NULL;
1384 }
1385 newd = PyArray_DescrNew(saved);
1386 if (newd == NULL) {
1387 Py_DECREF(new_name);
1388 return NULL;
1389 }
1390 Py_DECREF(newd->names);
1391 newd->names = new_name;
1392 ((PyArrayObject_fields *)self)->descr = newd;
1393 }
1394
1395 val = PyArray_Sort(self, axis, sortkind);
1396 if (order != NULL) {
1397 Py_XDECREF(PyArray_DESCR(self));
1398 ((PyArrayObject_fields *)self)->descr = saved;
1399 }
1400 if (val < 0) {
1401 return NULL;

Callers

nothing calls this directly

Calls 3

PyArray_DESCRFunction · 0.85
PyArray_DescrNewFunction · 0.85
PyArray_SortFunction · 0.85

Tested by

no test coverage detected