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

Function npyiter_convert_ops

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

* Converts the operand array and op_flags array into the form * NpyIter_AdvancedNew needs. Sets nop, and on success, each * op[i] owns a reference to an array object. */

Source from the content-addressed store, hash-verified

582 * op[i] owns a reference to an array object.
583 */
584static int
585npyiter_convert_ops(PyObject *op_in, PyObject *op_flags_in,
586 PyArrayObject **op, npy_uint32 *op_flags,
587 int *nop_out)
588{
589 int iop, nop;
590
591 /* nop and op */
592 if (PyTuple_Check(op_in) || PyList_Check(op_in)) {
593 nop = PySequence_Size(op_in);
594 if (nop == 0) {
595 PyErr_SetString(PyExc_ValueError,
596 "Must provide at least one operand");
597 return 0;
598 }
599 if (nop > NPY_MAXARGS) {
600 PyErr_SetString(PyExc_ValueError, "Too many operands");
601 return 0;
602 }
603
604 for (iop = 0; iop < nop; ++iop) {
605 PyObject *item = PySequence_GetItem(op_in, iop);
606 if (item == NULL) {
607 npy_intp i;
608 for (i = 0; i < iop; ++i) {
609 Py_XDECREF(op[i]);
610 }
611 return 0;
612 }
613 else if (item == Py_None) {
614 Py_DECREF(item);
615 item = NULL;
616 }
617 /* This is converted to an array after op flags are retrieved */
618 op[iop] = (PyArrayObject *)item;
619 }
620 }
621 else {
622 nop = 1;
623 /* Is converted to an array after op flags are retrieved */
624 Py_INCREF(op_in);
625 op[0] = (PyArrayObject *)op_in;
626 }
627
628 *nop_out = nop;
629
630 /* op_flags */
631 if (op_flags_in == NULL || op_flags_in == Py_None) {
632 for (iop = 0; iop < nop; ++iop) {
633 /*
634 * By default, make NULL operands writeonly and flagged for
635 * allocation, and everything else readonly. To write
636 * to a provided operand, you must specify the write flag manually.
637 */
638 if (op[iop] == NULL) {
639 op_flags[iop] = NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE;
640 }
641 else {

Callers 2

npyiter_initFunction · 0.85
NpyIter_NestedItersFunction · 0.85

Calls 1

Tested by

no test coverage detected