* 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. */
| 1254 | * positive indices. |
| 1255 | */ |
| 1256 | NPY_NO_EXPORT PyObject * |
| 1257 | array_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 | /* |
no test coverage detected