src/zero.rs

Fri, 28 Mar 2025 08:36:08 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 28 Mar 2025 08:36:08 -0500
changeset 59
743984f4664e
parent 55
15f01efc034b
permissions
-rw-r--r--

Add auxiliary results

/*!
Implementation of the the constant zero function on a manifold.
*/

use alg_tools::mapping::{Mapping, Instance};
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> {
    #[allow(dead_code)]
    pub fn new() -> Self {
        ZeroFn{_phantoms : PhantomData }
    }
}

impl<M : ManifoldPoint> Mapping<M> for ZeroFn<M> {
    type Codomain = f64;

    fn apply<I : Instance<M>>(&self, _x : I) -> Self::Codomain {
        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
    }
}

mercurial