simsimd

Trait SpatialSimilarity

Source
pub trait SpatialSimilarity
where Self: Sized,
{ // Required methods fn cos(a: &[Self], b: &[Self]) -> Option<f64>; fn dot(a: &[Self], b: &[Self]) -> Option<f64>; fn l2sq(a: &[Self], b: &[Self]) -> Option<f64>; // Provided methods fn sqeuclidean(a: &[Self], b: &[Self]) -> Option<f64> { ... } fn inner(a: &[Self], b: &[Self]) -> Option<f64> { ... } fn cosine(a: &[Self], b: &[Self]) -> Option<f64> { ... } }
Expand description

SpatialSimilarity provides a set of trait methods for computing similarity or distance between spatial data vectors in SIMD (Single Instruction, Multiple Data) context. These methods can be used to calculate metrics like cosine similarity, dot product, and squared Euclidean distance between two slices of data.

Each method takes two slices of data (a and b) and returns an Option. The result is None if the slices are not of the same length, as these operations require one-to-one correspondence between the elements of the slices. Otherwise, it returns the computed similarity or distance as Some(f32).

Required Methods§

Source

fn cos(a: &[Self], b: &[Self]) -> Option<f64>

Computes the cosine similarity between two slices. The cosine similarity is a measure of similarity between two non-zero vectors of an dot product space that measures the cosine of the angle between them.

Source

fn dot(a: &[Self], b: &[Self]) -> Option<f64>

Computes the inner product (also known as dot product) between two slices. The dot product is the sum of the products of the corresponding entries of the two sequences of numbers.

Source

fn l2sq(a: &[Self], b: &[Self]) -> Option<f64>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.

Provided Methods§

Source

fn sqeuclidean(a: &[Self], b: &[Self]) -> Option<f64>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.

Source

fn inner(a: &[Self], b: &[Self]) -> Option<f64>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.

Source

fn cosine(a: &[Self], b: &[Self]) -> Option<f64>

Computes the cosine similarity between two slices. The cosine similarity is a measure of similarity between two non-zero vectors of an dot product space that measures the cosine of the angle between them.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SpatialSimilarity for f32

Source§

fn cos(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn dot(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn l2sq(a: &[Self], b: &[Self]) -> Option<f64>

Source§

impl SpatialSimilarity for f64

Source§

fn cos(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn dot(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn l2sq(a: &[Self], b: &[Self]) -> Option<f64>

Source§

impl SpatialSimilarity for i8

Source§

fn cos(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn dot(a: &[Self], b: &[Self]) -> Option<f64>

Source§

fn l2sq(a: &[Self], b: &[Self]) -> Option<f64>

Implementors§