Tue, 01 Apr 2025 21:45:15 -0500
Another README typofix
13 | 1 | /*! |
2 | Implementation of the the constant zero function on a manifold. | |
3 | */ | |
6
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
55 | 5 | use alg_tools::mapping::{Mapping, Instance}; |
6
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 | 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 | |
55 | 22 | impl<M : ManifoldPoint> Mapping<M> for ZeroFn<M> { |
23 | type Codomain = f64; | |
6
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | |
55 | 25 | fn apply<I : Instance<M>>(&self, _x : I) -> Self::Codomain { |
6
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 | |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | impl<M : ManifoldPoint> Desc<M> for ZeroFn<M> { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | fn desc(&self, _τ : f64, x : M) -> M { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | x |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | } |
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 | impl<M : ManifoldPoint> Grad<M> for ZeroFn<M> { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | fn grad(&self, x : &M) -> M::Tangent { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | x.tangent_origin() |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | } |
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 | impl<M : ManifoldPoint> Prox<M> for ZeroFn<M> { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | fn prox(&self, _τ : f64, x : M) -> M { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | x |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | } |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | } |