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

Function array_subscript

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

* General function for indexing a NumPy array with a Python object. */

Source from the content-addressed store, hash-verified

1432 * General function for indexing a NumPy array with a Python object.
1433 */
1434NPY_NO_EXPORT PyObject *
1435array_subscript(PyArrayObject *self, PyObject *op)
1436{
1437 int index_type;
1438 int index_num;
1439 int i, ndim, fancy_ndim;
1440 NPY_cast_info cast_info = {.func = NULL};
1441
1442 /*
1443 * Index info array. We can have twice as many indices as dimensions
1444 * (because of None). The + 1 is to not need to check as much.
1445 */
1446 npy_index_info indices[NPY_MAXDIMS * 2 + 1];
1447
1448 PyArrayObject *view = NULL;
1449 PyObject *result = NULL;
1450
1451 PyArrayMapIterObject * mit = NULL;
1452
1453 /* return fields if op is a string index */
1454 if (PyDataType_HASFIELDS(PyArray_DESCR(self))) {
1455 PyArrayObject *view;
1456 int ret = _get_field_view(self, op, &view);
1457 if (ret == 0){
1458 if (view == NULL) {
1459 return NULL;
1460 }
1461 return (PyObject*)view;
1462 }
1463 }
1464
1465 /* Prepare the indices */
1466 index_type = prepare_index(self, op, indices, &index_num,
1467 &ndim, &fancy_ndim, 1);
1468
1469 if (index_type < 0) {
1470 return NULL;
1471 }
1472
1473 /* Full integer index */
1474 else if (index_type == HAS_INTEGER) {
1475 char *item;
1476 if (get_item_pointer(self, &item, indices, index_num) < 0) {
1477 goto finish;
1478 }
1479 result = (PyObject *) PyArray_Scalar(item, PyArray_DESCR(self),
1480 (PyObject *)self);
1481 /* Because the index is full integer, we do not need to decref */
1482 return result;
1483 }
1484
1485 /* Single boolean array */
1486 else if (index_type == HAS_BOOL) {
1487 result = (PyObject *)array_boolean_subscript(self,
1488 (PyArrayObject *)indices[0].object,
1489 NPY_CORDER);
1490 goto finish;
1491 }

Callers 1

array_subscript_asarrayFunction · 0.85

Calls 15

PyArray_DESCRFunction · 0.85
_get_field_viewFunction · 0.85
prepare_indexFunction · 0.85
get_item_pointerFunction · 0.85
PyArray_ScalarFunction · 0.85
array_boolean_subscriptFunction · 0.85
PyArray_ViewFunction · 0.85
get_view_from_indexFunction · 0.85
PyArray_NewCopyFunction · 0.85
PyArray_ITEMSIZEFunction · 0.85
IsUintAlignedFunction · 0.85
PyArray_NewFromDescrFunction · 0.85

Tested by

no test coverage detected