Skip to main content

Quantizer

Struct Quantizer 

Source
pub struct Quantizer { /* private fields */ }
Expand description

The quantiser for one collection: its rotation and its width.

Implementations§

Source§

impl Quantizer

Source

pub fn new(dim: usize, bits: Bits, seed: u64) -> Quantizer

The quantiser for dim dimensional vectors at bits, with seed choosing the rotation.

§Panics

If dim is zero.

Source

pub fn dim(&self) -> usize

How many coordinates a vector has.

Source

pub fn bits(&self) -> Bits

How wide a coordinate is written.

Source

pub fn seed(&self) -> u64

The seed the rotation was built from, which is what a catalogue stores.

Source

pub fn code_bytes(&self) -> usize

How many bytes one code takes.

A plane is whole 64 bit words because the scan reads words, so a dimension that is not a multiple of 64 pays for the rest of its last word. At the dimensions embedding families actually use there is nothing to pay.

Source

pub fn rotate(&self, v: &[f32]) -> Vec<f32>

A vector in the frame everything else here works in.

The rotation is linear, so rotate(v - c) is rotate(v) - rotate(c), and an index that keeps its centroids already rotated never has to rotate one again. That is what Quantizer::encode_rotated and Quantizer::query_rotated are for, and the rotation is the expensive half of both of the two calls above them.

§Panics

If v is not Quantizer::dim long.

Source

pub fn encode(&self, v: &[f32], centroid: &[f32], code: &mut [u8]) -> Coded

Write v’s code against the centroid of the partition it is going into.

§Panics

If v or centroid is not Quantizer::dim long, or code is not Quantizer::code_bytes long.

Source

pub fn encode_rotated( &self, x: &[f32], centroid: &[f32], code: &mut [u8], ) -> Coded

The same as Quantizer::encode with both sides already rotated.

§Panics

If x or centroid is not Quantizer::dim long, or code is not Quantizer::code_bytes long.

Source

pub fn query(&self, q: &[f32], centroid: &[f32]) -> Query

Prepare a query against the centroid of a partition being scanned.

This is the per partition half of a search and it happens once, where the estimate against a code happens once per vector in the partition.

§Panics

If q or centroid is not Quantizer::dim long.

Source

pub fn query_rotated(&self, q: &[f32], centroid: &[f32]) -> Query

The same as Quantizer::query with both sides already rotated.

A search rotates its query once and then meets every partition it probes through this, so the rotation is paid for once rather than once per partition.

§Panics

If q or centroid is not Quantizer::dim long.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.