pub trait SpatialSimilaritywhere
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 OptionNone 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§
Sourcefn cos(a: &[Self], b: &[Self]) -> Option<f64>
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.
Provided Methods§
Sourcefn sqeuclidean(a: &[Self], b: &[Self]) -> Option<f64>
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.
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.