Skip to main content

PackedBlock

Struct PackedBlock 

Source
pub struct PackedBlock {
    pub bits: u8,
    pub scale: f16,
    pub packed_indices: Vec<u8>,
}
Expand description

A packed quantized block that stores a scale factor and bit-packed indices.

Replaces the former BlockTQ2, BlockTQ3, and BlockTQ4 structs with a single type that tracks its own bit width.

Fields§

§bits: u8

Bit width used for packing (2, 3, or 4).

§scale: f16

Scaling factor (L2-norm of original vector).

§packed_indices: Vec<u8>

Packed indices (layout depends on bits).

Implementations§

Source§

impl PackedBlock

Source

pub fn new(bits: u8, scale: f16, indices: &[u8]) -> Self

Create a new packed block from a scale and a slice of unpacked index values.

The indices are bit-packed internally based on the specified bits width.

Pure Integration: delegates packing to the bit-width-specific helper selected by the pack closure (IOSP lenient-mode closure pattern).

Source

pub fn size_bytes(&self) -> usize

Total size of the block in bytes (2 bytes for f16 scale + packed data).

Source

pub fn from_raw(bits: u8, scale: f16, packed_indices: Vec<u8>) -> Self

Creates a PackedBlock from pre-packed data without re-packing.

Use this to reconstruct blocks from GPU-quantized data that is already in the correct packed layout.

Pure Operation: field assignment only.

Source

pub fn unpack_into(&self, count: usize, buf: &mut Vec<u8>)

Unpacks stored indices into a caller-provided buffer, avoiding allocation.

This is the hot-path variant: reuses the buffer across repeated calls (e.g. inside attention score loops) to eliminate per-key allocations.

Pure Integration: delegates unpacking to the bit-width-specific helper selected by the do_unpack closure (IOSP lenient-mode closure pattern).

Source

pub fn unpack(&self, count: usize) -> Vec<u8>

Recover the unpacked index values.

Allocates a fresh buffer. For hot paths, prefer unpack_into with a reusable buffer.

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> 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, 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.