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

Function multiiter_new_impl

numpy/core/src/multiarray/iterators.c:1255–1323  ·  view source on GitHub ↗

* Common implementation for all PyArrayMultiIterObject constructors. */

Source from the content-addressed store, hash-verified

1253 * Common implementation for all PyArrayMultiIterObject constructors.
1254 */
1255static PyObject*
1256multiiter_new_impl(int n_args, PyObject **args)
1257{
1258 PyArrayMultiIterObject *multi;
1259 int i;
1260
1261 multi = PyArray_malloc(sizeof(PyArrayMultiIterObject));
1262 if (multi == NULL) {
1263 return PyErr_NoMemory();
1264 }
1265 PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
1266 multi->numiter = 0;
1267
1268 for (i = 0; i < n_args; ++i) {
1269 PyObject *obj = args[i];
1270 PyObject *arr;
1271 PyArrayIterObject *it;
1272
1273 if (PyObject_IsInstance(obj, (PyObject *)&PyArrayMultiIter_Type)) {
1274 PyArrayMultiIterObject *mit = (PyArrayMultiIterObject *)obj;
1275 int j;
1276
1277 if (multi->numiter + mit->numiter > NPY_MAXARGS) {
1278 multiiter_wrong_number_of_args();
1279 goto fail;
1280 }
1281 for (j = 0; j < mit->numiter; ++j) {
1282 arr = (PyObject *)mit->iters[j]->ao;
1283 it = (PyArrayIterObject *)PyArray_IterNew(arr);
1284 if (it == NULL) {
1285 goto fail;
1286 }
1287 multi->iters[multi->numiter++] = it;
1288 }
1289 }
1290 else if (multi->numiter < NPY_MAXARGS) {
1291 arr = PyArray_FromAny(obj, NULL, 0, 0, 0, NULL);
1292 if (arr == NULL) {
1293 goto fail;
1294 }
1295 it = (PyArrayIterObject *)PyArray_IterNew(arr);
1296 Py_DECREF(arr);
1297 if (it == NULL) {
1298 goto fail;
1299 }
1300 multi->iters[multi->numiter++] = it;
1301 }
1302 else {
1303 multiiter_wrong_number_of_args();
1304 goto fail;
1305 }
1306 }
1307
1308 if (multi->numiter < 0) {
1309 multiiter_wrong_number_of_args();
1310 goto fail;
1311 }
1312 if (PyArray_Broadcast(multi) < 0) {

Callers 3

PyArray_MultiIterNewFunction · 0.85
arraymultiter_newFunction · 0.85

Calls 4

PyArray_IterNewFunction · 0.85
PyArray_FromAnyFunction · 0.85
PyArray_BroadcastFunction · 0.85

Tested by

no test coverage detected