TensorElement

Trait TensorElement 

Source
pub trait TensorElement:
    Clone
    + Send
    + Sync
    + 'static
    + Copy {
    const DTYPE: DType;
    const ZERO: Self;
    const ONE: Self;
    const MIN: Self;
    const MAX: Self;
Show 20 methods // Required methods fn from_f32(val: f32) -> Self; fn to_f32(self) -> f32; fn from_f64(val: f64) -> Self; fn to_f64(self) -> f64; fn is_zero(self) -> bool; fn infinity() -> Self; fn from_u8(val: u8) -> Self; fn from_u16(val: u16) -> Self; fn from_u32(val: u32) -> Self; fn from_u64(val: u64) -> Self; fn from_i8(val: i8) -> Self; fn from_i16(val: i16) -> Self; fn from_i32(val: i32) -> Self; fn from_i64(val: i64) -> Self; fn from_bool(val: bool) -> Self; fn from_f16(val: f16) -> Self; fn from_bf16(val: bf16) -> Self; // Provided methods fn zero() -> Self { ... } fn one() -> Self { ... } fn dtype() -> DType { ... }
}
Expand description

Trait for types that can be used as tensor elements

Required Associated Constants§

Source

const DTYPE: DType

The data type of this tensor element

Source

const ZERO: Self

The zero/additive identity value for this type

Source

const ONE: Self

The one/multiplicative identity value for this type

Source

const MIN: Self

The minimum value for this type

Source

const MAX: Self

The maximum value for this type

Required Methods§

Source

fn from_f32(val: f32) -> Self

Convert from f32 (for type casting)

Source

fn to_f32(self) -> f32

Convert to f32 (for type casting)

Source

fn from_f64(val: f64) -> Self

Convert from f64 (for type casting)

Source

fn to_f64(self) -> f64

Convert to f64 (for type casting)

Source

fn is_zero(self) -> bool

Check if value is zero

Source

fn infinity() -> Self

Infinity value (for division by zero)

Source

fn from_u8(val: u8) -> Self

Source

fn from_u16(val: u16) -> Self

Source

fn from_u32(val: u32) -> Self

Source

fn from_u64(val: u64) -> Self

Source

fn from_i8(val: i8) -> Self

Source

fn from_i16(val: i16) -> Self

Source

fn from_i32(val: i32) -> Self

Source

fn from_i64(val: i64) -> Self

Source

fn from_bool(val: bool) -> Self

Source

fn from_f16(val: f16) -> Self

Source

fn from_bf16(val: bf16) -> Self

Provided Methods§

Source

fn zero() -> Self

Zero value for this type (for backward compatibility)

Source

fn one() -> Self

One value for this type (for backward compatibility)

Source

fn dtype() -> DType

Get the dtype for this type

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TensorElement for bool

Source§

const DTYPE: DType = DType::Bool

Source§

const ZERO: Self = false

Source§

const ONE: Self = true

Source§

const MIN: Self = false

Source§

const MAX: Self = true

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for f32

Source§

const DTYPE: DType = DType::Fp32

Source§

const ZERO: Self = 0f32

Source§

const ONE: Self = 1f32

Source§

const MIN: Self = -3.40282347E+38f32

Source§

const MAX: Self = 3.40282347E+38f32

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for f64

Source§

const DTYPE: DType = DType::Fp64

Source§

const ZERO: Self = 0f64

Source§

const ONE: Self = 1f64

Source§

const MIN: Self = -1.7976931348623157E+308f64

Source§

const MAX: Self = 1.7976931348623157E+308f64

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for i8

Source§

const DTYPE: DType = DType::Int8

Source§

const ZERO: Self = 0i8

Source§

const ONE: Self = 1i8

Source§

const MIN: Self = -128i8

Source§

const MAX: Self = 127i8

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for i16

Source§

const DTYPE: DType = DType::Int16

Source§

const ZERO: Self = 0i16

Source§

const ONE: Self = 1i16

Source§

const MIN: Self = -32_768i16

Source§

const MAX: Self = 32_767i16

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for i32

Source§

const DTYPE: DType = DType::Int32

Source§

const ZERO: Self = 0i32

Source§

const ONE: Self = 1i32

Source§

const MIN: Self = -2_147_483_648i32

Source§

const MAX: Self = 2_147_483_647i32

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for i64

Source§

const DTYPE: DType = DType::Int64

Source§

const ZERO: Self = 0i64

Source§

const ONE: Self = 1i64

Source§

const MIN: Self = -9_223_372_036_854_775_808i64

Source§

const MAX: Self = 9_223_372_036_854_775_807i64

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for u8

Source§

const DTYPE: DType = DType::Uint8

Source§

const ZERO: Self = 0u8

Source§

const ONE: Self = 1u8

Source§

const MIN: Self = 0u8

Source§

const MAX: Self = 255u8

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for u16

Source§

const DTYPE: DType = DType::Uint16

Source§

const ZERO: Self = 0u16

Source§

const ONE: Self = 1u16

Source§

const MIN: Self = 0u16

Source§

const MAX: Self = 65_535u16

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for u32

Source§

const DTYPE: DType = DType::Uint32

Source§

const ZERO: Self = 0u32

Source§

const ONE: Self = 1u32

Source§

const MIN: Self = 0u32

Source§

const MAX: Self = 4_294_967_295u32

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for u64

Source§

const DTYPE: DType = DType::Uint64

Source§

const ZERO: Self = 0u64

Source§

const ONE: Self = 1u64

Source§

const MIN: Self = 0u64

Source§

const MAX: Self = 18_446_744_073_709_551_615u64

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn is_zero(self) -> bool

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for bf16

Source§

const DTYPE: DType = DType::Bf16

Source§

const ZERO: Self = bf16::ZERO

Source§

const ONE: Self = bf16::ONE

Source§

const MIN: Self = bf16::MIN

Source§

const MAX: Self = bf16::MAX

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn is_zero(self) -> bool

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Source§

impl TensorElement for f16

Source§

const DTYPE: DType = DType::Fp16

Source§

const ZERO: Self = f16::ZERO

Source§

const ONE: Self = f16::ONE

Source§

const MIN: Self = f16::MIN

Source§

const MAX: Self = f16::MAX

Source§

fn from_f32(val: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn is_zero(self) -> bool

Source§

fn from_f64(val: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn infinity() -> Self

Source§

fn from_u8(val: u8) -> Self

Source§

fn from_u16(val: u16) -> Self

Source§

fn from_u32(val: u32) -> Self

Source§

fn from_u64(val: u64) -> Self

Source§

fn from_i8(val: i8) -> Self

Source§

fn from_i16(val: i16) -> Self

Source§

fn from_i32(val: i32) -> Self

Source§

fn from_i64(val: i64) -> Self

Source§

fn from_bool(val: bool) -> Self

Source§

fn from_f16(val: f16) -> Self

Source§

fn from_bf16(val: bf16) -> Self

Implementors§