* 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. */
| 1288 | * them to positive indices before calling this. |
| 1289 | */ |
| 1290 | NPY_NO_EXPORT PyObject * |
| 1291 | array_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 */ |
nothing calls this directly
no test coverage detected