NUMPY_API * Where */
| 3366 | * Where |
| 3367 | */ |
| 3368 | NPY_NO_EXPORT PyObject * |
| 3369 | PyArray_Where(PyObject *condition, PyObject *x, PyObject *y) |
| 3370 | { |
| 3371 | PyArrayObject *arr, *ax, *ay; |
| 3372 | PyObject *ret = NULL; |
| 3373 | |
| 3374 | arr = (PyArrayObject *)PyArray_FROM_O(condition); |
| 3375 | if (arr == NULL) { |
| 3376 | return NULL; |
| 3377 | } |
| 3378 | if ((x == NULL) && (y == NULL)) { |
| 3379 | ret = PyArray_Nonzero(arr); |
| 3380 | Py_DECREF(arr); |
| 3381 | return ret; |
| 3382 | } |
| 3383 | if ((x == NULL) || (y == NULL)) { |
| 3384 | Py_DECREF(arr); |
| 3385 | PyErr_SetString(PyExc_ValueError, |
| 3386 | "either both or neither of x and y should be given"); |
| 3387 | return NULL; |
| 3388 | } |
| 3389 | |
| 3390 | NPY_cast_info cast_info = {.func = NULL}; |
| 3391 | |
| 3392 | ax = (PyArrayObject*)PyArray_FROM_O(x); |
| 3393 | ay = (PyArrayObject*)PyArray_FROM_O(y); |
| 3394 | if (ax == NULL || ay == NULL) { |
| 3395 | goto fail; |
| 3396 | } |
| 3397 | else { |
| 3398 | npy_uint32 flags = NPY_ITER_EXTERNAL_LOOP | NPY_ITER_BUFFERED | |
| 3399 | NPY_ITER_REFS_OK | NPY_ITER_ZEROSIZE_OK; |
| 3400 | PyArrayObject * op_in[4] = { |
| 3401 | NULL, arr, ax, ay |
| 3402 | }; |
| 3403 | npy_uint32 op_flags[4] = { |
| 3404 | NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE | NPY_ITER_NO_SUBTYPE, |
| 3405 | NPY_ITER_READONLY, |
| 3406 | NPY_ITER_READONLY | NPY_ITER_ALIGNED, |
| 3407 | NPY_ITER_READONLY | NPY_ITER_ALIGNED |
| 3408 | }; |
| 3409 | PyArray_Descr * common_dt = PyArray_ResultType(2, &op_in[0] + 2, |
| 3410 | 0, NULL); |
| 3411 | PyArray_Descr * op_dt[4] = {common_dt, PyArray_DescrFromType(NPY_BOOL), |
| 3412 | common_dt, common_dt}; |
| 3413 | NpyIter * iter; |
| 3414 | NPY_BEGIN_THREADS_DEF; |
| 3415 | |
| 3416 | if (common_dt == NULL || op_dt[1] == NULL) { |
| 3417 | Py_XDECREF(op_dt[1]); |
| 3418 | Py_XDECREF(common_dt); |
| 3419 | goto fail; |
| 3420 | } |
| 3421 | iter = NpyIter_MultiNew(4, op_in, flags, |
| 3422 | NPY_KEEPORDER, NPY_UNSAFE_CASTING, |
| 3423 | op_flags, op_dt); |
| 3424 | Py_DECREF(op_dt[1]); |
| 3425 | Py_DECREF(common_dt); |
no test coverage detected