Skip to main content

DistanceKernel

Trait DistanceKernel 

Source
pub trait DistanceKernel: Send + Sync {
    // Required methods
    fn l2_squared_f32(&self, a: &[f32], b: &[f32]) -> f32;
    fn dot_f32(&self, a: &[f32], b: &[f32]) -> f32;
    fn dot_i8(&self, a: &[i8], b: &[i8]) -> i32;
    fn l2_squared_batch_f32(
        &self,
        query: &[f32],
        vectors: &[f32],
        dim: usize,
        out: &mut [f32],
    );
    fn dot_batch_f32(
        &self,
        query: &[f32],
        vectors: &[f32],
        dim: usize,
        out: &mut [f32],
    );
    fn simd_level(&self) -> SimdLevel;
}
Expand description

Trait for portable distance kernels

Required Methods§

Source

fn l2_squared_f32(&self, a: &[f32], b: &[f32]) -> f32

Compute L2 squared distance between two f32 vectors

Source

fn dot_f32(&self, a: &[f32], b: &[f32]) -> f32

Compute dot product of two f32 vectors

Source

fn dot_i8(&self, a: &[i8], b: &[i8]) -> i32

Compute dot product of two i8 vectors (returns i32)

Source

fn l2_squared_batch_f32( &self, query: &[f32], vectors: &[f32], dim: usize, out: &mut [f32], )

Batch L2 squared: query vs multiple vectors

Source

fn dot_batch_f32( &self, query: &[f32], vectors: &[f32], dim: usize, out: &mut [f32], )

Batch dot product: query vs multiple vectors

Source

fn simd_level(&self) -> SimdLevel

SIMD level of this kernel

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl DistanceKernel for Avx2Kernel

Available on x86-64 only.
Source§

impl DistanceKernel for ScalarKernel