pub struct Sq8Codec { /* private fields */ }Expand description
Per-dimension scalar quantization parameters, fit from a set of vectors.
Implementations§
Source§impl Sq8Codec
impl Sq8Codec
Sourcepub fn fit(matrix: &[f32], dim: usize) -> Result<Self>
pub fn fit(matrix: &[f32], dim: usize) -> Result<Self>
Fit one (min, scale) pair per dimension from rows row-major
vectors of length dim packed into matrix (matrix.len() == rows * dim). rows may be 0, in which case every parameter is 0 and every
row encodes to all-zero codes.
§Errors
ItzmaError::CorruptIndex (labelled "(encoding)", matching the
on-disk SQ8 index encoder, which calls this) if dim is 0 or does not
fit a u32, matrix.len() is not a multiple of dim, or matrix
holds a value that is not finite.
Sourcepub fn encode(&self, row: &[f32]) -> Vec<u8> ⓘ
pub fn encode(&self, row: &[f32]) -> Vec<u8> ⓘ
Quantize one row to one code per dimension. The output has
row.len().min(self.dim()) entries — see the module docs’ length
convention.
Sourcepub fn decode(&self, code: &[u8]) -> Vec<f32>
pub fn decode(&self, code: &[u8]) -> Vec<f32>
Reconstruct a row from its codes, off by at most half a step per
dimension. The output has code.len().min(self.dim()) entries.
Sourcepub fn distance(&self, metric: Metric, query: &[f32], code: &[u8]) -> f32
pub fn distance(&self, metric: Metric, query: &[f32], code: &[u8]) -> f32
Approximate distance from a raw query to a stored code, under
metric. Lower is closer, matching
search::distance, whose value this
approximates for the reconstructed vector. Stops at the shortest of
self.dim(), query.len() and code.len().
Prepares the query on every call. A caller comparing one query with
many codes should call Sq8Codec::prepare once instead.
Trait Implementations§
impl StructuralPartialEq for Sq8Codec
Auto Trait Implementations§
impl Forget for Sq8Codec
impl Freeze for Sq8Codec
impl Move for Sq8Codec
impl RefUnwindSafe for Sq8Codec
impl Send for Sq8Codec
impl Sync for Sq8Codec
impl Unpin for Sq8Codec
impl UnsafeUnpin for Sq8Codec
impl UnwindSafe for Sq8Codec
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 more