Mon, 21 Oct 2024 08:44:23 -0500
Add a zero function on manifolds
src/cube.rs | file | annotate | diff | comparison | revisions | |
src/main.rs | file | annotate | diff | comparison | revisions | |
src/manifold.rs | file | annotate | diff | comparison | revisions | |
src/zero.rs | file | annotate | diff | comparison | revisions |
--- a/src/cube.rs Sat Oct 19 10:46:13 2024 -0500 +++ b/src/cube.rs Mon Oct 21 08:44:23 2024 -0500 @@ -232,6 +232,10 @@ fn dist_to(&self, other : &Self) -> f64 { self.log_dist(other).1 } + + fn tangent_origin(&self) -> Self::Tangent { + Loc([0.0, 0.0]) + } } #[cfg(test)]
--- a/src/main.rs Sat Oct 19 10:46:13 2024 -0500 +++ b/src/main.rs Mon Oct 21 08:44:23 2024 -0500 @@ -9,6 +9,7 @@ mod fb; mod cube; mod dist; +mod zero; fn main() {
--- a/src/manifold.rs Sat Oct 19 10:46:13 2024 -0500 +++ b/src/manifold.rs Mon Oct 21 08:44:23 2024 -0500 @@ -14,5 +14,8 @@ /// Distance to `other` fn dist_to(&self, other : &Self) -> f64; + + /// Return the zero tangent at `self`. + fn tangent_origin(&self) -> Self::Tangent; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/zero.rs Mon Oct 21 08:44:23 2024 -0500 @@ -0,0 +1,50 @@ + +use alg_tools::mapping::Apply; +use crate::manifold::ManifoldPoint; +use crate::fb::{Grad, Desc, Prox}; +use std::marker::PhantomData; + +/// Zero function on manifolds. +pub struct ZeroFn<M : ManifoldPoint> { + _phantoms : PhantomData<M> +} + +impl<M: ManifoldPoint> ZeroFn<M> { + pub fn new() -> Self { + ZeroFn{_phantoms : PhantomData } + } +} + +impl<M : ManifoldPoint> Apply<M> for ZeroFn<M> { + type Output = f64; + + fn apply(&self, _x : M) -> Self::Output { + 0.0 + } +} + +impl<'a, M : ManifoldPoint> Apply<&'a M> for ZeroFn<M> { + type Output = f64; + + fn apply(&self, _x : &'a M) -> Self::Output { + 0.0 + } +} + +impl<M : ManifoldPoint> Desc<M> for ZeroFn<M> { + fn desc(&self, _τ : f64, x : M) -> M { + x + } +} + +impl<M : ManifoldPoint> Grad<M> for ZeroFn<M> { + fn grad(&self, x : &M) -> M::Tangent { + x.tangent_origin() + } +} + +impl<M : ManifoldPoint> Prox<M> for ZeroFn<M> { + fn prox(&self, _τ : f64, x : M) -> M { + x + } +} \ No newline at end of file