pub struct SphericalQuantizer<A = GlobalAllocator>where
A: Allocator,{ /* private fields */ }Implementations§
Source§impl<A> SphericalQuantizer<A>where
A: Allocator,
impl<A> SphericalQuantizer<A>where
A: Allocator,
Sourcepub fn input_dim(&self) -> usize
pub fn input_dim(&self) -> usize
Return the number dimensions this quantizer has been trained for.
Sourcepub fn output_dim(&self) -> usize
pub fn output_dim(&self) -> usize
Return the dimension of the post-transformed vector.
Output storage vectors should use this dimension instead of self.dim() because
in general, the output dim may be different from the input dimension.
Sourcepub fn shift(&self) -> &[f32]
pub fn shift(&self) -> &[f32]
Return the per-dimension shift vector.
This vector is meant to accomplish two goals:
- Centers the data around the training dataset mean.
- Offsets each dimension into a range that can be encoded in unsigned values.
Sourcepub fn mean_norm(&self) -> Positive<f32>
pub fn mean_norm(&self) -> Positive<f32>
Return the approximate mean norm of the training data.
Sourcepub fn pre_scale(&self) -> Positive<f32>
pub fn pre_scale(&self) -> Positive<f32>
Return the pre-scaling parameter for data. This value is multiplied to every compressed vector to adjust its dynamic range.
A value of 1.0 means that no scaling is occurring.
Sourcepub fn generate(
centroid: Poly<[f32], A>,
mean_norm: f32,
transform: TransformKind,
metric: SupportedMetric,
pre_scale: Option<f32>,
rng: &mut dyn RngCore,
allocator: A,
) -> Result<Self, TrainError>
pub fn generate( centroid: Poly<[f32], A>, mean_norm: f32, transform: TransformKind, metric: SupportedMetric, pre_scale: Option<f32>, rng: &mut dyn RngCore, allocator: A, ) -> Result<Self, TrainError>
A lower-level constructor that accepts a centroid, mean norm, and pre-scale directly.
Sourcepub fn metric(&self) -> SupportedMetric
pub fn metric(&self) -> SupportedMetric
Return the metric used by this quantizer.
Sourcepub fn train<T, R>(
data: MatrixView<'_, T>,
transform: TransformKind,
metric: SupportedMetric,
pre_scale: PreScale,
rng: &mut R,
allocator: A,
) -> Result<Self, TrainError>
pub fn train<T, R>( data: MatrixView<'_, T>, transform: TransformKind, metric: SupportedMetric, pre_scale: PreScale, rng: &mut R, allocator: A, ) -> Result<Self, TrainError>
Construct a quantizer for vectors in the distribution of data.
The type of distance-preserving transform to use is selected by the TransformKind.
Vectors compressed with this quantizer will be metric specific and optimized for distance computations rather than reconstruction. This means that vectors compressed targeting the inner-product distance will not return meaningful results if used for L2 distance computations.
Additionally, vectors compressed when using the SupportedMetric::Cosine distance
will be implicitly normalized before being compressed to enable better compression.
If argument pre_scale is given, then all vectors compressed by this quantizer will
first be scaled by this value. Note that if given, pre_scale must be positive.
Trait Implementations§
Source§impl<A> AsFunctor<CompensatedCosine> for SphericalQuantizer<A>where
A: Allocator,
impl<A> AsFunctor<CompensatedCosine> for SphericalQuantizer<A>where
A: Allocator,
fn as_functor(&self) -> CompensatedCosine
Source§impl<A> AsFunctor<CompensatedIP> for SphericalQuantizer<A>where
A: Allocator,
impl<A> AsFunctor<CompensatedIP> for SphericalQuantizer<A>where
A: Allocator,
fn as_functor(&self) -> CompensatedIP
Source§impl<A> AsFunctor<CompensatedSquaredL2> for SphericalQuantizer<A>where
A: Allocator,
impl<A> AsFunctor<CompensatedSquaredL2> for SphericalQuantizer<A>where
A: Allocator,
fn as_functor(&self) -> CompensatedSquaredL2
Source§impl<A> CompressIntoWith<&[f32], Slice<&mut [f32], Mut<'_, FullQueryMeta>>, ScopedAllocator<'_>> for SphericalQuantizer<A>where
A: Allocator,
impl<A> CompressIntoWith<&[f32], Slice<&mut [f32], Mut<'_, FullQueryMeta>>, ScopedAllocator<'_>> for SphericalQuantizer<A>where
A: Allocator,
Source§fn compress_into_with(
&self,
from: &[f32],
into: FullQueryMut<'_>,
allocator: ScopedAllocator<'_>,
) -> Result<(), Self::Error>
fn compress_into_with( &self, from: &[f32], into: FullQueryMut<'_>, allocator: ScopedAllocator<'_>, ) -> Result<(), Self::Error>
Compress the input vector from into the bitslice into.
§Error
Returns an error if
- The input contains
NaN. from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.into.len() != self.output_dim(): Compressed vector must have the same dimensionality as the output of the distance-preserving transform. Importantely, this may be different thanself.dim()and should be retrieved fromself.output_dim().
Source§type Error = CompressionError
type Error = CompressionError
Source§impl<const NBITS: usize, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, DataMeta>>, ScopedAllocator<'_>> for SphericalQuantizer<A>
impl<const NBITS: usize, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, DataMeta>>, ScopedAllocator<'_>> for SphericalQuantizer<A>
Source§fn compress_into_with(
&self,
from: &[f32],
into: DataMut<'_, NBITS>,
allocator: ScopedAllocator<'_>,
) -> Result<(), Self::Error>
fn compress_into_with( &self, from: &[f32], into: DataMut<'_, NBITS>, allocator: ScopedAllocator<'_>, ) -> Result<(), Self::Error>
Compress the input vector from into the bitslice into.
§Error
Returns an error if
- The input contains
NaN. from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.into.len() != self.output_dim(): Compressed vector must have the same dimensionality as the output of the distance-preserving transform. Importantely, this may be different thanself.dim()and should be retrieved fromself.output_dim().
Source§type Error = CompressionError
type Error = CompressionError
Source§impl<const NBITS: usize, Perm, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, QueryMeta>, Perm>, ScopedAllocator<'_>> for SphericalQuantizer<A>
impl<const NBITS: usize, Perm, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, QueryMeta>, Perm>, ScopedAllocator<'_>> for SphericalQuantizer<A>
Source§fn compress_into_with(
&self,
from: &[f32],
into: QueryMut<'_, NBITS, Perm>,
allocator: ScopedAllocator<'_>,
) -> Result<(), Self::Error>
fn compress_into_with( &self, from: &[f32], into: QueryMut<'_, NBITS, Perm>, allocator: ScopedAllocator<'_>, ) -> Result<(), Self::Error>
Compress the input vector from into the bitslice into.
§Error
Returns an error if
- The input contains
NaN. from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.into.len() != self.output_dim(): Compressed vector must have the same dimensionality as the output of the distance-preserving transform. Importantely, this may be different thanself.dim()and should be retrieved fromself.output_dim().
Source§type Error = CompressionError
type Error = CompressionError
Auto Trait Implementations§
impl<A> Freeze for SphericalQuantizer<A>where
A: Freeze,
impl<A> RefUnwindSafe for SphericalQuantizer<A>where
A: RefUnwindSafe,
impl<A> Send for SphericalQuantizer<A>where
A: Send,
impl<A> Sync for SphericalQuantizer<A>where
A: Sync,
impl<A> Unpin for SphericalQuantizer<A>where
A: Unpin,
impl<A> UnsafeUnpin for SphericalQuantizer<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for SphericalQuantizer<A>where
A: UnwindSafe,
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> 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