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

Function array_argpartition

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

Source from the content-addressed store, hash-verified

1535
1536
1537static PyObject *
1538array_argpartition(PyArrayObject *self,
1539 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
1540{
1541 int axis = -1;
1542 NPY_SELECTKIND sortkind = NPY_INTROSELECT;
1543 PyObject *order = NULL, *res;
1544 PyArray_Descr *newd, *saved=NULL;
1545 PyObject * kthobj;
1546 PyArrayObject * ktharray;
1547 NPY_PREPARE_ARGPARSER;
1548
1549 if (npy_parse_arguments("argpartition", args, len_args, kwnames,
1550 "kth", NULL, &kthobj,
1551 "|axis", &PyArray_AxisConverter, &axis,
1552 "|kind", &PyArray_SelectkindConverter, &sortkind,
1553 "|order", NULL, &order,
1554 NULL, NULL, NULL) < 0) {
1555 return NULL;
1556 }
1557 if (order == Py_None) {
1558 order = NULL;
1559 }
1560 if (order != NULL) {
1561 PyObject *new_name;
1562 PyObject *_numpy_internal;
1563 saved = PyArray_DESCR(self);
1564 if (!PyDataType_HASFIELDS(saved)) {
1565 PyErr_SetString(PyExc_ValueError, "Cannot specify "
1566 "order when the array has no fields.");
1567 return NULL;
1568 }
1569 _numpy_internal = PyImport_ImportModule("numpy.core._internal");
1570 if (_numpy_internal == NULL) {
1571 return NULL;
1572 }
1573 new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
1574 "OO", saved, order);
1575 Py_DECREF(_numpy_internal);
1576 if (new_name == NULL) {
1577 return NULL;
1578 }
1579 newd = PyArray_DescrNew(saved);
1580 if (newd == NULL) {
1581 Py_DECREF(new_name);
1582 return NULL;
1583 }
1584 Py_DECREF(newd->names);
1585 newd->names = new_name;
1586 ((PyArrayObject_fields *)self)->descr = newd;
1587 }
1588
1589 ktharray = (PyArrayObject *)PyArray_FromAny(kthobj, NULL, 0, 1,
1590 NPY_ARRAY_DEFAULT, NULL);
1591 if (ktharray == NULL)
1592 return NULL;
1593
1594 res = PyArray_ArgPartition(self, ktharray, axis, sortkind);

Callers

nothing calls this directly

Calls 5

PyArray_DESCRFunction · 0.85
PyArray_DescrNewFunction · 0.85
PyArray_FromAnyFunction · 0.85
PyArray_ArgPartitionFunction · 0.85
PyArray_ReturnFunction · 0.85

Tested by

no test coverage detected