pub mod dotf32;
pub mod dotf64;
pub mod quantized;
pub trait DotProduct {
type Output;
fn dot_product(&self, other: &Self) -> Self::Output;
}
pub trait EuclideanDistance {
type Output;
fn euclidean_distance(&self, other: &Self) -> Self::Output;
}
impl DotProduct for [f32] {
type Output = f32;
#[inline]
fn dot_product(&self, other: &Self) -> Self::Output {
dotf32::dot_product(self, other)
}
}
impl DotProduct for [f64] {
type Output = f64;
#[inline]
fn dot_product(&self, other: &Self) -> Self::Output {
dotf64::dot_product(self, other)
}
}
impl EuclideanDistance for [f32] {
type Output = f32;
#[inline]
fn euclidean_distance(&self, other: &Self) -> Self::Output {
dotf32::euclidean_distance(self, other)
}
}
impl EuclideanDistance for [f64] {
type Output = f64;
#[inline]
fn euclidean_distance(&self, other: &Self) -> Self::Output {
dotf64::euclidean_distance(self, other)
}
}
#[inline]
pub fn dot_product<T>(a: &[T], b: &[T]) -> <[T] as DotProduct>::Output
where
[T]: DotProduct,
{
a.dot_product(b)
}
#[inline]
pub fn euclidean_distance<T>(a: &[T], b: &[T]) -> <[T] as EuclideanDistance>::Output
where
[T]: EuclideanDistance,
{
a.euclidean_distance(b)
}