Predicate: can from_ be cast to to under the promotion rules?
Returns True iff to's category is at least from_'s
(bool int float complex). Casts within
a category (both widening and narrowing, e.g. int8 → int32,
int64 → int8, float64 → float32) and casts to a higher
category are permitted; casts to a lower category (e.g.
float32 → int32, complex64 → float32) are rejected.
Parameters
from_dtype-likeSource dtype.
todtype-likeDestination dtype.
Returns
boolTrue if the cast is permitted, False otherwise.
Notes
With kind(d) denoting the category ordering
bool < int < float < complex:
Contrast with result_type, which returns the target dtype for
a mixed-type expression rather than a boolean — use can_cast for
pre-flight checks, result_type for selecting an output dtype.
Examples
>>> import lucid
>>> lucid.can_cast(lucid.int8, lucid.int32)
True
>>> lucid.can_cast(lucid.float64, lucid.float32)
True
>>> lucid.can_cast(lucid.float32, lucid.int32)
False