Skip to main content

PQCode

Struct PQCode 

Source
pub struct PQCode<const M: usize, const NBITS: usize>
where [(); { _ }]:,
{ pub codes: [[u8; { _ }]; M], }
Expand description

Encoded representation from Product Quantization.

Stores M centroid indices, each using ceil(NBITS/8) bytes (byte-aligned).

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

Examples:

  • PQCode<8, 8>: 8 subquantizers, 256 centroids each, 8 bytes total
  • PQCode<16, 10>: 16 subquantizers, 1024 centroids each, 32 bytes total

Fields§

§codes: [[u8; { _ }]; M]

Raw byte storage: M * ceil(NBITS/8) bytes, stored as [[u8; B]; M]

Implementations§

Source§

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

Source

pub const KSUB: usize

Number of centroids per subquantizer (2^NBITS)

Source

pub const BYTES_PER_CODE: usize

Bytes per centroid index

Source

pub const TOTAL_BYTES: usize

Total bytes for all M codes

Source

pub fn new(codes: [[u8; { _ }]; M]) -> Self

Create a new PQCode from raw byte array

Source

pub fn get(&self, m: usize) -> u32

Get centroid index at position m as u32

Source

pub fn set(&mut self, m: usize, value: u32)

Set centroid index at position m

Source

pub fn m(&self) -> usize

Number of subquantizers

Source

pub fn zeros() -> Self

Create a zeroed PQCode

Source

pub fn from_indices(indices: &[u32]) -> Self

Create from individual centroid indices

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> PQCode<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 PQCode<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> Display for PQCode<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> Embedding for PQCode<M, NBITS>
where [(); { _ }]:,

Source§

type Scalar = u8

Source§

fn length() -> usize

Source§

fn as_slice(&self) -> &[Self::Scalar]

Source§

fn from_slice(data: &[Self::Scalar]) -> Self

Source§

fn zeros() -> Self

Source§

impl<const M: usize, const NBITS: usize> From<PQCode<M, NBITS>> for TensorProto
where [(); { _ }]:,

Available on crate feature proto only.
Source§

fn from(code: PQCode<M, NBITS>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Source§

fn eq(&self, other: &PQCode<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> TryFrom<TensorProto> for PQCode<M, NBITS>
where [(); { _ }]:,

Available on crate feature proto only.
Source§

type Error = ProtoConversionError

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

fn try_from(proto: TensorProto) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<const M: usize, const NBITS: usize> UnwindSafe for PQCode<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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