Skip to main content

TurboQuantized

Struct TurboQuantized 

Source
pub struct TurboQuantized { /* private fields */ }
Available on crate feature alloc only.
Expand description

Quantized weight vector (owned).

Created by quantize, quantize_weights, quantize_f32, or quantize_i16. Supports inference via predict and serialization via to_bytes.

Weights are stored in Hadamard-rotated space (H * D * w). During prediction, the same rotation is applied to features so the dot product is preserved.

Implementations§

Source§

impl TurboQuantized

Source

pub fn predict(&self, features: &[f64]) -> f64

Dot product of quantized weights with a feature vector.

Applies the same Hadamard rotation to features, then computes the dot product with the quantized rotated weights over the full padded length. Since HD is orthogonal, w . x == (HD*w) . (HD*x).

Source

pub fn predict_with_scratch(&self, features: &[f64], scratch: &mut [f64]) -> f64

Predict using a caller-provided scratch buffer for the Hadamard rotation.

scratch must have length >= padded_len. This avoids allocation, making it suitable for embedded inference loops.

Source

pub fn dequantize(&self) -> Vec<f64>

Dequantize all weights back to f64 (approximate original space).

Unpacks all padded_len rotated values, then applies the inverse Hadamard rotation to recover approximate original weights.

Source

pub fn n_weights(&self) -> usize

Number of quantized weights.

Source

pub fn padded_len(&self) -> usize

Power-of-2 padded length used for FWHT (needed for scratch allocation).

Source

pub fn mode(&self) -> QuantMode

Quantization mode used.

Source

pub fn compression_ratio(&self) -> f64

Compression ratio vs f64 (original bytes / packed bytes).

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize to bytes for embedded deployment.

Format (36-byte header):

[n_weights: u32 LE]
[mode: u32 LE]        // 0=Bits8, 1=Bits3_5, 2=Bits2_5
[seed: u64 LE]
[padded_len: u32 LE]
[scale: f64 LE]
[offset: f64 LE]
[packed_words: u32 LE...]

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.