| 1292 | |
| 1293 | |
| 1294 | static int |
| 1295 | npyiter_check_casting(int nop, PyArrayObject **op, |
| 1296 | PyArray_Descr **op_dtype, |
| 1297 | NPY_CASTING casting, |
| 1298 | npyiter_opitflags *op_itflags) |
| 1299 | { |
| 1300 | int iop; |
| 1301 | |
| 1302 | for(iop = 0; iop < nop; ++iop) { |
| 1303 | NPY_IT_DBG_PRINT1("Iterator: Checking casting for operand %d\n", |
| 1304 | (int)iop); |
| 1305 | #if NPY_IT_DBG_TRACING |
| 1306 | printf("op: "); |
| 1307 | if (op[iop] != NULL) { |
| 1308 | PyObject_Print((PyObject *)PyArray_DESCR(op[iop]), stdout, 0); |
| 1309 | } |
| 1310 | else { |
| 1311 | printf("<null>"); |
| 1312 | } |
| 1313 | printf(", iter: "); |
| 1314 | PyObject_Print((PyObject *)op_dtype[iop], stdout, 0); |
| 1315 | printf("\n"); |
| 1316 | #endif |
| 1317 | /* If the types aren't equivalent, a cast is necessary */ |
| 1318 | if (op[iop] != NULL && !PyArray_EquivTypes(PyArray_DESCR(op[iop]), |
| 1319 | op_dtype[iop])) { |
| 1320 | /* Check read (op -> temp) casting */ |
| 1321 | if ((op_itflags[iop] & NPY_OP_ITFLAG_READ) && |
| 1322 | !PyArray_CanCastArrayTo(op[iop], |
| 1323 | op_dtype[iop], |
| 1324 | casting)) { |
| 1325 | PyErr_Format(PyExc_TypeError, |
| 1326 | "Iterator operand %d dtype could not be cast from " |
| 1327 | "%R to %R according to the rule %s", |
| 1328 | iop, PyArray_DESCR(op[iop]), op_dtype[iop], |
| 1329 | npyiter_casting_to_string(casting)); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | /* Check write (temp -> op) casting */ |
| 1333 | if ((op_itflags[iop] & NPY_OP_ITFLAG_WRITE) && |
| 1334 | !PyArray_CanCastTypeTo(op_dtype[iop], |
| 1335 | PyArray_DESCR(op[iop]), |
| 1336 | casting)) { |
| 1337 | PyErr_Format(PyExc_TypeError, |
| 1338 | "Iterator requested dtype could not be cast from " |
| 1339 | "%R to %R, the operand %d dtype, " |
| 1340 | "according to the rule %s", |
| 1341 | op_dtype[iop], PyArray_DESCR(op[iop]), iop, |
| 1342 | npyiter_casting_to_string(casting)); |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | NPY_IT_DBG_PRINT("Iterator: Setting NPY_OP_ITFLAG_CAST " |
| 1347 | "because the types aren't equivalent\n"); |
| 1348 | /* Indicate that this operand needs casting */ |
| 1349 | op_itflags[iop] |= NPY_OP_ITFLAG_CAST; |
| 1350 | } |
| 1351 | } |
no test coverage detected