NUMPY_API * Resets the iterator to its initial state, with new base data pointers. * This function requires great caution. * * If errmsg is non-NULL, it should point to a variable which will * receive the error message, and no Python exception will be set. * This is so that the function can be called from code not holding * the GIL. Note that cast errors may still lead to the GIL being * g
| 314 | * grabbed temporarily. |
| 315 | */ |
| 316 | NPY_NO_EXPORT int |
| 317 | NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs, char **errmsg) |
| 318 | { |
| 319 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 320 | /*int ndim = NIT_NDIM(iter);*/ |
| 321 | int iop, nop = NIT_NOP(iter); |
| 322 | |
| 323 | char **resetdataptr = NIT_RESETDATAPTR(iter); |
| 324 | npy_intp *baseoffsets = NIT_BASEOFFSETS(iter); |
| 325 | |
| 326 | if (itflags&NPY_ITFLAG_BUFFER) { |
| 327 | /* If buffer allocation was delayed, do it now */ |
| 328 | if (itflags&NPY_ITFLAG_DELAYBUF) { |
| 329 | if (!npyiter_allocate_buffers(iter, errmsg)) { |
| 330 | return NPY_FAIL; |
| 331 | } |
| 332 | NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_DELAYBUF; |
| 333 | } |
| 334 | else { |
| 335 | if (npyiter_copy_from_buffers(iter) < 0) { |
| 336 | if (errmsg != NULL) { |
| 337 | *errmsg = _reset_cast_error; |
| 338 | } |
| 339 | return NPY_FAIL; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* The new data pointers for resetting */ |
| 345 | for (iop = 0; iop < nop; ++iop) { |
| 346 | resetdataptr[iop] = baseptrs[iop] + baseoffsets[iop]; |
| 347 | } |
| 348 | |
| 349 | npyiter_goto_iterindex(iter, NIT_ITERSTART(iter)); |
| 350 | |
| 351 | if (itflags&NPY_ITFLAG_BUFFER) { |
| 352 | /* Prepare the next buffers and set iterend/size */ |
| 353 | if (npyiter_copy_to_buffers(iter, NULL) < 0) { |
| 354 | if (errmsg != NULL) { |
| 355 | *errmsg = _reset_cast_error; |
| 356 | } |
| 357 | return NPY_FAIL; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return NPY_SUCCEED; |
| 362 | } |
| 363 | |
| 364 | /*NUMPY_API |
| 365 | * Resets the iterator to a new iterator index range |
no test coverage detected