Skip to main content

Cast

Trait Cast 

Source
pub trait Cast<B: Backend, K: TensorKind<B>> {
    type OutputKind: TensorKind<B>;

    // Required method
    fn cast(
        primitive: K::Primitive,
        dtype: Self,
    ) -> <Self::OutputKind as TensorKind<B>>::Primitive;
}
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: TensorKind<B>

The output tensor kind after casting.

Required Methods§

Source

fn cast( primitive: K::Primitive, dtype: Self, ) -> <Self::OutputKind as TensorKind<B>>::Primitive

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<B: Backend> Cast<B, Bool> for FloatDType

Source§

impl<B: Backend> Cast<B, Bool> for IntDType

Source§

impl<B: Backend> Cast<B, 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<B: Backend> Cast<B, Float> for FloatDType

Source§

impl<B: Backend> Cast<B, Float> for IntDType

Source§

impl<B: Backend> Cast<B, 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<B: Backend> Cast<B, Int> for FloatDType

Source§

impl<B: Backend> Cast<B, Int> for IntDType