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

Function NpyIter_GetIterView

numpy/core/src/multiarray/nditer_api.c:1155–1205  ·  view source on GitHub ↗

NUMPY_API * Returns a view to the i-th object with the iterator's internal axes */

Source from the content-addressed store, hash-verified

1153 * Returns a view to the i-th object with the iterator's internal axes
1154 */
1155NPY_NO_EXPORT PyArrayObject *
1156NpyIter_GetIterView(NpyIter *iter, npy_intp i)
1157{
1158 npy_uint32 itflags = NIT_ITFLAGS(iter);
1159 int idim, ndim = NIT_NDIM(iter);
1160 int nop = NIT_NOP(iter);
1161
1162 npy_intp shape[NPY_MAXDIMS], strides[NPY_MAXDIMS];
1163 PyArrayObject *obj, *view;
1164 PyArray_Descr *dtype;
1165 char *dataptr;
1166 NpyIter_AxisData *axisdata;
1167 npy_intp sizeof_axisdata;
1168 int writeable;
1169
1170 if (i < 0) {
1171 PyErr_SetString(PyExc_IndexError,
1172 "index provided for an iterator view was out of bounds");
1173 return NULL;
1174 }
1175
1176 /* Don't provide views if buffering is enabled */
1177 if (itflags&NPY_ITFLAG_BUFFER) {
1178 PyErr_SetString(PyExc_ValueError,
1179 "cannot provide an iterator view when buffering is enabled");
1180 return NULL;
1181 }
1182
1183 obj = NIT_OPERANDS(iter)[i];
1184 dtype = PyArray_DESCR(obj);
1185 writeable = NIT_OPITFLAGS(iter)[i]&NPY_OP_ITFLAG_WRITE;
1186 dataptr = NIT_RESETDATAPTR(iter)[i];
1187 axisdata = NIT_AXISDATA(iter);
1188 sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
1189
1190 /* Retrieve the shape and strides from the axisdata */
1191 for (idim = 0; idim < ndim; ++idim) {
1192 shape[ndim-idim-1] = NAD_SHAPE(axisdata);
1193 strides[ndim-idim-1] = NAD_STRIDES(axisdata)[i];
1194
1195 NIT_ADVANCE_AXISDATA(axisdata, 1);
1196 }
1197
1198 Py_INCREF(dtype);
1199 view = (PyArrayObject *)PyArray_NewFromDescrAndBase(
1200 &PyArray_Type, dtype,
1201 ndim, shape, strides, dataptr,
1202 writeable ? NPY_ARRAY_WRITEABLE : 0, NULL, (PyObject *)obj);
1203
1204 return view;
1205}
1206
1207/*NUMPY_API
1208 * Get a pointer to the index, if it is being tracked

Callers 1

npyiter_itviews_getFunction · 0.85

Calls 2

PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected