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

Function PyArray_Choose

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

NUMPY_API */

Source from the content-addressed store, hash-verified

957/*NUMPY_API
958 */
959NPY_NO_EXPORT PyObject *
960PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
961 NPY_CLIPMODE clipmode)
962{
963 PyArrayObject *obj = NULL;
964 PyArray_Descr *dtype;
965 int n, elsize;
966 npy_intp i;
967 char *ret_data;
968 PyArrayObject **mps, *ap;
969 PyArrayMultiIterObject *multi = NULL;
970 npy_intp mi;
971 NPY_cast_info cast_info = {.func = NULL};
972 ap = NULL;
973
974 /*
975 * Convert all inputs to arrays of a common type
976 * Also makes them C-contiguous
977 */
978 mps = PyArray_ConvertToCommonType(op, &n);
979 if (mps == NULL) {
980 return NULL;
981 }
982 for (i = 0; i < n; i++) {
983 if (mps[i] == NULL) {
984 goto fail;
985 }
986 }
987 ap = (PyArrayObject *)PyArray_FROM_OT((PyObject *)ip, NPY_INTP);
988 if (ap == NULL) {
989 goto fail;
990 }
991 /* Broadcast all arrays to each other, index array at the end. */
992 multi = (PyArrayMultiIterObject *)
993 PyArray_MultiIterFromObjects((PyObject **)mps, n, 1, ap);
994 if (multi == NULL) {
995 goto fail;
996 }
997 dtype = PyArray_DESCR(mps[0]);
998
999 /* Set-up return array */
1000 if (out == NULL) {
1001 Py_INCREF(dtype);
1002 obj = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(ap),
1003 dtype,
1004 multi->nd,
1005 multi->dimensions,
1006 NULL, NULL, 0,
1007 (PyObject *)ap);
1008 }
1009 else {
1010 int flags = NPY_ARRAY_CARRAY |
1011 NPY_ARRAY_WRITEBACKIFCOPY |
1012 NPY_ARRAY_FORCECAST;
1013
1014 if ((PyArray_NDIM(out) != multi->nd)
1015 || !PyArray_CompareLists(PyArray_DIMS(out),
1016 multi->dimensions,

Callers 1

array_chooseFunction · 0.85

Calls 15

PyArray_DESCRFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_CompareListsFunction · 0.85
PyArray_DIMSFunction · 0.85
arrays_overlapFunction · 0.85
PyArray_FromArrayFunction · 0.85
PyArray_DATAFunction · 0.85
IsUintAlignedFunction · 0.85

Tested by

no test coverage detected