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

Function npyiter_copy

numpy/core/src/multiarray/nditer_pywrap.c:1230–1264  ·  view source on GitHub ↗

* Makes a copy of the iterator. Note that the nesting is not * copied. */

Source from the content-addressed store, hash-verified

1228 * copied.
1229 */
1230static PyObject *
1231npyiter_copy(NewNpyArrayIterObject *self, PyObject *NPY_UNUSED(args))
1232{
1233 NewNpyArrayIterObject *iter;
1234
1235 if (self->iter == NULL) {
1236 PyErr_SetString(PyExc_ValueError,
1237 "Iterator is invalid");
1238 return NULL;
1239 }
1240
1241 /* Allocate the iterator */
1242 iter = (NewNpyArrayIterObject *)npyiter_new(&NpyIter_Type, NULL, NULL);
1243 if (iter == NULL) {
1244 return NULL;
1245 }
1246
1247 /* Copy the C iterator */
1248 iter->iter = NpyIter_Copy(self->iter);
1249 if (iter->iter == NULL) {
1250 Py_DECREF(iter);
1251 return NULL;
1252 }
1253
1254 /* Cache some values for the member functions to use */
1255 if (npyiter_cache_values(iter) < 0) {
1256 Py_DECREF(iter);
1257 return NULL;
1258 }
1259
1260 iter->started = self->started;
1261 iter->finished = self->finished;
1262
1263 return (PyObject *)iter;
1264}
1265
1266static PyObject *
1267npyiter_iternext(NewNpyArrayIterObject *self, PyObject *NPY_UNUSED(args))

Callers

nothing calls this directly

Calls 3

npyiter_newFunction · 0.85
NpyIter_CopyFunction · 0.85
npyiter_cache_valuesFunction · 0.85

Tested by

no test coverage detected