* General function for indexing a NumPy array with a Python object. */
| 1432 | * General function for indexing a NumPy array with a Python object. |
| 1433 | */ |
| 1434 | NPY_NO_EXPORT PyObject * |
| 1435 | array_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 | } |
no test coverage detected