pub struct VectorQuantizer { /* private fields */ }Expand description
Vector quantizer for compressing and decompressing vectors.
Implementations§
Source§impl VectorQuantizer
impl VectorQuantizer
Sourcepub fn new(method: QuantizationMethod, dimension: usize) -> Self
pub fn new(method: QuantizationMethod, dimension: usize) -> Self
Create a new vector quantizer.
The quantizer is created in an untrained state. Before calling
quantize(), you must call train()
with a representative set of vectors (unless the method is
QuantizationMethod::None, which requires no training).
§Arguments
method- The quantization method to use.dimension- The expected vector dimension. All vectors passed toquantize()must have this dimension.
Sourcepub fn train(&mut self, vectors: &[Vector]) -> Result<()>
pub fn train(&mut self, vectors: &[Vector]) -> Result<()>
Train the quantizer on a set of vectors.
For Scalar8Bit, this computes
per-dimension min/max values from the training set so that vectors can
be linearly mapped to the [0, 255] range.
For None, no training is performed and
this method returns immediately.
For ProductQuantization,
this method currently returns an error because product quantization is
not yet implemented.
§Arguments
vectors- A representative set of vectors to learn quantization parameters from. Must not be empty forScalar8Bit.
§Errors
Returns an error if the training set is empty (for Scalar8Bit) or if
the quantization method is not yet implemented (ProductQuantization).
Sourcepub fn quantize(&self, vector: &Vector) -> Result<QuantizedVector>
pub fn quantize(&self, vector: &Vector) -> Result<QuantizedVector>
Quantize a vector to compressed representation.
Sourcepub fn dequantize(&self, quantized: &QuantizedVector) -> Result<Vector>
pub fn dequantize(&self, quantized: &QuantizedVector) -> Result<Vector>
Dequantize a compressed vector back to full precision.
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Get the compression ratio achieved by this quantization method.
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Check if the quantizer is trained.
Auto Trait Implementations§
impl Freeze for VectorQuantizer
impl RefUnwindSafe for VectorQuantizer
impl Send for VectorQuantizer
impl Sync for VectorQuantizer
impl Unpin for VectorQuantizer
impl UnsafeUnpin for VectorQuantizer
impl UnwindSafe for VectorQuantizer
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> 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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.