* Reads values from a sequence of integers and stores them into an array. * * @param seq A sequence created using `PySequence_Fast`. * @param vals Array used to store dimensions (must be large enough to * hold `maxvals` values). * @param max_vals Maximum number of dimensions that can be written into `vals`. * @return Number of dimensions or -1 if an
| 1089 | * for the number of values. |
| 1090 | */ |
| 1091 | NPY_NO_EXPORT npy_intp |
| 1092 | PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals) |
| 1093 | { |
| 1094 | /* |
| 1095 | * First of all, check if sequence is a scalar integer or if it can be |
| 1096 | * "casted" into a scalar. |
| 1097 | */ |
| 1098 | Py_ssize_t nd = PySequence_Fast_GET_SIZE(seq); |
| 1099 | PyObject *op; |
| 1100 | for (Py_ssize_t i = 0; i < PyArray_MIN(nd, maxvals); i++) { |
| 1101 | op = PySequence_Fast_GET_ITEM(seq, i); |
| 1102 | |
| 1103 | vals[i] = dimension_from_scalar(op); |
| 1104 | if (error_converting(vals[i])) { |
| 1105 | return -1; |
| 1106 | } |
| 1107 | } |
| 1108 | return nd; |
| 1109 | } |
| 1110 | |
| 1111 | /*NUMPY_API |
| 1112 | * PyArray_IntpFromSequence |
no test coverage detected