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

Function PyArray_AssignZero

numpy/core/src/multiarray/convert.c:444–469  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

442 * Returns 0 on success, -1 on failure.
443 */
444NPY_NO_EXPORT int
445PyArray_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

Callers 1

PyArray_MatrixProduct2Function · 0.85

Calls 2

PyArray_AssignRawScalarFunction · 0.85
PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected