Skip to main content

FloatLayout

Struct FloatLayout 

Source
pub struct FloatLayout {
    pub exponent_bits: u8,
    pub mantissa_bits: u8,
    pub specials: Specials,
    pub bias_override: Option<i16>,
    pub sign: SignEncoding,
}
Expand description

A sign encoding, exponent_bits, mantissa_bits; at most 32 bits wide. An integer is the layout with exponent_bits 0 and a bias_override of 1 - mantissa_bits, which makes its scale exactly 1.

Fields§

§exponent_bits: u8

Width of the exponent field; 3 for E3M2, 8 for binary32.

§mantissa_bits: u8

Width of the stored mantissa field, excluding the implicit leading one; 2 for E3M2, 23 for binary32.

§specials: Specials

Policy for the all-ones exponent and for overflow; Specials::None for E3M2.

§bias_override: Option<i16>

Replaces the IEEE bias 2^(exponent_bits - 1) - 1 when set; Some(4) on E3M2 shifts its max normal from 28.0 to 14.0.

§sign: SignEncoding

How the sign is encoded; Magnitude for IEEE floats, TwosComplement for int8.

Implementations§

Source§

impl FloatLayout

Source

pub const E5M2: Self

Source

pub const E5M2_SATURATING: Self

E5M2 widths with saturation: the GGUF bf8 storage policy, which keeps infinities out of stored weights.

Source

pub const F16: Self

IEEE 754 binary16: bias 15, inf and nan reserved, max normal 65504.0.

Source

pub const E2M1: Self

Source

pub const E2M2: Self

Proxima cold-storage E2M2: bias 1, no inf or nan, max normal 7.0.

Source

pub const E3M2: Self

OCP MX v1.0 FP6 E3M2: bias 3, no inf or nan, max normal 28.0 (page 12, section 5.3.2, Table 4).

Source

pub const E2M3: Self

Source

pub const BF32: Self

Source

pub const BF16: Self

Source

pub const BF8: Self = Self::E5M2

Source

pub const BF4: Self = Self::E2M1

Source

pub const INT8: Self

Source

pub const UINT8: Self

Source

pub const INT16: Self

Source

pub const UINT16: Self

Source

pub const INT32: Self

Source

pub const UINT32: Self

Source

pub const UINT1: Self

Source

pub const UINT2: Self

Source

pub const UINT3: Self

Source

pub const UINT4: Self

Source

pub const UINT5: Self

Source

pub const UINT6: Self

Source

pub const SIGN_MAGNITUDE_INT8: Self

Sign-magnitude eight bits: range -127..=127 with a negative zero.

Source

pub const fn bias(&self) -> i16

Source

pub const fn width(&self) -> u8

Source

pub fn same_format(&self, other: &Self) -> bool

Whether two layouts are the same format: equal exponent and mantissa widths, equal specials, and equal effective bias. == also compares the raw bias_override, so a layout spelled with Some(15) and one with None differ under == and agree here.

Source

pub const fn packed_bytes( &self, elements: u64, scale_block: Option<(FloatLayout, u64)>, ) -> u64

Bytes elements values occupy packed densely at width() bits each, plus one scale code per block elements when scale_block is Some((scale, block)), rounded up to whole bytes: 32 elements of E3M2 under an f16 scale are 32 * 6 + 16 = 208 bits, 26 bytes.

Source

pub const fn max_normal(&self) -> f32

Source

pub const fn min_normal(&self) -> f32

Source

pub const fn min_subnormal(&self) -> f32

Trait Implementations§

Source§

impl Clone for FloatLayout

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for FloatLayout

Source§

impl Debug for FloatLayout

Source§

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

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

impl<'de> Deserialize<'de> for FloatLayout

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for FloatLayout

Source§

impl Hash for FloatLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FloatLayout

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for FloatLayout

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for FloatLayout

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more