pub struct ResidualCodebookV1 {
pub schema_version: String,
pub size: u32,
pub block_dim: u32,
pub codewords: Vec<f32>,
pub codebook_digest: String,
}Expand description
A residual codebook — a small set of codewords for encoding the quantization residual from the main codebook.
Fields§
§schema_version: StringStable schema marker.
size: u32Number of residual codewords (typically 4-8).
block_dim: u32Block dimension (must match the main codebook’s block_dim).
codewords: Vec<f32>Row-major size × block_dim f32 codewords.
codebook_digest: StringDigest of the residual codebook.
Implementations§
Source§impl ResidualCodebookV1
impl ResidualCodebookV1
Sourcepub fn build(
profile: &FibQuantProfileV1,
main_codebook: &FibCodebookV1,
) -> Result<Self>
pub fn build( profile: &FibQuantProfileV1, main_codebook: &FibCodebookV1, ) -> Result<Self>
Build a deterministic residual codebook.
The residual codebook is seeded from the main profile’s codebook_seed with a fixed offset. It uses a small set of unit-length directions scaled by a fraction of the expected residual magnitude.
Sourcepub fn train(
profile: &FibQuantProfileV1,
main_codebook: &FibCodebookV1,
training_vectors: &[Vec<f32>],
num_codewords: usize,
) -> Result<Self>
pub fn train( profile: &FibQuantProfileV1, main_codebook: &FibCodebookV1, training_vectors: &[Vec<f32>], num_codewords: usize, ) -> Result<Self>
Train a residual codebook using Lloyd-Max on the residual distribution.
Collects residuals after encoding training vectors with the main codebook, then runs Lloyd-Max refinement to find optimal residual codewords adapted to the actual residual distribution (instead of random directions).
§Arguments
profile- The quantization profile (provides dims, rotation, seed).main_codebook- The main codebook to compute residuals against.training_vectors- Full ambient-dim training vectors (will be normalized + rotated).num_codewords- Number of residual codewords to train.
Sourcepub fn nearest(&self, residual: &[f32]) -> Result<u32>
pub fn nearest(&self, residual: &[f32]) -> Result<u32>
Find the nearest residual codeword for a given residual block.
Sourcepub fn bits_per_index(&self) -> u8
pub fn bits_per_index(&self) -> u8
Bits per residual index.
Trait Implementations§
Source§impl Clone for ResidualCodebookV1
impl Clone for ResidualCodebookV1
Source§fn clone(&self) -> ResidualCodebookV1
fn clone(&self) -> ResidualCodebookV1
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResidualCodebookV1
impl Debug for ResidualCodebookV1
Source§impl<'de> Deserialize<'de> for ResidualCodebookV1
impl<'de> Deserialize<'de> for ResidualCodebookV1
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ResidualCodebookV1
impl PartialEq for ResidualCodebookV1
Source§impl Serialize for ResidualCodebookV1
impl Serialize for ResidualCodebookV1
impl StructuralPartialEq for ResidualCodebookV1
Auto Trait Implementations§
impl Freeze for ResidualCodebookV1
impl RefUnwindSafe for ResidualCodebookV1
impl Send for ResidualCodebookV1
impl Sync for ResidualCodebookV1
impl Unpin for ResidualCodebookV1
impl UnsafeUnpin for ResidualCodebookV1
impl UnwindSafe for ResidualCodebookV1
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.