Compute the dtype that a binary operation on the inputs would produce.
The dtype a + b (and every other binary op) computes in: the same
rule, from the same place, as the operators themselves.
Parameters
Returns
DTypeThe dtype that an arithmetic operation on tensor and other would
produce.
Notes
Operands fall into three tiers: tensors with at least one dimension,
0-d tensors, and Python numbers. Each tier's dtypes meet on the
promote_types lattice, and a lower tier can lift the result's
category (bool int float complex) but
never its width within a category:
A Python bool counts as bool, an int as int64, a float as
the default dtype and a complex as its complex counterpart. Where
the reference would answer complex32 (float16 beside a complex
operand), Lucid answers complex64.
See also promote_types (operates directly on dtype objects).
Examples
>>> import lucid
>>> a = lucid.tensor([1, 2], dtype=lucid.int32)
>>> b = lucid.tensor([1., 2.], dtype=lucid.float32)
>>> lucid.result_type(a, b)
lucid.float32
>>> lucid.result_type(a, 2.5)
lucid.float32
>>> lucid.result_type(lucid.ones(2, dtype=lucid.float16), lucid.tensor(0.5))
lucid.float16