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

Function npyiter_seq_item

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

Source from the content-addressed store, hash-verified

1967}
1968
1969NPY_NO_EXPORT PyObject *
1970npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i)
1971{
1972 npy_intp ret_ndim;
1973 npy_intp nop, innerloopsize, innerstride;
1974 char *dataptr;
1975 PyArray_Descr *dtype;
1976 int has_external_loop;
1977 Py_ssize_t i_orig = i;
1978
1979 if (self->iter == NULL || self->finished) {
1980 PyErr_SetString(PyExc_ValueError,
1981 "Iterator is past the end");
1982 return NULL;
1983 }
1984
1985 if (NpyIter_HasDelayedBufAlloc(self->iter)) {
1986 PyErr_SetString(PyExc_ValueError,
1987 "Iterator construction used delayed buffer allocation, "
1988 "and no reset has been done yet");
1989 return NULL;
1990 }
1991 nop = NpyIter_GetNOp(self->iter);
1992
1993 /* Negative indexing */
1994 if (i < 0) {
1995 i += nop;
1996 }
1997
1998 if (i < 0 || i >= nop) {
1999 PyErr_Format(PyExc_IndexError,
2000 "Iterator operand index %zd is out of bounds", i_orig);
2001 return NULL;
2002 }
2003
2004#if 0
2005 /*
2006 * This check is disabled because it prevents things like
2007 * np.add(it[0], it[1], it[2]), where it[2] is a write-only
2008 * parameter. When write-only, the value of it[i] is
2009 * likely random junk, as if it were allocated with an
2010 * np.empty(...) call.
2011 */
2012 if (!self->readflags[i]) {
2013 PyErr_Format(PyExc_RuntimeError,
2014 "Iterator operand %zd is write-only", i);
2015 return NULL;
2016 }
2017#endif
2018
2019 dataptr = self->dataptrs[i];
2020 dtype = self->dtypes[i];
2021 has_external_loop = NpyIter_HasExternalLoop(self->iter);
2022
2023 if (has_external_loop) {
2024 innerloopsize = *self->innerloopsizeptr;
2025 innerstride = self->innerstrides[i];
2026 ret_ndim = 1;

Callers 3

npyiter_value_getFunction · 0.85
npyiter_seq_sliceFunction · 0.85
npyiter_subscriptFunction · 0.85

Calls 4

NpyIter_GetNOpFunction · 0.85
NpyIter_HasExternalLoopFunction · 0.85

Tested by

no test coverage detected