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

Function npyiter_convert_op_flags_array

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

Source from the content-addressed store, hash-verified

390}
391
392static int
393npyiter_convert_op_flags_array(PyObject *op_flags_in,
394 npy_uint32 *op_flags_array, npy_intp nop)
395{
396 npy_intp iop;
397
398 if (!PyTuple_Check(op_flags_in) && !PyList_Check(op_flags_in)) {
399 PyErr_SetString(PyExc_ValueError,
400 "op_flags must be a tuple or array of per-op flag-tuples");
401 return 0;
402 }
403
404 if (PySequence_Size(op_flags_in) != nop) {
405 goto try_single_flags;
406 }
407
408 for (iop = 0; iop < nop; ++iop) {
409 PyObject *f = PySequence_GetItem(op_flags_in, iop);
410 if (f == NULL) {
411 return 0;
412 }
413 /* If the first item is a string, try as one set of flags */
414 if (iop == 0 && (PyBytes_Check(f) || PyUnicode_Check(f))) {
415 Py_DECREF(f);
416 goto try_single_flags;
417 }
418 if (NpyIter_OpFlagsConverter(f,
419 &op_flags_array[iop]) != 1) {
420 Py_DECREF(f);
421 return 0;
422 }
423
424 Py_DECREF(f);
425 }
426
427 return 1;
428
429try_single_flags:
430 if (NpyIter_OpFlagsConverter(op_flags_in,
431 &op_flags_array[0]) != 1) {
432 return 0;
433 }
434
435 for (iop = 1; iop < nop; ++iop) {
436 op_flags_array[iop] = op_flags_array[0];
437 }
438
439 return 1;
440}
441
442static int
443npyiter_convert_dtypes(PyObject *op_dtypes_in,

Callers 1

npyiter_convert_opsFunction · 0.85

Calls 1

NpyIter_OpFlagsConverterFunction · 0.85

Tested by

no test coverage detected