* This function converts one element of the indexing tuple * into a step size and a number of steps, returning the * starting index. Non-slices are signalled in 'n_steps', * as NEWAXIS_INDEX, ELLIPSIS_INDEX, or SINGLE_INDEX. */
| 47 | * as NEWAXIS_INDEX, ELLIPSIS_INDEX, or SINGLE_INDEX. |
| 48 | */ |
| 49 | NPY_NO_EXPORT npy_intp |
| 50 | parse_index_entry(PyObject *op, npy_intp *step_size, |
| 51 | npy_intp *n_steps, npy_intp max, |
| 52 | int axis, int check_index) |
| 53 | { |
| 54 | npy_intp i; |
| 55 | |
| 56 | if (op == Py_None) { |
| 57 | *n_steps = NEWAXIS_INDEX; |
| 58 | i = 0; |
| 59 | } |
| 60 | else if (op == Py_Ellipsis) { |
| 61 | *n_steps = ELLIPSIS_INDEX; |
| 62 | i = 0; |
| 63 | } |
| 64 | else if (PySlice_Check(op)) { |
| 65 | npy_intp stop; |
| 66 | if (PySlice_GetIndicesEx(op, max, &i, &stop, step_size, n_steps) < 0) { |
| 67 | goto fail; |
| 68 | } |
| 69 | if (*n_steps <= 0) { |
| 70 | *n_steps = 0; |
| 71 | *step_size = 1; |
| 72 | i = 0; |
| 73 | } |
| 74 | } |
| 75 | else if (coerce_index(op, &i)) { |
| 76 | *n_steps = SINGLE_INDEX; |
| 77 | *step_size = 0; |
| 78 | if (check_index) { |
| 79 | if (check_and_adjust_index(&i, max, axis, NULL) < 0) { |
| 80 | goto fail; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | else { |
| 85 | PyErr_SetString(PyExc_IndexError, |
| 86 | "each index entry must be either a " |
| 87 | "slice, an integer, Ellipsis, or " |
| 88 | "newaxis"); |
| 89 | goto fail; |
| 90 | } |
| 91 | return i; |
| 92 | |
| 93 | fail: |
| 94 | return -1; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /*********************** Element-wise Array Iterator ***********************/ |
no test coverage detected