# HG changeset patch # User Tuomo Valkonen # Date 1729518263 18000 # Node ID df962809228557f0290517dcec415f6e4d56e97c # Parent f248e1434c3bfb6fa15834b6fee5dcc876257354 Add a zero function on manifolds diff -r f248e1434c3b -r df9628092285 src/cube.rs --- 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)] diff -r f248e1434c3b -r df9628092285 src/main.rs --- 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() { diff -r f248e1434c3b -r df9628092285 src/manifold.rs --- 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; } diff -r f248e1434c3b -r df9628092285 src/zero.rs --- /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 { + _phantoms : PhantomData +} + +impl ZeroFn { + pub fn new() -> Self { + ZeroFn{_phantoms : PhantomData } + } +} + +impl Apply for ZeroFn { + type Output = f64; + + fn apply(&self, _x : M) -> Self::Output { + 0.0 + } +} + +impl<'a, M : ManifoldPoint> Apply<&'a M> for ZeroFn { + type Output = f64; + + fn apply(&self, _x : &'a M) -> Self::Output { + 0.0 + } +} + +impl Desc for ZeroFn { + fn desc(&self, _τ : f64, x : M) -> M { + x + } +} + +impl Grad for ZeroFn { + fn grad(&self, x : &M) -> M::Tangent { + x.tangent_origin() + } +} + +impl Prox for ZeroFn { + fn prox(&self, _τ : f64, x : M) -> M { + x + } +} \ No newline at end of file