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

Function array_item

numpy/core/src/multiarray/mapping.c:1290–1312  ·  view source on GitHub ↗

* Python C-Api level item subscription (implementation for PySequence_GetItem) * * Negative indices are not accepted because PySequence_GetItem converts * them to positive indices before calling this. */

Source from the content-addressed store, hash-verified

1288 * them to positive indices before calling this.
1289 */
1290NPY_NO_EXPORT PyObject *
1291array_item(PyArrayObject *self, Py_ssize_t i)
1292{
1293 if (PyArray_NDIM(self) == 1) {
1294 char *item;
1295 npy_index_info index;
1296
1297 if (i < 0) {
1298 /* This is an error, but undo PySequence_GetItem fix for message */
1299 i -= PyArray_DIM(self, 0);
1300 }
1301
1302 index.value = i;
1303 index.type = HAS_INTEGER;
1304 if (get_item_pointer(self, &item, &index, 1) < 0) {
1305 return NULL;
1306 }
1307 return PyArray_Scalar(item, PyArray_DESCR(self), (PyObject *)self);
1308 }
1309 else {
1310 return array_item_asarray(self, i);
1311 }
1312}
1313
1314
1315/* make sure subscript always returns an array object */

Callers

nothing calls this directly

Calls 6

PyArray_NDIMFunction · 0.85
PyArray_DIMFunction · 0.85
get_item_pointerFunction · 0.85
PyArray_ScalarFunction · 0.85
PyArray_DESCRFunction · 0.85
array_item_asarrayFunction · 0.85

Tested by

no test coverage detected