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

Function NpyIter_EnableExternalLoop

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

NUMPY_API * Removes the inner loop handling (so HasExternalLoop returns true) */

Source from the content-addressed store, hash-verified

190 * Removes the inner loop handling (so HasExternalLoop returns true)
191 */
192NPY_NO_EXPORT int
193NpyIter_EnableExternalLoop(NpyIter *iter)
194{
195 npy_uint32 itflags = NIT_ITFLAGS(iter);
196 /*int ndim = NIT_NDIM(iter);*/
197 int nop = NIT_NOP(iter);
198
199 /* Check conditions under which this can be done */
200 if (itflags&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASMULTIINDEX)) {
201 PyErr_SetString(PyExc_ValueError,
202 "Iterator flag EXTERNAL_LOOP cannot be used "
203 "if an index or multi-index is being tracked");
204 return NPY_FAIL;
205 }
206 if ((itflags&(NPY_ITFLAG_BUFFER|NPY_ITFLAG_RANGE|NPY_ITFLAG_EXLOOP))
207 == (NPY_ITFLAG_RANGE|NPY_ITFLAG_EXLOOP)) {
208 PyErr_SetString(PyExc_ValueError,
209 "Iterator flag EXTERNAL_LOOP cannot be used "
210 "with ranged iteration unless buffering is also enabled");
211 return NPY_FAIL;
212 }
213 /* Set the flag */
214 if (!(itflags&NPY_ITFLAG_EXLOOP)) {
215 itflags |= NPY_ITFLAG_EXLOOP;
216 NIT_ITFLAGS(iter) = itflags;
217
218 /*
219 * Check whether we can apply the single iteration
220 * optimization to the iternext function.
221 */
222 if (!(itflags&NPY_ITFLAG_BUFFER)) {
223 NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
224 if (NIT_ITERSIZE(iter) == NAD_SHAPE(axisdata)) {
225 NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
226 }
227 }
228 }
229
230 /* Reset the iterator */
231 return NpyIter_Reset(iter, NULL);
232}
233
234
235static char *_reset_cast_error = (

Callers 3

arr_unravel_indexFunction · 0.85

Calls 1

NpyIter_ResetFunction · 0.85

Tested by

no test coverage detected