Skip to main content

Encoder

Struct Encoder 

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

The prepared recipe: sign vectors and scales are FIXED per (seed, width), so they are computed once here, never per vector. Before this hoist the encode path allocated fresh sign vectors and re-ran the PRNG for EVERY vector – measured 3.3x on the 250K ingest ladder; the hoist plus ROUNDS 3 -> 1 (recall unchanged at 1.000 on both the gaussian and the hostile sparse dataset; the identity-rotation mutation fails the sparse case at 0.555) brought bulk 15.9s -> 8.6s.

Implementations§

Source§

impl Encoder

Source

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

Source

pub fn bits(&self) -> usize

Source

pub fn padded(&self) -> usize

Source

pub fn rotate(&self, x: &mut [f32])

Rotate x (already padded) in place.

Source

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

Encode: returns (norm, packed code) for a raw vector (dim <= padded).

Source

pub fn rotate_query(&self, q: &[f32]) -> Vec<f32>

Pad + rotate a query once per search.

Source§

impl Encoder

Source

pub fn affine_query(&self, q: &[f32]) -> AffineQuery

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.