NUMPY_API * PyArray_IntpFromSequence * Returns the number of integers converted or -1 if an error occurred. * vals must be large enough to hold maxvals */
| 1114 | * vals must be large enough to hold maxvals |
| 1115 | */ |
| 1116 | NPY_NO_EXPORT int |
| 1117 | PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals) |
| 1118 | { |
| 1119 | PyObject *seq_obj = NULL; |
| 1120 | if (!PyLong_CheckExact(seq) && PySequence_Check(seq)) { |
| 1121 | seq_obj = PySequence_Fast(seq, |
| 1122 | "expected a sequence of integers or a single integer"); |
| 1123 | if (seq_obj == NULL) { |
| 1124 | /* continue attempting to parse as a single integer. */ |
| 1125 | PyErr_Clear(); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | if (seq_obj == NULL) { |
| 1130 | vals[0] = dimension_from_scalar(seq); |
| 1131 | if (error_converting(vals[0])) { |
| 1132 | if (PyErr_ExceptionMatches(PyExc_TypeError)) { |
| 1133 | PyErr_Format(PyExc_TypeError, |
| 1134 | "expected a sequence of integers or a single " |
| 1135 | "integer, got '%.100R'", seq); |
| 1136 | } |
| 1137 | return -1; |
| 1138 | } |
| 1139 | return 1; |
| 1140 | } |
| 1141 | else { |
| 1142 | int res; |
| 1143 | res = PyArray_IntpFromIndexSequence(seq_obj, vals, (npy_intp)maxvals); |
| 1144 | Py_DECREF(seq_obj); |
| 1145 | return res; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | /** |
no test coverage detected