Skip to main content

Cast

Trait Cast 

Source
pub trait Cast<const D: usize, K: Basic> {
    type OutputKind: Basic;

    // Required method
    fn cast(tensor: Tensor<D, K>, dtype: Self) -> Tensor<D, Self::OutputKind>;
}
Expand description

Trait for types that represent a valid cast target from a tensor of kind K.

The generic parameter K is the input tensor kind (Float, Int, or Bool). Implementors declare the output kind and provide the actual cast logic.

Required Associated Types§

Source

type OutputKind: Basic

The output tensor kind after casting.

Required Methods§

Source

fn cast(tensor: Tensor<D, K>, dtype: Self) -> Tensor<D, Self::OutputKind>

Cast a tensor primitive to the target dtype.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const D: usize> Cast<D, Bool> for FloatDType

Source§

impl<const D: usize> Cast<D, Bool> for IntDType

Source§

impl<const D: usize> Cast<D, Float> for DType

Backward-compatible impl: only float DType variants are accepted.

§Panics

Panics if dtype is not a float variant (e.g., DType::I32). Use IntDType directly for cross-kind casting to int.

Source§

impl<const D: usize> Cast<D, Float> for FloatDType

Source§

impl<const D: usize> Cast<D, Float> for IntDType

Source§

impl<const D: usize> Cast<D, Int> for DType

Backward-compatible impl: only int DType variants are accepted.

§Panics

Panics if dtype is not an int variant (e.g., DType::F32). Use FloatDType directly for cross-kind casting to float.

Source§

impl<const D: usize> Cast<D, Int> for FloatDType

Source§

impl<const D: usize> Cast<D, Int> for IntDType