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

Function npyiter_subscript

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

Source from the content-addressed store, hash-verified

2226}
2227
2228static PyObject *
2229npyiter_subscript(NewNpyArrayIterObject *self, PyObject *op)
2230{
2231 if (self->iter == NULL || self->finished) {
2232 PyErr_SetString(PyExc_ValueError,
2233 "Iterator is past the end");
2234 return NULL;
2235 }
2236
2237 if (NpyIter_HasDelayedBufAlloc(self->iter)) {
2238 PyErr_SetString(PyExc_ValueError,
2239 "Iterator construction used delayed buffer allocation, "
2240 "and no reset has been done yet");
2241 return NULL;
2242 }
2243
2244 if (PyLong_Check(op) ||
2245 (PyIndex_Check(op) && !PySequence_Check(op))) {
2246 npy_intp i = PyArray_PyIntAsIntp(op);
2247 if (error_converting(i)) {
2248 return NULL;
2249 }
2250 return npyiter_seq_item(self, i);
2251 }
2252 else if (PySlice_Check(op)) {
2253 Py_ssize_t istart = 0, iend = 0, istep = 0, islicelength;
2254 if (PySlice_GetIndicesEx(op, NpyIter_GetNOp(self->iter),
2255 &istart, &iend, &istep, &islicelength) < 0) {
2256 return NULL;
2257 }
2258 if (istep != 1) {
2259 PyErr_SetString(PyExc_ValueError,
2260 "Iterator slicing only supports a step of 1");
2261 return NULL;
2262 }
2263 return npyiter_seq_slice(self, istart, iend);
2264 }
2265
2266 PyErr_SetString(PyExc_TypeError,
2267 "invalid index type for iterator indexing");
2268 return NULL;
2269}
2270
2271static int
2272npyiter_ass_subscript(NewNpyArrayIterObject *self, PyObject *op,

Callers

nothing calls this directly

Calls 5

PyArray_PyIntAsIntpFunction · 0.85
npyiter_seq_itemFunction · 0.85
NpyIter_GetNOpFunction · 0.85
npyiter_seq_sliceFunction · 0.85

Tested by

no test coverage detected