NUMPY_API * Resets the iterator to a new iterator index range * * 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 * grabbed temporarily. */
| 371 | * grabbed temporarily. |
| 372 | */ |
| 373 | NPY_NO_EXPORT int |
| 374 | NpyIter_ResetToIterIndexRange(NpyIter *iter, |
| 375 | npy_intp istart, npy_intp iend, char **errmsg) |
| 376 | { |
| 377 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 378 | /*int ndim = NIT_NDIM(iter);*/ |
| 379 | /*int nop = NIT_NOP(iter);*/ |
| 380 | |
| 381 | if (!(itflags&NPY_ITFLAG_RANGE)) { |
| 382 | if (errmsg == NULL) { |
| 383 | PyErr_SetString(PyExc_ValueError, |
| 384 | "Cannot call ResetToIterIndexRange on an iterator without " |
| 385 | "requesting ranged iteration support in the constructor"); |
| 386 | } |
| 387 | else { |
| 388 | *errmsg = "Cannot call ResetToIterIndexRange on an iterator " |
| 389 | "without requesting ranged iteration support in the " |
| 390 | "constructor"; |
| 391 | } |
| 392 | return NPY_FAIL; |
| 393 | } |
| 394 | |
| 395 | if (istart < 0 || iend > NIT_ITERSIZE(iter)) { |
| 396 | if (NIT_ITERSIZE(iter) < 0) { |
| 397 | if (errmsg == NULL) { |
| 398 | PyErr_SetString(PyExc_ValueError, "iterator is too large"); |
| 399 | } |
| 400 | else { |
| 401 | *errmsg = "iterator is too large"; |
| 402 | } |
| 403 | return NPY_FAIL; |
| 404 | } |
| 405 | if (errmsg == NULL) { |
| 406 | PyErr_Format(PyExc_ValueError, |
| 407 | "Out-of-bounds range [%" NPY_INTP_FMT ", %" NPY_INTP_FMT ") passed to " |
| 408 | "ResetToIterIndexRange", istart, iend); |
| 409 | } |
| 410 | else { |
| 411 | *errmsg = "Out-of-bounds range passed to ResetToIterIndexRange"; |
| 412 | } |
| 413 | return NPY_FAIL; |
| 414 | } |
| 415 | else if (iend < istart) { |
| 416 | if (errmsg == NULL) { |
| 417 | PyErr_Format(PyExc_ValueError, |
| 418 | "Invalid range [%" NPY_INTP_FMT ", %" NPY_INTP_FMT ") passed to ResetToIterIndexRange", |
| 419 | istart, iend); |
| 420 | } |
| 421 | else { |
| 422 | *errmsg = "Invalid range passed to ResetToIterIndexRange"; |
| 423 | } |
| 424 | return NPY_FAIL; |
| 425 | } |
| 426 | |
| 427 | NIT_ITERSTART(iter) = istart; |
| 428 | NIT_ITEREND(iter) = iend; |
| 429 | |
| 430 | return NpyIter_Reset(iter, errmsg); |
no test coverage detected