fn

promote_types

DType
promote_types(a_dtype: dtype, b_dtype: dtype)
source

Compute the joint promotion of two dtypes.

Operates on dtype objects directly (no tensor required). Combines the two dtypes according to the standard kind/width ordering: higher kind (bool << int << float << complex) wins outright, and ties in kind are broken by the wider bit-width.

Parameters

a_dtypeDType
First dtype.
b_dtypeDType
Second dtype.

Returns

DType

The dtype that values of either input dtype would be promoted to in a binary operation.

Notes

With kind(d) and width(d) denoting the kind and bit-width of a dtype:

promote(da,db)={da,kind(da)>kind(db),db,kind(da)<kind(db),da,kind equal and width(da)width(db),db,otherwise.\text{promote}(d_a, d_b) = \begin{cases} d_a, & \text{kind}(d_a) > \text{kind}(d_b), \\ d_b, & \text{kind}(d_a) < \text{kind}(d_b), \\ d_a, & \text{kind equal and width}(d_a) \geq \text{width}(d_b), \\ d_b, & \text{otherwise}. \end{cases}

The relation is symmetric (up to ties) and commutative on the output dtype.

Examples

>>> import lucid
>>> lucid.promote_types(lucid.int32, lucid.float32)
lucid.float32
>>> lucid.promote_types(lucid.int8, lucid.int64)
lucid.int64