| 1300 | } |
| 1301 | |
| 1302 | static PyObject* |
| 1303 | _new_argsortlike(PyArrayObject *op, int axis, PyArray_ArgSortFunc *argsort, |
| 1304 | PyArray_ArgPartitionFunc *argpart, |
| 1305 | npy_intp const *kth, npy_intp nkth) |
| 1306 | { |
| 1307 | npy_intp N = PyArray_DIM(op, axis); |
| 1308 | npy_intp elsize = (npy_intp)PyArray_ITEMSIZE(op); |
| 1309 | npy_intp astride = PyArray_STRIDE(op, axis); |
| 1310 | int swap = PyArray_ISBYTESWAPPED(op); |
| 1311 | int is_aligned = IsAligned(op); |
| 1312 | int needcopy = !is_aligned || swap || astride != elsize; |
| 1313 | int needs_api = PyDataType_FLAGCHK(PyArray_DESCR(op), NPY_NEEDS_PYAPI); |
| 1314 | int needidxbuffer; |
| 1315 | |
| 1316 | char *valbuffer = NULL; |
| 1317 | npy_intp *idxbuffer = NULL; |
| 1318 | |
| 1319 | PyArrayObject *rop; |
| 1320 | npy_intp rstride; |
| 1321 | |
| 1322 | PyArrayIterObject *it, *rit; |
| 1323 | npy_intp size; |
| 1324 | |
| 1325 | int ret = 0; |
| 1326 | |
| 1327 | PyArray_Descr *descr = PyArray_DESCR(op); |
| 1328 | PyArray_Descr *odescr = NULL; |
| 1329 | |
| 1330 | NPY_ARRAYMETHOD_FLAGS transfer_flags; |
| 1331 | NPY_cast_info cast_info = {.func = NULL}; |
| 1332 | |
| 1333 | NPY_BEGIN_THREADS_DEF; |
| 1334 | |
| 1335 | PyObject *mem_handler = PyDataMem_GetHandler(); |
| 1336 | if (mem_handler == NULL) { |
| 1337 | return NULL; |
| 1338 | } |
| 1339 | rop = (PyArrayObject *)PyArray_NewFromDescr( |
| 1340 | Py_TYPE(op), PyArray_DescrFromType(NPY_INTP), |
| 1341 | PyArray_NDIM(op), PyArray_DIMS(op), NULL, NULL, |
| 1342 | 0, (PyObject *)op); |
| 1343 | if (rop == NULL) { |
| 1344 | Py_DECREF(mem_handler); |
| 1345 | return NULL; |
| 1346 | } |
| 1347 | rstride = PyArray_STRIDE(rop, axis); |
| 1348 | needidxbuffer = rstride != sizeof(npy_intp); |
| 1349 | |
| 1350 | /* Check if there is any argsorting to do */ |
| 1351 | if (N <= 1 || PyArray_SIZE(op) == 0) { |
| 1352 | Py_DECREF(mem_handler); |
| 1353 | memset(PyArray_DATA(rop), 0, PyArray_NBYTES(rop)); |
| 1354 | return (PyObject *)rop; |
| 1355 | } |
| 1356 | |
| 1357 | it = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, &axis); |
| 1358 | rit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)rop, &axis); |
| 1359 | if (it == NULL || rit == NULL) { |
no test coverage detected