src/bisection_tree/support.rs

branch
dev
changeset 150
c4e394a9c84c
parent 124
6aa955ad8122
child 151
402d717bb5c0
equal deleted inserted replaced
149:2f1798c65fd6 150:c4e394a9c84c
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
224 T: Clone, 224 T: Clone,
225 { 225 {
226 type Output = Weighted<T, F>; 226 type Output = Weighted<T, F>;
227 #[inline] 227 #[inline]
228 fn $fn(self, t: F) -> Self::Output { 228 fn $fn(self, t: F) -> Self::Output {
229 Weighted { 229 Weighted { weight: self.weight.$fn(t), base_fn: self.base_fn.clone() }
230 weight: self.weight.$fn(t),
231 base_fn: self.base_fn.clone(),
232 }
233 } 230 }
234 } 231 }
235 }; 232 };
236 } 233 }
237 234

mercurial