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

Function handle_promotion

numpy/core/src/multiarray/array_coercion.c:685–713  ·  view source on GitHub ↗

* Do the promotion step and possible casting. This function should * never be called if a descriptor was requested. In that case the output * dtype is not of importance, so we must not risk promotion errors. * * @param out_descr The current descriptor. * @param descr The newly found descriptor to promote with * @param fixed_DType The user provided (fixed) DType or NULL * @param flags dtype

Source from the content-addressed store, hash-verified

683 * @return -1 on error, 0 on success.
684 */
685static inline int
686handle_promotion(PyArray_Descr **out_descr, PyArray_Descr *descr,
687 PyArray_DTypeMeta *fixed_DType, enum _dtype_discovery_flags *flags)
688{
689 assert(!(*flags & DESCRIPTOR_WAS_SET));
690
691 if (*out_descr == NULL) {
692 Py_INCREF(descr);
693 *out_descr = descr;
694 return 0;
695 }
696 PyArray_Descr *new_descr = PyArray_PromoteTypes(descr, *out_descr);
697 if (NPY_UNLIKELY(new_descr == NULL)) {
698 if (fixed_DType != NULL || PyErr_ExceptionMatches(PyExc_FutureWarning)) {
699 /*
700 * If a DType is fixed, promotion must not fail. Do not catch
701 * FutureWarning (raised for string+numeric promotions). We could
702 * only catch TypeError here or even always raise the error.
703 */
704 return -1;
705 }
706 PyErr_Clear();
707 *flags |= PROMOTION_FAILED;
708 /* Continue with object, since we may need the dimensionality */
709 new_descr = PyArray_DescrFromType(NPY_OBJECT);
710 }
711 Py_SETREF(*out_descr, new_descr);
712 return 0;
713}
714
715
716/**

Callers 2

handle_scalarFunction · 0.85

Calls 1

PyArray_PromoteTypesFunction · 0.85

Tested by

no test coverage detected