src/zero.rs

Wed, 06 Nov 2024 22:27:35 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 06 Nov 2024 22:27:35 -0500
changeset 27
29859ffd0ac1
parent 19
bc7f268b324a
child 55
15f01efc034b
permissions
-rw-r--r--

.hgignore additions

13
f67949050a32 documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 6
diff changeset
1 /*!
f67949050a32 documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 6
diff changeset
2 Implementation of the the constant zero function on a manifold.
f67949050a32 documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 6
diff changeset
3 */
6
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 use alg_tools::mapping::Apply;
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 use crate::manifold::ManifoldPoint;
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 use crate::fb::{Grad, Desc, Prox};
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 use std::marker::PhantomData;
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 /// Zero function on manifolds.
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 pub struct ZeroFn<M : ManifoldPoint> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 _phantoms : PhantomData<M>
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 impl<M: ManifoldPoint> ZeroFn<M> {
19
bc7f268b324a test change
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
16 #[allow(dead_code)]
6
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 pub fn new() -> Self {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 ZeroFn{_phantoms : PhantomData }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 impl<M : ManifoldPoint> Apply<M> for ZeroFn<M> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 type Output = f64;
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 fn apply(&self, _x : M) -> Self::Output {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 0.0
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 impl<'a, M : ManifoldPoint> Apply<&'a M> for ZeroFn<M> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 type Output = f64;
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 fn apply(&self, _x : &'a M) -> Self::Output {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 0.0
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 impl<M : ManifoldPoint> Desc<M> for ZeroFn<M> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 fn desc(&self, _τ : f64, x : M) -> M {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 x
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 impl<M : ManifoldPoint> Grad<M> for ZeroFn<M> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
45 fn grad(&self, x : &M) -> M::Tangent {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 x.tangent_origin()
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 impl<M : ManifoldPoint> Prox<M> for ZeroFn<M> {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 fn prox(&self, _τ : f64, x : M) -> M {
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 x
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 }
df9628092285 Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 }

mercurial