Skip to main content

Int4EmbeddingsView

Struct Int4EmbeddingsView 

Source
pub struct Int4EmbeddingsView<'a> {
    pub scales: &'a [u8],
    pub codes: &'a [u8],
    pub n: usize,
    pub dim: usize,
    pub blocks: usize,
}
Expand description

Decoded view over an int4 embeddings payload. Slices borrow the input bytes (no copy); accessors decode scales/codes on demand.

Fields§

§scales: &'a [u8]

f16 LE group scales, n * blocks of them, row-major.

§codes: &'a [u8]

packed nibble codes, n * dim/2 bytes.

§n: usize§dim: usize§blocks: usize

Implementations§

Source§

impl<'a> Int4EmbeddingsView<'a>

Source

pub fn parse(bytes: &'a [u8], n: usize, dim: usize) -> Result<Self>

Source

pub fn group_scale(&self, i: usize, g: usize) -> f32

Read the f16 group scale g of row i as f32.

Source

pub fn row_codes(&self, i: usize) -> &'a [u8] ⓘ

Borrow row i’s packed nibble bytes (dim/2 of them).

Source

pub fn row_scales_f32(&self, i: usize) -> Vec<f32>

Decode row i’s f16 group scales into a fresh Vec<f32> (one per 64-dim block). One-shot use only (the packed ANN store materializes every row once); the per-candidate rerank uses row_scales_into.

Source

pub fn row_scales_into(&self, i: usize, out: &mut [f32])

Decode row i’s f16 group scales into a caller-owned buffer of exactly blocks f32s, so a rerank over thousands of candidates reuses one allocation instead of one Vec per row.

§Panics

When out.len() != self.blocks.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.