dpctl.tensor.can_cast(from, to, casting="safe")[source]

Determines if one data type can be cast to another data type according to Type Promotion Rules.

  • from (Union[usm_ndarray, dtype]) – source data type. If from_ is an array, a device-specific type promotion rules apply.

  • to (dtype) – target data type

  • casting (Optional[str]) –

    controls what kind of data casting may occur.

    • ”no” means data types should not be cast at all.

    • ”safe” means only casts that preserve values are allowed.

    • ”same_kind” means only safe casts and casts within a kind, like float64 to float32, are allowed.

    • ”unsafe” means any data conversion can be done.

    Default: “safe”.


Gives True if cast can occur according to the casting rule.

Return type:


Device-specific type promotion rules take into account which data type are and are not supported by a specific device.