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

Function PyArray_MapIterReset

numpy/core/src/multiarray/mapping.c:2255–2299  ·  view source on GitHub ↗

Reset the map iterator to the beginning */

Source from the content-addressed store, hash-verified

2253
2254/* Reset the map iterator to the beginning */
2255NPY_NO_EXPORT int
2256PyArray_MapIterReset(PyArrayMapIterObject *mit)
2257{
2258 npy_intp indval;
2259 char *baseptrs[2];
2260 int i;
2261
2262 if (mit->size == 0) {
2263 return 0;
2264 }
2265
2266 if (!NpyIter_Reset(mit->outer, NULL)) {
2267 return -1;
2268 }
2269 if (mit->extra_op_iter) {
2270 if (!NpyIter_Reset(mit->extra_op_iter, NULL)) {
2271 return -1;
2272 }
2273
2274 baseptrs[1] = mit->extra_op_ptrs[0];
2275 }
2276
2277 baseptrs[0] = mit->baseoffset;
2278
2279 for (i = 0; i < mit->numiter; i++) {
2280 indval = *((npy_intp*)mit->outer_ptrs[i]);
2281 if (indval < 0) {
2282 indval += mit->fancy_dims[i];
2283 }
2284 baseptrs[0] += indval * mit->fancy_strides[i];
2285 }
2286 mit->dataptr = baseptrs[0];
2287
2288 if (mit->subspace_iter) {
2289 if (!NpyIter_ResetBasePointers(mit->subspace_iter, baseptrs, NULL)) {
2290 return -1;
2291 }
2292 mit->iter_count = *NpyIter_GetInnerLoopSizePtr(mit->subspace_iter);
2293 }
2294 else {
2295 mit->iter_count = *NpyIter_GetInnerLoopSizePtr(mit->outer);
2296 }
2297
2298 return 0;
2299}
2300
2301
2302/*NUMPY_API

Callers 1

Calls 3

NpyIter_ResetFunction · 0.85

Tested by

no test coverage detected