pub struct FibQuantizer { /* private fields */ }Expand description
FibQuant encoder/decoder bound to one profile and codebook.
Implementations§
Source§impl FibQuantizer
impl FibQuantizer
Sourcepub fn new(profile: FibQuantProfileV1) -> Result<Self>
pub fn new(profile: FibQuantProfileV1) -> Result<Self>
Build a quantizer by constructing the profile codebook.
Sourcepub fn from_codebook(codebook: FibCodebookV1) -> Result<Self>
pub fn from_codebook(codebook: FibCodebookV1) -> Result<Self>
Build a quantizer from a validated codebook.
Sourcepub fn profile(&self) -> &FibQuantProfileV1
pub fn profile(&self) -> &FibQuantProfileV1
Access the profile.
Sourcepub fn codebook(&self) -> &FibCodebookV1
pub fn codebook(&self) -> &FibCodebookV1
Access the codebook.
Sourcepub fn encode(&self, x: &[f32]) -> Result<FibCodeV1>
pub fn encode(&self, x: &[f32]) -> Result<FibCodeV1>
Encode a vector into a fixed-rate artifact.
Sourcepub fn encode_with_receipt(
&self,
x: &[f32],
) -> Result<(FibCodeV1, FibQuantCompressionReceiptV1)>
pub fn encode_with_receipt( &self, x: &[f32], ) -> Result<(FibCodeV1, FibQuantCompressionReceiptV1)>
Encode and emit a receipt.
Sourcepub fn reconstruction_mse(&self, x: &[f32]) -> Result<f64>
pub fn reconstruction_mse(&self, x: &[f32]) -> Result<f64>
Reconstruction MSE for one vector.
Sourcepub fn cosine_similarity(&self, x: &[f32]) -> Result<f64>
pub fn cosine_similarity(&self, x: &[f32]) -> Result<f64>
Reconstruction cosine similarity for one vector.
Sourcepub fn encode_batch(&self, vectors: &[&[f32]]) -> Result<Vec<FibCodeV1>>
pub fn encode_batch(&self, vectors: &[&[f32]]) -> Result<Vec<FibCodeV1>>
Encode a batch of vectors. Uses gpu-backend for the Hadamard + Lloyd-Max portions when available, keeping the FibCodeV1 format identical to single encode.
Sourcepub fn decode_batch(&self, codes: &[FibCodeV1]) -> Result<Vec<Vec<f32>>>
pub fn decode_batch(&self, codes: &[FibCodeV1]) -> Result<Vec<Vec<f32>>>
Decode a batch of codes.
Sourcepub fn decode_batch_fast(&self, codes: &[FibCodeV1]) -> Result<Vec<Vec<f32>>>
pub fn decode_batch_fast(&self, codes: &[FibCodeV1]) -> Result<Vec<Vec<f32>>>
Fast batch decode. Optimized for the case where many small codes share the same profile (so the codebook + rotation are reused).
Key wins over decode_batch:
- No per-index
Vec<f64>allocation in the codeword gather — each codeword is copied in place into a singleVec<f32>. - The rotation matrix is converted to f32 once for the whole
batch, then
apply_inverse_f32is called per code (no f32→f64 roundtrip on the rotation or the input). - The unpacked indices are reused via
as_f32_slice()where possible.
Output is byte-identical to calling decode per code, modulo
the final as f32 cast in decode (we also cast to f32 at the
end; intermediate precision is below the codebook quantization
noise floor and matches the original as f32 step exactly).
Sourcepub fn is_gpu_accelerated(&self) -> bool
pub fn is_gpu_accelerated(&self) -> bool
Check if GPU acceleration is available.
This is a device-availability probe: it returns true if a CUDA device was found at init time. Whether an individual encode_batch call actually dispatches to GPU depends on the call’s batch size and vector dimension crossing the runtime thresholds.
Use Self::is_gpu_accelerated_for for an honest per-call check.
Sourcepub fn is_gpu_accelerated_for(&self, n: usize, d: usize) -> bool
pub fn is_gpu_accelerated_for(&self, n: usize, d: usize) -> bool
Check if a batch of n vectors of dimension d would actually
dispatch to GPU. Returns true only when:
- the
gpufeature is compiled in, - a CUDA device is available at runtime,
n >= GPU_MIN_BATCH_SIZEandd >= GPU_MIN_DIM, AND- the codebook size
Nis <= 32 (the codebook_lookup kernel is one warp wide and falls back to CPU otherwise).
This is the honest gate for receipts: a 4-doc corpus with dim 64
returns false even with --features gpu, because the batch is too
small to overcome GPU launch overhead. A corpus with a codebook
larger than 32 also returns false.
Sourcepub fn gpu_steps_for(&self, n: usize, d: usize) -> GpuStepReport
pub fn gpu_steps_for(&self, n: usize, d: usize) -> GpuStepReport
Per-step GPU dispatch report. hadamard is true if a batch of size
n at dim d would dispatch the Hadamard rotation to GPU.
codebook_lookup is true only if both the Hadamard AND the
codebook-lookup step would dispatch (additionally requires codebook
size <= 32). The latter is independent of the gpu_codebook_lookup
feature gate — the feature controls whether the dispatch is enabled
in encode_batch, not whether the kernel would be a win.
Trait Implementations§
Source§impl Clone for FibQuantizer
impl Clone for FibQuantizer
Source§fn clone(&self) -> FibQuantizer
fn clone(&self) -> FibQuantizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FibQuantizer
impl RefUnwindSafe for FibQuantizer
impl Send for FibQuantizer
impl Sync for FibQuantizer
impl Unpin for FibQuantizer
impl UnsafeUnpin for FibQuantizer
impl UnwindSafe for FibQuantizer
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,
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
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.