NUMPY_API * Removes an axis from iteration. This requires that NPY_ITER_MULTI_INDEX * was set for iterator creation, and does not work if buffering is * enabled. This function also resets the iterator to its initial state. * * Returns NPY_SUCCEED or NPY_FAIL. */
| 33 | * Returns NPY_SUCCEED or NPY_FAIL. |
| 34 | */ |
| 35 | NPY_NO_EXPORT int |
| 36 | NpyIter_RemoveAxis(NpyIter *iter, int axis) |
| 37 | { |
| 38 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 39 | int idim, ndim = NIT_NDIM(iter); |
| 40 | int iop, nop = NIT_NOP(iter); |
| 41 | |
| 42 | int xdim = 0; |
| 43 | npy_int8 *perm = NIT_PERM(iter); |
| 44 | NpyIter_AxisData *axisdata_del = NIT_AXISDATA(iter), *axisdata; |
| 45 | npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); |
| 46 | |
| 47 | npy_intp *baseoffsets = NIT_BASEOFFSETS(iter); |
| 48 | char **resetdataptr = NIT_RESETDATAPTR(iter); |
| 49 | |
| 50 | if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { |
| 51 | PyErr_SetString(PyExc_RuntimeError, |
| 52 | "Iterator RemoveAxis may only be called " |
| 53 | "if a multi-index is being tracked"); |
| 54 | return NPY_FAIL; |
| 55 | } |
| 56 | else if (itflags&NPY_ITFLAG_HASINDEX) { |
| 57 | PyErr_SetString(PyExc_RuntimeError, |
| 58 | "Iterator RemoveAxis may not be called on " |
| 59 | "an index is being tracked"); |
| 60 | return NPY_FAIL; |
| 61 | } |
| 62 | else if (itflags&NPY_ITFLAG_BUFFER) { |
| 63 | PyErr_SetString(PyExc_RuntimeError, |
| 64 | "Iterator RemoveAxis may not be called on " |
| 65 | "a buffered iterator"); |
| 66 | return NPY_FAIL; |
| 67 | } |
| 68 | else if (axis < 0 || axis >= ndim) { |
| 69 | PyErr_SetString(PyExc_ValueError, |
| 70 | "axis out of bounds in iterator RemoveAxis"); |
| 71 | return NPY_FAIL; |
| 72 | } |
| 73 | |
| 74 | /* Reverse axis, since the iterator treats them that way */ |
| 75 | axis = ndim - 1 - axis; |
| 76 | |
| 77 | /* First find the axis in question */ |
| 78 | for (idim = 0; idim < ndim; ++idim) { |
| 79 | /* If this is it, and it's iterated forward, done */ |
| 80 | if (perm[idim] == axis) { |
| 81 | xdim = idim; |
| 82 | break; |
| 83 | } |
| 84 | /* If this is it, but it's iterated backward, must reverse the axis */ |
| 85 | else if (-1 - perm[idim] == axis) { |
| 86 | npy_intp *strides = NAD_STRIDES(axisdata_del); |
| 87 | npy_intp shape = NAD_SHAPE(axisdata_del), offset; |
| 88 | |
| 89 | xdim = idim; |
| 90 | |
| 91 | /* |
| 92 | * Adjust baseoffsets and resetbaseptr back to the start of |
no test coverage detected