pub struct L2Distance;Expand description
Squared Euclidean distance: $d(a, b) = \sum_i (a_i - b_i)^2$.
Returns the squared distance (no sqrt) because ranking is preserved and sqrt is unnecessary for nearest-neighbor comparisons.
§Example
use cvx_core::DistanceMetric;
use cvx_index::metrics::L2Distance;
let d = L2Distance;
let a = vec![1.0, 0.0];
let b = vec![0.0, 1.0];
assert!((d.distance(&a, &b) - 2.0).abs() < 1e-5); // (1-0)^2 + (0-1)^2 = 2Trait Implementations§
Source§impl Clone for L2Distance
impl Clone for L2Distance
Source§fn clone(&self) -> L2Distance
fn clone(&self) -> L2Distance
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl DistanceMetric for L2Distance
impl DistanceMetric for L2Distance
impl Copy for L2Distance
Auto Trait Implementations§
impl Freeze for L2Distance
impl RefUnwindSafe for L2Distance
impl Send for L2Distance
impl Sync for L2Distance
impl Unpin for L2Distance
impl UnwindSafe for L2Distance
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more