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

Function npyiter_seq_ass_item

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

Source from the content-addressed store, hash-verified

2090}
2091
2092NPY_NO_EXPORT int
2093npyiter_seq_ass_item(NewNpyArrayIterObject *self, Py_ssize_t i, PyObject *v)
2094{
2095
2096 npy_intp nop, innerloopsize, innerstride;
2097 char *dataptr;
2098 PyArray_Descr *dtype;
2099 PyArrayObject *tmp;
2100 int ret, has_external_loop;
2101 Py_ssize_t i_orig = i;
2102
2103
2104 if (v == NULL) {
2105 PyErr_SetString(PyExc_TypeError,
2106 "Cannot delete iterator elements");
2107 return -1;
2108 }
2109
2110 if (self->iter == NULL || self->finished) {
2111 PyErr_SetString(PyExc_ValueError,
2112 "Iterator is past the end");
2113 return -1;
2114 }
2115
2116 if (NpyIter_HasDelayedBufAlloc(self->iter)) {
2117 PyErr_SetString(PyExc_ValueError,
2118 "Iterator construction used delayed buffer allocation, "
2119 "and no reset has been done yet");
2120 return -1;
2121 }
2122 nop = NpyIter_GetNOp(self->iter);
2123
2124 /* Negative indexing */
2125 if (i < 0) {
2126 i += nop;
2127 }
2128
2129 if (i < 0 || i >= nop) {
2130 PyErr_Format(PyExc_IndexError,
2131 "Iterator operand index %zd is out of bounds", i_orig);
2132 return -1;
2133 }
2134 if (!self->writeflags[i]) {
2135 PyErr_Format(PyExc_RuntimeError,
2136 "Iterator operand %zd is not writeable", i_orig);
2137 return -1;
2138 }
2139
2140 dataptr = self->dataptrs[i];
2141 dtype = self->dtypes[i];
2142 has_external_loop = NpyIter_HasExternalLoop(self->iter);
2143
2144 if (has_external_loop) {
2145 innerloopsize = *self->innerloopsizeptr;
2146 innerstride = self->innerstrides[i];
2147 }
2148 else {
2149 innerloopsize = 1;

Callers 2

npyiter_seq_ass_sliceFunction · 0.85
npyiter_ass_subscriptFunction · 0.85

Calls 5

NpyIter_GetNOpFunction · 0.85
NpyIter_HasExternalLoopFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_CopyObjectFunction · 0.85

Tested by

no test coverage detected