Skip to main content

SDCTable

Struct SDCTable 

Source
pub struct SDCTable<const M: usize, const NBITS: usize>
where [(); { _ }]:,
{ /* private fields */ }
Expand description

Precomputed centroid-to-centroid distances for Symmetric Distance Computation (SDC).

SDC enables fast distance computation between two PQ codes without needing the original vectors. During quantizer training, we precompute squared L2 distances between all pairs of centroids in each subspace.

Table layout: table[m * ksub * ksub + i * ksub + j] is the squared distance between centroid i and centroid j in subspace m.

The const generics must match the ProductQuantizer configuration:

  • M: number of subquantizers
  • NBITS: bits per centroid index

Implementations§

Source§

impl<const M: usize, const NBITS: usize> SDCTable<M, NBITS>
where [(); { _ }]:,

Source

pub const KSUB: usize

Number of centroids per subspace (2^NBITS)

Source

pub fn from_centroids(centroids: &[f32], dsub: usize) -> Self

Create an SDCTable from centroids using squared L2 distance.

§Arguments
  • centroids - Flat centroid storage: M * ksub * dsub floats
  • dsub - Dimension of each subspace
Source

pub fn from_centroids_with_distance( centroids: &[f32], dsub: usize, subspace_distance: impl Fn(&[f32], &[f32]) -> f32, ) -> Self

Create an SDCTable from centroids using a custom subspace distance function.

The distance function receives two subvector slices of length dsub and returns a non-negative distance value.

§Arguments
  • centroids - Flat centroid storage: M * ksub * dsub floats
  • dsub - Dimension of each subspace
  • subspace_distance - Distance function for subvector pairs
Source

pub fn distance( &self, code1: &PQCode<M, NBITS>, code2: &PQCode<M, NBITS>, ) -> f32

Compute approximate squared L2 distance between two PQ codes.

This is the core of SDC: sum precomputed centroid-to-centroid distances for each subspace.

Source

pub fn ksub(&self) -> usize

Number of centroids per subspace.

Source

pub fn table_data(&self) -> &[f32]

Access the raw table data for serialization.

Source

pub fn from_raw(table: Vec<f32>, ksub: usize) -> Self

Reconstruct an SDCTable from raw data.

Trait Implementations§

Source§

impl<const M: usize, const NBITS: usize> Clone for SDCTable<M, NBITS>
where [(); { _ }]:,

Source§

fn clone(&self) -> SDCTable<M, NBITS>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const M: usize, const NBITS: usize> Debug for SDCTable<M, NBITS>
where [(); { _ }]:,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const M: usize, const NBITS: usize> PartialEq for SDCTable<M, NBITS>
where [(); { _ }]:,

Source§

fn eq(&self, other: &SDCTable<M, NBITS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const M: usize, const NBITS: usize> StructuralPartialEq for SDCTable<M, NBITS>
where [(); { _ }]:,

Auto Trait Implementations§

§

impl<const M: usize, const NBITS: usize> Freeze for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> RefUnwindSafe for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> Send for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> Sync for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> Unpin for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> UnsafeUnpin for SDCTable<M, NBITS>

§

impl<const M: usize, const NBITS: usize> UnwindSafe for SDCTable<M, NBITS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V