diff -r cfd8d2304e9e -r 15f01efc034b src/dist.rs --- a/src/dist.rs Sat Dec 07 21:54:59 2024 -0500 +++ b/src/dist.rs Sun Dec 15 01:10:52 2024 -0500 @@ -2,7 +2,7 @@ Implementations of the distance function and the distance function squared, on manifolds. */ -use alg_tools::mapping::Apply; +use alg_tools::mapping::{Mapping, Instance}; use alg_tools::euclidean::Euclidean; use crate::manifold::ManifoldPoint; use crate::fb::{Grad, Desc, Prox}; @@ -10,39 +10,22 @@ /// Structure for distance-to functions pub struct DistTo(pub M); -impl Apply for DistTo { - type Output = f64; +impl Mapping for DistTo { + type Codomain = f64; - fn apply(&self, x : M) -> Self::Output { - self.0.dist_to(&x) - } -} - -impl<'a, M : ManifoldPoint> Apply<&'a M> for DistTo { - type Output = f64; - - fn apply(&self, x : &'a M) -> Self::Output { - self.0.dist_to(x) + fn apply>(&self, x : I) -> Self::Codomain { + x.eval(|x̃| self.0.dist_to(x̃)) } } /// Structure for distance-to functions pub struct DistToSquaredDiv2(pub M); -impl Apply for DistToSquaredDiv2 { - type Output = f64; +impl Mapping for DistToSquaredDiv2 { + type Codomain = f64; - fn apply(&self, x : M) -> Self::Output { - let d = self.0.dist_to(&x); - d*d / 2.0 - } -} - -impl<'a, M : ManifoldPoint> Apply<&'a M> for DistToSquaredDiv2 { - type Output = f64; - - fn apply(&self, x : &'a M) -> Self::Output { - let d = self.0.dist_to(x); + fn apply>(&self, x : I) -> Self::Codomain { + let d = x.eval(|x̃| self.0.dist_to(x̃)); d*d / 2.0 } }