Skip to main content

WithDType

Trait WithDType 

pub trait WithDType:
    Copy
    + Send
    + Sync
    + 'static
    + NumCast
    + Debug {
    const DTYPE: DType;

    // Required methods
    fn to_f64(self) -> f64;
    fn from_f64(v: f64) -> Self;

    // Provided methods
    fn zero() -> Self { ... }
    fn one() -> Self { ... }
}
Expand description

Re-export core types. Trait implemented by Rust types that can be stored in a tensor.

Provides the mapping between the concrete Rust type and the DType enum, plus conversions to/from f64 for numeric operations.

Required Associated Constants§

const DTYPE: DType

The corresponding DType enum variant.

Required Methods§

fn to_f64(self) -> f64

Convert this value to f64 (for generic numeric code).

fn from_f64(v: f64) -> Self

Create a value of this type from f64.

Provided Methods§

fn zero() -> Self

The zero value.

fn one() -> Self

The one value.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

§

impl WithDType for bf16

§

const DTYPE: DType = DType::BF16

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> bf16

§

impl WithDType for f16

§

const DTYPE: DType = DType::F16

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> f16

§

impl WithDType for f32

§

const DTYPE: DType = DType::F32

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> f32

§

impl WithDType for f64

§

const DTYPE: DType = DType::F64

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> f64

§

impl WithDType for i64

§

const DTYPE: DType = DType::I64

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> i64

§

impl WithDType for u8

§

const DTYPE: DType = DType::U8

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> u8

§

impl WithDType for u32

§

const DTYPE: DType = DType::U32

§

fn to_f64(self) -> f64

§

fn from_f64(v: f64) -> u32

Implementors§