src/bisection_tree/support.rs

branch
dev
changeset 97
4e80fb049dca
parent 96
962c8e346ab9
child 124
6aa955ad8122
equal deleted inserted replaced
96:962c8e346ab9 97:4e80fb049dca
1 /*! 1 /*!
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 use crate::loc::Loc; 6 use crate::loc::Loc;
6 use crate::mapping::{DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space}; 7 use crate::mapping::{DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space};
7 use crate::maputil::map2; 8 use crate::maputil::map2;
8 use crate::norms::{Linfinity, Norm, L1, L2}; 9 use crate::norms::{Linfinity, Norm, L1, L2};
9 pub use crate::operator_arithmetic::{Constant, Weighted}; 10 pub use crate::operator_arithmetic::{Constant, Weighted};
50 base_fn: self, 51 base_fn: self,
51 } 52 }
52 } 53 }
53 } 54 }
54 55
55 /// Trait for globally analysing a property `A` of a [`Mapping`].
56 ///
57 /// Typically `A` is an [`Aggregator`][super::aggregator::Aggregator] such as
58 /// [`Bounds`][super::aggregator::Bounds].
59 pub trait GlobalAnalysis<F: Num, A> {
60 /// Perform global analysis of the property `A` of `Self`.
61 ///
62 /// As an example, in the case of `A` being [`Bounds`][super::aggregator::Bounds],
63 /// this function will return global upper and lower bounds for the mapping
64 /// represented by `self`.
65 fn global_analysis(&self) -> A;
66 }
67
68 // default impl<F, A, N, L> GlobalAnalysis<F, A, N> for L
69 // where L : LocalAnalysis<F, A, N> {
70 // #[inline]
71 // fn global_analysis(&self) -> Bounds<F> {
72 // self.local_analysis(&self.support_hint())
73 // }
74 // }
75
76 /// Trait for locally analysing a property `A` of a [`Mapping`] (implementing [`Support`])
77 /// within a [`Cube`].
78 ///
79 /// Typically `A` is an [`Aggregator`][super::aggregator::Aggregator] such as
80 /// [`Bounds`][super::aggregator::Bounds].
81 pub trait LocalAnalysis<F: Num, A, const N: usize>: GlobalAnalysis<F, A> + Support<F, N> {
82 /// Perform local analysis of the property `A` of `Self`.
83 ///
84 /// As an example, in the case of `A` being [`Bounds`][super::aggregator::Bounds],
85 /// this function will return upper and lower bounds within `cube` for the mapping
86 /// represented by `self`.
87 fn local_analysis(&self, cube: &Cube<F, N>) -> A;
88 }
89
90 /// Trait for determining the upper and lower bounds of an float-valued [`Mapping`].
91 ///
92 /// This is a blanket-implemented alias for [`GlobalAnalysis`]`<F, Bounds<F>>`
93 /// [`Mapping`] is not a supertrait to allow flexibility in the implementation of either
94 /// reference or non-reference arguments.
95 pub trait Bounded<F: Float>: GlobalAnalysis<F, Bounds<F>> {
96 /// Return lower and upper bounds for the values of of `self`.
97 #[inline]
98 fn bounds(&self) -> Bounds<F> {
99 self.global_analysis()
100 }
101 }
102
103 impl<F: Float, T: GlobalAnalysis<F, Bounds<F>>> Bounded<F> for T {}
104
105 /// Shift of [`Support`] and [`Mapping`]; output of [`Support::shift`]. 56 /// Shift of [`Support`] and [`Mapping`]; output of [`Support::shift`].
106 #[derive(Copy, Clone, Debug, Serialize)] // Serialize! but not implemented by Loc. 57 #[derive(Copy, Clone, Debug, Serialize)] // Serialize! but not implemented by Loc.
107 pub struct Shift<T, F, const N: usize> { 58 pub struct Shift<T, F, const N: usize> {
108 shift: Loc<F, N>, 59 shift: Loc<F, N>,
109 base_fn: T, 60 base_fn: T,

mercurial