MCPcopy Create free account
hub / github.com/numpy/numpy / NpyIter_Reset

Function NpyIter_Reset

numpy/core/src/multiarray/nditer_api.c:251–304  ·  view source on GitHub ↗

NUMPY_API * Resets the iterator to its initial state * * The use of errmsg is discouraged, it cannot be guaranteed that the GIL * will not be grabbed on casting errors even when this is passed. * * 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 holdi

Source from the content-addressed store, hash-verified

249 * grabbed temporarily.
250 */
251NPY_NO_EXPORT int
252NpyIter_Reset(NpyIter *iter, char **errmsg)
253{
254 npy_uint32 itflags = NIT_ITFLAGS(iter);
255 /*int ndim = NIT_NDIM(iter);*/
256 int nop = NIT_NOP(iter);
257
258 if (itflags&NPY_ITFLAG_BUFFER) {
259 NpyIter_BufferData *bufferdata;
260
261 /* If buffer allocation was delayed, do it now */
262 if (itflags&NPY_ITFLAG_DELAYBUF) {
263 if (!npyiter_allocate_buffers(iter, errmsg)) {
264 if (errmsg != NULL) {
265 *errmsg = _reset_cast_error;
266 }
267 return NPY_FAIL;
268 }
269 NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_DELAYBUF;
270 }
271 else {
272 /*
273 * If the iterindex is already right, no need to
274 * do anything (and no cast error has previously occurred).
275 */
276 bufferdata = NIT_BUFFERDATA(iter);
277 if (NIT_ITERINDEX(iter) == NIT_ITERSTART(iter) &&
278 NBF_BUFITEREND(bufferdata) <= NIT_ITEREND(iter) &&
279 NBF_SIZE(bufferdata) > 0) {
280 return NPY_SUCCEED;
281 }
282 if (npyiter_copy_from_buffers(iter) < 0) {
283 if (errmsg != NULL) {
284 *errmsg = _reset_cast_error;
285 }
286 return NPY_FAIL;
287 }
288 }
289 }
290
291 npyiter_goto_iterindex(iter, NIT_ITERSTART(iter));
292
293 if (itflags&NPY_ITFLAG_BUFFER) {
294 /* Prepare the next buffers and set iterend/size */
295 if (npyiter_copy_to_buffers(iter, NULL) < 0) {
296 if (errmsg != NULL) {
297 *errmsg = _reset_cast_error;
298 }
299 return NPY_FAIL;
300 }
301 }
302
303 return NPY_SUCCEED;
304}
305
306/*NUMPY_API
307 * Resets the iterator to its initial state, with new base data pointers.

Callers 9

npyiter_resetFunction · 0.85
NpyIter_RemoveAxisFunction · 0.85
NpyIter_RemoveMultiIndexFunction · 0.85
array_subscriptFunction · 0.85
array_assign_subscriptFunction · 0.85
PyArray_MapIterResetFunction · 0.85
PyUFunc_ReduceWrapperFunction · 0.85

Calls 4

npyiter_allocate_buffersFunction · 0.85
npyiter_goto_iterindexFunction · 0.85
npyiter_copy_to_buffersFunction · 0.85

Tested by

no test coverage detected