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

Function npyiter_check_per_op_flags

numpy/core/src/multiarray/nditer_constr.c:925–1010  ·  view source on GitHub ↗

* Checks the per-operand input flags, and fills in op_itflags. * * Returns 1 on success, 0 on failure. */

Source from the content-addressed store, hash-verified

923 * Returns 1 on success, 0 on failure.
924 */
925static int
926npyiter_check_per_op_flags(npy_uint32 op_flags, npyiter_opitflags *op_itflags)
927{
928 if ((op_flags & NPY_ITER_GLOBAL_FLAGS) != 0) {
929 PyErr_SetString(PyExc_ValueError,
930 "A global iterator flag was passed as a per-operand flag "
931 "to the iterator constructor");
932 return 0;
933 }
934
935 /* Check the read/write flags */
936 if (op_flags & NPY_ITER_READONLY) {
937 /* The read/write flags are mutually exclusive */
938 if (op_flags & (NPY_ITER_READWRITE|NPY_ITER_WRITEONLY)) {
939 PyErr_SetString(PyExc_ValueError,
940 "Only one of the iterator flags READWRITE, "
941 "READONLY, and WRITEONLY may be "
942 "specified for an operand");
943 return 0;
944 }
945
946 *op_itflags = NPY_OP_ITFLAG_READ;
947 }
948 else if (op_flags & NPY_ITER_READWRITE) {
949 /* The read/write flags are mutually exclusive */
950 if (op_flags & NPY_ITER_WRITEONLY) {
951 PyErr_SetString(PyExc_ValueError,
952 "Only one of the iterator flags READWRITE, "
953 "READONLY, and WRITEONLY may be "
954 "specified for an operand");
955 return 0;
956 }
957
958 *op_itflags = NPY_OP_ITFLAG_READ|NPY_OP_ITFLAG_WRITE;
959 }
960 else if(op_flags & NPY_ITER_WRITEONLY) {
961 *op_itflags = NPY_OP_ITFLAG_WRITE;
962 }
963 else {
964 PyErr_SetString(PyExc_ValueError,
965 "None of the iterator flags READWRITE, "
966 "READONLY, or WRITEONLY were "
967 "specified for an operand");
968 return 0;
969 }
970
971 /* Check the flags for temporary copies */
972 if (((*op_itflags) & NPY_OP_ITFLAG_WRITE) &&
973 (op_flags & (NPY_ITER_COPY |
974 NPY_ITER_UPDATEIFCOPY)) == NPY_ITER_COPY) {
975 PyErr_SetString(PyExc_ValueError,
976 "If an iterator operand is writeable, must use "
977 "the flag UPDATEIFCOPY instead of "
978 "COPY");
979 return 0;
980 }
981
982 /* Check the flag for a write masked operands */

Callers 1

npyiter_prepare_operandsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected