Skip to main content

e3m2

Struct e3m2 

Source
#[repr(transparent)]
pub struct e3m2(pub u8);
Expand description

6-bit E3M2 micro-float (padded to 8-bit storage).

Layout: sign(1) + exponent(3) + mantissa(2), bias=3. Range: ±28, supports infinities. Only 64 total codes; 26 (40.6%) fall in [−1, +1]. Exact integer dot products via exponent-sum binning (15 bins).

§Examples

use numkong::e3m2;

let fp6 = e3m2::from_f32(2.5);
let float = fp6.to_f32();

Tuple Fields§

§0: u8

Implementations§

Source§

impl e3m2

Source

pub const ZERO: Self

Positive zero.

Source

pub const ONE: Self

Positive one.

Source

pub const NEG_ONE: Self

Negative one.

Source

pub fn from_f32(value: f32) -> Self

Source

pub fn to_f32(self) -> f32

Source

pub fn is_nan(self) -> bool

Returns true if this value is NaN.

Source

pub fn is_infinite(self) -> bool

Returns true if this value is positive or negative infinity.

Source

pub fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

Source

pub fn abs(self) -> Self

Returns the absolute value of self.

Trait Implementations§

Source§

impl Add for e3m2

Source§

type Output = e3m2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Angular for e3m2

Source§

type Output = f32

Source§

fn angular(a: &[Self], b: &[Self]) -> Option<Self::Output>

Source§

fn cosine(a: &[Self], b: &[Self]) -> Option<Self::Output>

Alias for angular.
Source§

impl Angulars for e3m2

Source§

type SpatialResult = f32

Result type for angular distances.
Source§

unsafe fn angulars_packed( a: *const Self, packed: *const u8, c: *mut Self::SpatialResult, height: usize, width: usize, depth: usize, a_stride: usize, c_stride: usize, )

Computes angular distances between A rows and packed B columns. Read more
Source§

unsafe fn angulars_symmetric( vectors: *const Self, n_vectors: usize, depth: usize, stride: usize, result: *mut Self::SpatialResult, result_stride: usize, row_start: usize, row_count: usize, )

Computes symmetric angular distance matrix. Read more
Source§

impl Binary for e3m2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Clone for e3m2

Source§

fn clone(&self) -> e3m2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for e3m2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for e3m2

Source§

fn default() -> e3m2

Returns the “default value” for a type. Read more
Source§

impl Display for e3m2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for e3m2

Source§

type Output = e3m2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Dot for e3m2

Source§

type Output = f32

Source§

fn dot(a: &[Self], b: &[Self]) -> Option<Self::Output>

Source§

fn inner(a: &[Self], b: &[Self]) -> Option<Self::Output>

Alias for dot.
Source§

impl Dots for e3m2

Source§

type Accumulator = f32

Accumulator type for the multiplication.
Source§

fn dots_packed_size(width: usize, depth: usize) -> usize

Returns the size in bytes needed for the packed B matrix buffer.
Source§

unsafe fn dots_pack( b: *const Self, width: usize, depth: usize, b_stride: usize, packed: *mut u8, )

Packs the B matrix into an optimized backend-specific layout. Read more
Source§

unsafe fn dots_packed( a: *const Self, packed: *const u8, c: *mut Self::Accumulator, height: usize, width: usize, depth: usize, a_stride: usize, c_stride: usize, )

Computes C = A × Bᵀ using packed B. Read more
Source§

unsafe fn dots_symmetric( vectors: *const Self, n_vectors: usize, depth: usize, stride: usize, result: *mut Self::Accumulator, result_stride: usize, row_start: usize, row_count: usize, )

Computes C = A × Aᵀ where C is symmetric. Read more
Source§

impl EachBlend for e3m2

Source§

type Scalar = f32

Source§

fn each_blend( a: &[Self], b: &[Self], alpha: f32, beta: f32, result: &mut [Self], ) -> Option<()>

Source§

impl EachFMA for e3m2

Source§

type Scalar = f32

Source§

fn each_fma( a: &[Self], b: &[Self], c: &[Self], alpha: f32, beta: f32, result: &mut [Self], ) -> Option<()>

Source§

impl EachScale for e3m2

Source§

type Scalar = f32

Source§

fn each_scale( a: &[Self], alpha: f32, beta: f32, result: &mut [Self], ) -> Option<()>

Source§

impl EachSum for e3m2

Source§

fn each_sum(a: &[Self], b: &[Self], result: &mut [Self]) -> Option<()>

Source§

impl Euclidean for e3m2

Source§

type SqEuclideanOutput = f32

Source§

type EuclideanOutput = f32

Source§

fn sqeuclidean(a: &[Self], b: &[Self]) -> Option<Self::SqEuclideanOutput>

Squared Euclidean distance (L2²). Faster than euclidean for comparisons.
Source§

fn euclidean(a: &[Self], b: &[Self]) -> Option<Self::EuclideanOutput>

Euclidean distance (L2). True metric distance.
Source§

impl Euclideans for e3m2

Source§

type SpatialResult = f32

Result type for euclidean distances.
Source§

unsafe fn euclideans_packed( a: *const Self, packed: *const u8, c: *mut Self::SpatialResult, height: usize, width: usize, depth: usize, a_stride: usize, c_stride: usize, )

Computes euclidean distances between A rows and packed B columns. Read more
Source§

unsafe fn euclideans_symmetric( vectors: *const Self, n_vectors: usize, depth: usize, stride: usize, result: *mut Self::SpatialResult, result_stride: usize, row_start: usize, row_count: usize, )

Computes symmetric euclidean distance matrix. Read more
Source§

impl FloatConvertible for e3m2

Source§

type DimScalar = e3m2

Scalar type for individual sub-dimensions.
Source§

type Unpacked = [e3m2; 1]

Fixed-size array holding all unpacked sub-dimensions.
Source§

fn unpack(self) -> [e3m2; 1]

Unpack all logical sub-dimensions from this packed value.
Source§

fn pack(dims: [e3m2; 1]) -> Self

Pack sub-dimension scalars into a single storage value.
Source§

impl From<e3m2> for f32

Source§

fn from(value: e3m2) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for e3m2

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl LowerHex for e3m2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Mul for e3m2

Source§

type Output = e3m2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for e3m2

Source§

type Output = e3m2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl NumberLike for e3m2

Source§

fn from_f32(v: f32) -> Self

Convert from f32 to this type.
Source§

fn to_f32(self) -> f32

Convert from this type to f32.
Source§

fn abs(self) -> Self

Source§

fn is_nan(self) -> bool

Source§

fn is_finite(self) -> bool

Source§

fn is_infinite(self) -> bool

Source§

fn has_subnormals() -> bool

Source§

fn max_value() -> f32

Source§

fn min_positive() -> f32

Source§

fn from_f64(v: f64) -> Self

Convert from f64 to this type (default: via f32 roundtrip).
Source§

fn to_f64(self) -> f64

Convert from this type to f64 (default: via f32 roundtrip).
Source§

fn has_infinity() -> bool

Source§

fn has_nan() -> bool

Source§

impl PartialEq for e3m2

Source§

fn eq(&self, other: &e3m2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for e3m2

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ReduceMinMax for e3m2

Source§

const NONE_ON_SENTINEL: bool = false

Whether NK_SIZE_MAX indicates that the reduction produced no value.
Source§

type Output = e3m2

Output type for the min/max values — matches the C layer’s native type.
Source§

unsafe fn reduce_minmax_raw( data: *const Self, count: usize, stride_bytes: usize, ) -> Option<(Self::Output, usize, Self::Output, usize)>

Returns Some((min_value, min_index, max_value, max_index)) for raw pointer input with the specified stride, or None if all elements are NaN. Read more
Source§

fn reduce_minmax( data: &[Self], stride_bytes: usize, ) -> Option<(Self::Output, usize, Self::Output, usize)>

Returns Some((min_value, min_index, max_value, max_index)) for the given data with the specified stride, or None if all elements are NaN.
Source§

impl ReduceMoments for e3m2

Source§

type SumOutput = f32

Type for the sum output.
Source§

type SumSqOutput = f32

Type for the sum-of-squares output.
Source§

unsafe fn reduce_moments_raw( data: *const Self, count: usize, stride_bytes: usize, ) -> (Self::SumOutput, Self::SumSqOutput)

Compute (sum, sum_of_squares) for raw pointer input with the given stride in bytes. Read more
Source§

fn reduce_moments( data: &[Self], stride_bytes: usize, ) -> (Self::SumOutput, Self::SumSqOutput)

Compute (sum, sum_of_squares) for data with the given stride (in bytes). Use stride_bytes = size_of::<Self>() for contiguous data.
Source§

impl StorageElement for e3m2

Source§

fn zero() -> Self

The additive identity.
Source§

fn one() -> Self

The multiplicative identity.
Source§

fn dimensions_per_value() -> usize

Number of logical dimensions packed into one storage value. Default: 1 for all normal types. Override for sub-byte packed types.
Source§

impl Sub for e3m2

Source§

type Output = e3m2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl UpperHex for e3m2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl VDot for e3m2

Source§

fn vdot(a: &[Self], b: &[Self]) -> Option<Self::Output>

Source§

impl CastDtype for e3m2

Source§

impl Copy for e3m2

Source§

impl Eq for e3m2

Source§

impl StructuralPartialEq for e3m2

Auto Trait Implementations§

§

impl Freeze for e3m2

§

impl RefUnwindSafe for e3m2

§

impl Send for e3m2

§

impl Sync for e3m2

§

impl Unpin for e3m2

§

impl UnsafeUnpin for e3m2

§

impl UnwindSafe for e3m2

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> FloatLike for T
where T: NumberLike,

Source§

impl<T> Reductions for T

Source§

impl<T> SpatialSimilarity for T
where T: Dot + Angular + Euclidean,