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

Function npyiter_prepare_one_operand

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

* Prepares a constructor operand. Assumes a reference to 'op' * is owned, and that 'op' may be replaced. Fills in 'op_dataptr', * 'op_dtype', and may modify 'op_itflags'. * * Returns 1 on success, 0 on failure. */

Source from the content-addressed store, hash-verified

1017 * Returns 1 on success, 0 on failure.
1018 */
1019static int
1020npyiter_prepare_one_operand(PyArrayObject **op,
1021 char **op_dataptr,
1022 PyArray_Descr *op_request_dtype,
1023 PyArray_Descr **op_dtype,
1024 npy_uint32 flags,
1025 npy_uint32 op_flags, npyiter_opitflags *op_itflags)
1026{
1027 /* NULL operands must be automatically allocated outputs */
1028 if (*op == NULL) {
1029 /* ALLOCATE or VIRTUAL should be enabled */
1030 if ((op_flags & (NPY_ITER_ALLOCATE|NPY_ITER_VIRTUAL)) == 0) {
1031 PyErr_SetString(PyExc_ValueError,
1032 "Iterator operand was NULL, but neither the "
1033 "ALLOCATE nor the VIRTUAL flag was specified");
1034 return 0;
1035 }
1036
1037 if (op_flags & NPY_ITER_ALLOCATE) {
1038 /* Writing should be enabled */
1039 if (!((*op_itflags) & NPY_OP_ITFLAG_WRITE)) {
1040 PyErr_SetString(PyExc_ValueError,
1041 "Automatic allocation was requested for an iterator "
1042 "operand, but it wasn't flagged for writing");
1043 return 0;
1044 }
1045 /*
1046 * Reading should be disabled if buffering is enabled without
1047 * also enabling NPY_ITER_DELAY_BUFALLOC. In all other cases,
1048 * the caller may initialize the allocated operand to a value
1049 * before beginning iteration.
1050 */
1051 if (((flags & (NPY_ITER_BUFFERED |
1052 NPY_ITER_DELAY_BUFALLOC)) == NPY_ITER_BUFFERED) &&
1053 ((*op_itflags) & NPY_OP_ITFLAG_READ)) {
1054 PyErr_SetString(PyExc_ValueError,
1055 "Automatic allocation was requested for an iterator "
1056 "operand, and it was flagged as readable, but "
1057 "buffering without delayed allocation was enabled");
1058 return 0;
1059 }
1060
1061 /* If a requested dtype was provided, use it, otherwise NULL */
1062 Py_XINCREF(op_request_dtype);
1063 *op_dtype = op_request_dtype;
1064 }
1065 else {
1066 *op_dtype = NULL;
1067 }
1068
1069 /* Specify bool if no dtype was requested for the mask */
1070 if (op_flags & NPY_ITER_ARRAYMASK) {
1071 if (*op_dtype == NULL) {
1072 *op_dtype = PyArray_DescrFromType(NPY_BOOL);
1073 if (*op_dtype == NULL) {
1074 return 0;
1075 }
1076 }

Callers 1

npyiter_prepare_operandsFunction · 0.85

Calls 6

PyArray_BYTESFunction · 0.85
PyArray_DESCRFunction · 0.85
IsAlignedFunction · 0.85

Tested by

no test coverage detected