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

Function npyiter_multi_index_set

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

Source from the content-addressed store, hash-verified

1574}
1575
1576static int
1577npyiter_multi_index_set(
1578 NewNpyArrayIterObject *self, PyObject *value, void *NPY_UNUSED(ignored))
1579{
1580 npy_intp idim, ndim, multi_index[NPY_MAXDIMS];
1581
1582 if (value == NULL) {
1583 PyErr_SetString(PyExc_AttributeError,
1584 "Cannot delete nditer multi_index");
1585 return -1;
1586 }
1587 if (self->iter == NULL) {
1588 PyErr_SetString(PyExc_ValueError,
1589 "Iterator is invalid");
1590 return -1;
1591 }
1592
1593 if (NpyIter_HasMultiIndex(self->iter)) {
1594 ndim = NpyIter_GetNDim(self->iter);
1595 if (!PySequence_Check(value)) {
1596 PyErr_SetString(PyExc_ValueError,
1597 "multi_index must be set with a sequence");
1598 return -1;
1599 }
1600 if (PySequence_Size(value) != ndim) {
1601 PyErr_SetString(PyExc_ValueError,
1602 "Wrong number of indices");
1603 return -1;
1604 }
1605 for (idim = 0; idim < ndim; ++idim) {
1606 PyObject *v = PySequence_GetItem(value, idim);
1607 multi_index[idim] = PyLong_AsLong(v);
1608 Py_DECREF(v);
1609 if (error_converting(multi_index[idim])) {
1610 return -1;
1611 }
1612 }
1613 if (NpyIter_GotoMultiIndex(self->iter, multi_index) != NPY_SUCCEED) {
1614 return -1;
1615 }
1616 self->started = 0;
1617 self->finished = 0;
1618
1619 /* If there is nesting, the nested iterators should be reset */
1620 if (npyiter_resetbasepointers(self) != NPY_SUCCEED) {
1621 return -1;
1622 }
1623
1624 return 0;
1625 }
1626 else {
1627 PyErr_SetString(PyExc_ValueError,
1628 "Iterator is not tracking a multi-index");
1629 return -1;
1630 }
1631}
1632
1633static PyObject *

Callers

nothing calls this directly

Calls 4

NpyIter_HasMultiIndexFunction · 0.85
NpyIter_GetNDimFunction · 0.85
NpyIter_GotoMultiIndexFunction · 0.85

Tested by

no test coverage detected