pub struct ScalarQuantizer { /* private fields */ }Expand description
Scalar quantizer (SQ8): one u8 per dimension, 4× compression.
Build one with ScalarQuantizer::new (or Default), train it once
with a representative sample, then quantize and compare. The trained
quantizer is callable from multiple threads — it owns its calibration
by value and exposes no interior mutability.
§Examples
use iqdb_quantize::{Quantizer, ScalarQuantizer};
use iqdb_types::DistanceMetric;
let mut sq = ScalarQuantizer::new();
sq.train(&[&[0.0_f32, 1.0, 2.0][..], &[1.0_f32, 0.0, 1.0][..]])
.expect("two non-empty, finite vectors of equal dim");
let code = sq.quantize(&[0.5_f32, 0.5, 1.5]).expect("dim matches");
let d = sq
.distance(&[0.5_f32, 0.5, 1.5], &code, DistanceMetric::Euclidean)
.expect("dim matches");
assert!(d.is_finite());Implementations§
Source§impl ScalarQuantizer
impl ScalarQuantizer
Sourcepub fn new() -> Self
pub fn new() -> Self
Build an untrained scalar quantizer.
Every hot method returns IqdbError::InvalidConfig until
Quantizer::train succeeds.
§Examples
use iqdb_quantize::ScalarQuantizer;
let _sq = ScalarQuantizer::new();Trait Implementations§
Source§impl Clone for ScalarQuantizer
impl Clone for ScalarQuantizer
Source§fn clone(&self) -> ScalarQuantizer
fn clone(&self) -> ScalarQuantizer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ScalarQuantizer
impl Debug for ScalarQuantizer
Source§impl Default for ScalarQuantizer
impl Default for ScalarQuantizer
Source§fn default() -> ScalarQuantizer
fn default() -> ScalarQuantizer
Returns the “default value” for a type. Read more
Source§impl PartialEq for ScalarQuantizer
impl PartialEq for ScalarQuantizer
Source§fn eq(&self, other: &ScalarQuantizer) -> bool
fn eq(&self, other: &ScalarQuantizer) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Quantizer for ScalarQuantizer
impl Quantizer for ScalarQuantizer
Source§type Quantized = Sq8Code
type Quantized = Sq8Code
The compact code produced by
Quantizer::quantize.Source§fn train(&mut self, vectors: &[&[f32]]) -> Result<()>
fn train(&mut self, vectors: &[&[f32]]) -> Result<()>
Train the quantizer from a sample of representative vectors. Read more
Source§fn quantize(&self, vector: &[f32]) -> Result<Self::Quantized>
fn quantize(&self, vector: &[f32]) -> Result<Self::Quantized>
Encode
vector as a compact code. Read moreimpl StructuralPartialEq for ScalarQuantizer
Auto Trait Implementations§
impl Freeze for ScalarQuantizer
impl RefUnwindSafe for ScalarQuantizer
impl Send for ScalarQuantizer
impl Sync for ScalarQuantizer
impl Unpin for ScalarQuantizer
impl UnsafeUnpin for ScalarQuantizer
impl UnwindSafe for ScalarQuantizer
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
Mutably borrows from an owned value. Read more