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

Function npyiter_seq_ass_slice

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

Source from the content-addressed store, hash-verified

2166}
2167
2168static int
2169npyiter_seq_ass_slice(NewNpyArrayIterObject *self, Py_ssize_t ilow,
2170 Py_ssize_t ihigh, PyObject *v)
2171{
2172 npy_intp nop;
2173 Py_ssize_t i;
2174
2175 if (v == NULL) {
2176 PyErr_SetString(PyExc_TypeError,
2177 "Cannot delete iterator elements");
2178 return -1;
2179 }
2180
2181 if (self->iter == NULL || self->finished) {
2182 PyErr_SetString(PyExc_ValueError,
2183 "Iterator is past the end");
2184 return -1;
2185 }
2186
2187 if (NpyIter_HasDelayedBufAlloc(self->iter)) {
2188 PyErr_SetString(PyExc_ValueError,
2189 "Iterator construction used delayed buffer allocation, "
2190 "and no reset has been done yet");
2191 return -1;
2192 }
2193 nop = NpyIter_GetNOp(self->iter);
2194 if (ilow < 0) {
2195 ilow = 0;
2196 }
2197 else if (ilow >= nop) {
2198 ilow = nop-1;
2199 }
2200 if (ihigh < ilow) {
2201 ihigh = ilow;
2202 }
2203 else if (ihigh > nop) {
2204 ihigh = nop;
2205 }
2206
2207 if (!PySequence_Check(v) || PySequence_Size(v) != ihigh-ilow) {
2208 PyErr_SetString(PyExc_ValueError,
2209 "Wrong size to assign to iterator slice");
2210 return -1;
2211 }
2212
2213 for (i = ilow; i < ihigh ; ++i) {
2214 PyObject *item = PySequence_GetItem(v, i-ilow);
2215 if (item == NULL) {
2216 return -1;
2217 }
2218 if (npyiter_seq_ass_item(self, i, item) < 0) {
2219 Py_DECREF(item);
2220 return -1;
2221 }
2222 Py_DECREF(item);
2223 }
2224
2225 return 0;

Callers 1

npyiter_ass_subscriptFunction · 0.85

Calls 3

NpyIter_GetNOpFunction · 0.85
npyiter_seq_ass_itemFunction · 0.85

Tested by

no test coverage detected