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

Function array_item_asarray

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

* C-level integer indexing always returning an array and never a scalar. * Works also for subclasses, but it will not be called on one from the * Python API. * * This function does not accept negative indices because it is called by * PySequence_GetItem (through array_item) and that converts them to * positive indices. */

Source from the content-addressed store, hash-verified

1254 * positive indices.
1255 */
1256NPY_NO_EXPORT PyObject *
1257array_item_asarray(PyArrayObject *self, npy_intp i)
1258{
1259 npy_index_info indices[2];
1260 PyObject *result;
1261
1262 if (PyArray_NDIM(self) == 0) {
1263 PyErr_SetString(PyExc_IndexError,
1264 "too many indices for array");
1265 return NULL;
1266 }
1267 if (i < 0) {
1268 /* This is an error, but undo PySequence_GetItem fix for message */
1269 i -= PyArray_DIM(self, 0);
1270 }
1271
1272 indices[0].value = i;
1273 indices[0].type = HAS_INTEGER;
1274 indices[1].value = PyArray_NDIM(self) - 1;
1275 indices[1].type = HAS_ELLIPSIS;
1276 if (get_view_from_index(self, (PyArrayObject **)&result,
1277 indices, 2, 0) < 0) {
1278 return NULL;
1279 }
1280 return result;
1281}
1282
1283
1284/*

Callers 3

array_itemFunction · 0.85

Calls 3

PyArray_NDIMFunction · 0.85
PyArray_DIMFunction · 0.85
get_view_from_indexFunction · 0.85

Tested by

no test coverage detected