pub struct Sq8Code { /* private fields */ }Expand description
A scalar-quantized (SQ8) code: one u8 per dimension of the trained
vector space.
Produced by Quantizer::quantize on a
trained ScalarQuantizer. The byte at
position i is the linear u8 encoding of the original f32
component under that dimension’s affine calibration; it is not useful
on its own. Decode it with
Quantizer::dequantize or compare it
against a query through
Quantizer::distance.
§Examples
use iqdb_quantize::{Quantizer, ScalarQuantizer};
let mut sq = ScalarQuantizer::new();
sq.train(&[&[0.0_f32, 1.0][..], &[1.0_f32, 0.0][..]]).expect("ok");
let code = sq.quantize(&[0.5_f32, 0.5]).expect("ok");
assert_eq!(code.len(), 2);Implementations§
Source§impl Sq8Code
impl Sq8Code
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the dimension of the encoded vector (one byte per dimension).
§Examples
use iqdb_quantize::{Quantizer, ScalarQuantizer};
let mut sq = ScalarQuantizer::new();
sq.train(&[&[0.0_f32, 1.0, 2.0][..]]).expect("ok");
let code = sq.quantize(&[0.5_f32, 0.5, 0.5]).expect("ok");
assert_eq!(code.len(), 3);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the code holds no bytes.
A Sq8Code produced by Quantizer::quantize
on a trained ScalarQuantizer is never
empty (empty inputs are rejected at the boundary); this method
exists for API symmetry with Sq8Code::len.
§Examples
use iqdb_quantize::{Quantizer, ScalarQuantizer};
let mut sq = ScalarQuantizer::new();
sq.train(&[&[0.0_f32, 1.0][..]]).expect("ok");
let code = sq.quantize(&[0.5_f32, 0.5]).expect("ok");
assert!(!code.is_empty());Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Borrow the raw u8 code bytes.
§Examples
use iqdb_quantize::{Quantizer, ScalarQuantizer};
let mut sq = ScalarQuantizer::new();
sq.train(&[&[0.0_f32, 1.0][..]]).expect("ok");
let code = sq.quantize(&[0.5_f32, 0.5]).expect("ok");
assert_eq!(code.as_bytes().len(), 2);Trait Implementations§
impl Eq for Sq8Code
impl StructuralPartialEq for Sq8Code
Auto Trait Implementations§
impl Freeze for Sq8Code
impl RefUnwindSafe for Sq8Code
impl Send for Sq8Code
impl Sync for Sq8Code
impl Unpin for Sq8Code
impl UnsafeUnpin for Sq8Code
impl UnwindSafe for Sq8Code
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