* Internal function to fill an array with zeros. * Used in einsum and dot, which ensures the dtype is, in some sense, numerical * and not a str or struct * * dst: The destination array. * wheremask: If non-NULL, a boolean mask specifying where to set the values. * * Returns 0 on success, -1 on failure. */
| 442 | * Returns 0 on success, -1 on failure. |
| 443 | */ |
| 444 | NPY_NO_EXPORT int |
| 445 | PyArray_AssignZero(PyArrayObject *dst, |
| 446 | PyArrayObject *wheremask) |
| 447 | { |
| 448 | int retcode = 0; |
| 449 | if (PyArray_ISOBJECT(dst)) { |
| 450 | PyObject * pZero = PyLong_FromLong(0); |
| 451 | retcode = PyArray_AssignRawScalar(dst, PyArray_DESCR(dst), |
| 452 | (char *)&pZero, wheremask, NPY_SAFE_CASTING); |
| 453 | Py_DECREF(pZero); |
| 454 | } |
| 455 | else { |
| 456 | /* Create a raw bool scalar with the value False */ |
| 457 | PyArray_Descr *bool_dtype = PyArray_DescrFromType(NPY_BOOL); |
| 458 | if (bool_dtype == NULL) { |
| 459 | return -1; |
| 460 | } |
| 461 | npy_bool value = 0; |
| 462 | |
| 463 | retcode = PyArray_AssignRawScalar(dst, bool_dtype, (char *)&value, |
| 464 | wheremask, NPY_SAFE_CASTING); |
| 465 | |
| 466 | Py_DECREF(bool_dtype); |
| 467 | } |
| 468 | return retcode; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /*NUMPY_API |
no test coverage detected