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

Function NpyIter_OpFlagsConverter

numpy/core/src/multiarray/nditer_pywrap.c:236–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236static int
237NpyIter_OpFlagsConverter(PyObject *op_flags_in,
238 npy_uint32 *op_flags)
239{
240 int iflags, nflags;
241 npy_uint32 flag;
242
243 if (!PyTuple_Check(op_flags_in) && !PyList_Check(op_flags_in)) {
244 PyErr_SetString(PyExc_ValueError,
245 "op_flags must be a tuple or array of per-op flag-tuples");
246 return 0;
247 }
248
249 nflags = PySequence_Size(op_flags_in);
250
251 *op_flags = 0;
252 for (iflags = 0; iflags < nflags; ++iflags) {
253 PyObject *f;
254 char *str = NULL;
255 Py_ssize_t length = 0;
256
257 f = PySequence_GetItem(op_flags_in, iflags);
258 if (f == NULL) {
259 return 0;
260 }
261
262 if (PyUnicode_Check(f)) {
263 /* accept unicode input */
264 PyObject *f_str;
265 f_str = PyUnicode_AsASCIIString(f);
266 if (f_str == NULL) {
267 Py_DECREF(f);
268 return 0;
269 }
270 Py_DECREF(f);
271 f = f_str;
272 }
273
274 if (PyBytes_AsStringAndSize(f, &str, &length) < 0) {
275 PyErr_Clear();
276 Py_DECREF(f);
277 PyErr_SetString(PyExc_ValueError,
278 "op_flags must be a tuple or array of per-op flag-tuples");
279 return 0;
280 }
281
282 /* Use switch statements to quickly isolate the right flag */
283 flag = 0;
284 switch (str[0]) {
285 case 'a':
286 if (length > 2) switch(str[2]) {
287 case 'i':
288 if (strcmp(str, "aligned") == 0) {
289 flag = NPY_ITER_ALIGNED;
290 }
291 break;
292 case 'l':
293 if (strcmp(str, "allocate") == 0) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected