Skip to main content

cast

Function cast 

Source
pub fn cast<T: Element, U: Element>(x: T) -> U
Expand description

Converts between element types with the semantics of XLA’s convert on CPU:

  • from complex to other types: the real part is converted (as lax.convert_element_type lowers it);
  • to complex: the real part is converted, and the imaginary part is 0;
  • to bool: nonzero (and NaN) is true;
  • float to integer: rounds toward zero and saturates; NaN is 0;
  • integer to integer: wraps around;
  • to f32 and f64: rounded once;
  • to f16 and bf16: rounded through f32, as XLA does.