| 2 Traits for representing the support of a [`Mapping`], and analysing the mapping on a [`Cube`]. |
2 Traits for representing the support of a [`Mapping`], and analysing the mapping on a [`Cube`]. |
| 3 */ |
3 */ |
| 4 use super::aggregator::Bounds; |
4 use super::aggregator::Bounds; |
| 5 pub use crate::bounds::{GlobalAnalysis, LocalAnalysis}; |
5 pub use crate::bounds::{GlobalAnalysis, LocalAnalysis}; |
| 6 use crate::loc::Loc; |
6 use crate::loc::Loc; |
| 7 use crate::mapping::{DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space}; |
7 use crate::mapping::{ |
| |
8 ClosedSpace, DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space, |
| |
9 }; |
| 8 use crate::maputil::map2; |
10 use crate::maputil::map2; |
| 9 use crate::norms::{Linfinity, Norm, L1, L2}; |
11 use crate::norms::{Linfinity, Norm, L1, L2}; |
| 10 pub use crate::operator_arithmetic::{Constant, Weighted}; |
12 pub use crate::operator_arithmetic::{Constant, Weighted}; |
| 11 use crate::sets::Cube; |
13 use crate::sets::Cube; |
| 12 use crate::types::{Float, Num}; |
14 use crate::types::{Float, Num}; |
| 44 } |
46 } |
| 45 |
47 |
| 46 /// Translate `self` by `x`. |
48 /// Translate `self` by `x`. |
| 47 #[inline] |
49 #[inline] |
| 48 fn shift(self, x: Loc<N, F>) -> Shift<Self, N, F> { |
50 fn shift(self, x: Loc<N, F>) -> Shift<Self, N, F> { |
| 49 Shift { |
51 Shift { shift: x, base_fn: self } |
| 50 shift: x, |
|
| 51 base_fn: self, |
|
| 52 } |
|
| 53 } |
52 } |
| 54 } |
53 } |
| 55 |
54 |
| 56 /// Shift of [`Support`] and [`Mapping`]; output of [`Support::shift`]. |
55 /// Shift of [`Support`] and [`Mapping`]; output of [`Support::shift`]. |
| 57 #[derive(Copy, Clone, Debug, Serialize)] // Serialize! but not implemented by Loc. |
56 #[derive(Copy, Clone, Debug, Serialize)] // Serialize! but not implemented by Loc. |
| 58 pub struct Shift<T, const N: usize, F = f64> { |
57 pub struct Shift<T, const N: usize, F = f64> { |
| 59 shift: Loc<N, F>, |
58 shift: Loc<N, F>, |
| 60 base_fn: T, |
59 base_fn: T, |
| 61 } |
60 } |
| 62 |
61 |
| 63 impl<'a, T, V: Space, F: Float, const N: usize> Mapping<Loc<N, F>> for Shift<T, N, F> |
62 impl<'a, T, V: ClosedSpace, F: Float, const N: usize> Mapping<Loc<N, F>> for Shift<T, N, F> |
| 64 where |
63 where |
| 65 T: Mapping<Loc<N, F>, Codomain = V>, |
64 T: Mapping<Loc<N, F>, Codomain = V>, |
| 66 { |
65 { |
| 67 type Codomain = V; |
66 type Codomain = V; |
| 68 |
67 |
| 70 fn apply<I: Instance<Loc<N, F>>>(&self, x: I) -> Self::Codomain { |
69 fn apply<I: Instance<Loc<N, F>>>(&self, x: I) -> Self::Codomain { |
| 71 self.base_fn.apply(x.own() - &self.shift) |
70 self.base_fn.apply(x.own() - &self.shift) |
| 72 } |
71 } |
| 73 } |
72 } |
| 74 |
73 |
| 75 impl<'a, T, V: Space, F: Float, const N: usize> DifferentiableImpl<Loc<N, F>> for Shift<T, N, F> |
74 impl<'a, T, V: ClosedSpace, F: Float, const N: usize> DifferentiableImpl<Loc<N, F>> |
| |
75 for Shift<T, N, F> |
| 76 where |
76 where |
| 77 T: DifferentiableMapping<Loc<N, F>, DerivativeDomain = V>, |
77 T: DifferentiableMapping<Loc<N, F>, DerivativeDomain = V>, |
| 78 { |
78 { |
| 79 type Derivative = V; |
79 type Derivative = V; |
| 80 |
80 |