* Check whether the fancy indices are out of bounds. * Returns 0 on success and -1 on failure. * (Gets operands from the outer iterator, but iterates them independently) */
| 2556 | * (Gets operands from the outer iterator, but iterates them independently) |
| 2557 | */ |
| 2558 | NPY_NO_EXPORT int |
| 2559 | PyArray_MapIterCheckIndices(PyArrayMapIterObject *mit) |
| 2560 | { |
| 2561 | PyArrayObject *op; |
| 2562 | NpyIter *op_iter; |
| 2563 | NpyIter_IterNextFunc *op_iternext; |
| 2564 | npy_intp outer_dim, indval; |
| 2565 | int outer_axis; |
| 2566 | npy_intp itersize, *iterstride; |
| 2567 | char **iterptr; |
| 2568 | PyArray_Descr *intp_type; |
| 2569 | int i; |
| 2570 | NPY_BEGIN_THREADS_DEF; |
| 2571 | |
| 2572 | if (NpyIter_GetIterSize(mit->outer) == 0) { |
| 2573 | /* |
| 2574 | * When the outer iteration is empty, the indices broadcast to an |
| 2575 | * empty shape, and in this case we do not check if there are out |
| 2576 | * of bounds indices. |
| 2577 | * The code below does use the indices without broadcasting since |
| 2578 | * broadcasting only repeats values. |
| 2579 | */ |
| 2580 | return 0; |
| 2581 | } |
| 2582 | |
| 2583 | intp_type = PyArray_DescrFromType(NPY_INTP); |
| 2584 | |
| 2585 | NPY_BEGIN_THREADS; |
| 2586 | |
| 2587 | for (i=0; i < mit->numiter; i++) { |
| 2588 | op = NpyIter_GetOperandArray(mit->outer)[i]; |
| 2589 | |
| 2590 | outer_dim = mit->fancy_dims[i]; |
| 2591 | outer_axis = mit->iteraxes[i]; |
| 2592 | |
| 2593 | /* See if it is possible to just trivially iterate the array */ |
| 2594 | if (PyArray_TRIVIALLY_ITERABLE(op) && |
| 2595 | /* Check if the type is equivalent to INTP */ |
| 2596 | PyArray_ITEMSIZE(op) == sizeof(npy_intp) && |
| 2597 | PyArray_DESCR(op)->kind == 'i' && |
| 2598 | IsUintAligned(op) && |
| 2599 | PyDataType_ISNOTSWAPPED(PyArray_DESCR(op))) { |
| 2600 | char *data; |
| 2601 | npy_intp stride; |
| 2602 | /* release GIL if it was taken by nditer below */ |
| 2603 | if (_save == NULL) { |
| 2604 | NPY_BEGIN_THREADS; |
| 2605 | } |
| 2606 | |
| 2607 | PyArray_PREPARE_TRIVIAL_ITERATION(op, itersize, data, stride); |
| 2608 | |
| 2609 | while (itersize--) { |
| 2610 | indval = *((npy_intp*)data); |
| 2611 | if (check_and_adjust_index(&indval, |
| 2612 | outer_dim, outer_axis, _save) < 0) { |
| 2613 | Py_DECREF(intp_type); |
| 2614 | goto indexing_error; |
| 2615 | } |
no test coverage detected