MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_IntpFromSequence

Function PyArray_IntpFromSequence

numpy/core/src/multiarray/conversion_utils.c:1116–1147  ·  view source on GitHub ↗

NUMPY_API * PyArray_IntpFromSequence * Returns the number of integers converted or -1 if an error occurred. * vals must be large enough to hold maxvals */

Source from the content-addressed store, hash-verified

1114 * vals must be large enough to hold maxvals
1115 */
1116NPY_NO_EXPORT int
1117PyArray_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/**

Callers 1

array_setstateFunction · 0.85

Calls 2

dimension_from_scalarFunction · 0.85

Tested by

no test coverage detected