Sun, 27 Apr 2025 15:45:40 -0500
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
| 5 | 1 | /*! |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
2 | Traits for representing the support of a [`Mapping`], and analysing the mapping on a [`Cube`]. |
| 5 | 3 | */ |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
4 | use super::aggregator::Bounds; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
5 | use crate::loc::Loc; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
6 | use crate::mapping::{DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space}; |
| 5 | 7 | use crate::maputil::map2; |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
8 | use crate::norms::{Linfinity, Norm, L1, L2}; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
9 | pub use crate::operator_arithmetic::{Constant, Weighted}; |
| 5 | 10 | use crate::sets::Cube; |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
11 | use crate::types::{Float, Num}; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
12 | use serde::Serialize; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
13 | use std::ops::{DivAssign, MulAssign, Neg}; |
| 0 | 14 | |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
15 | /// A trait for working with the supports of [`Mapping`]s. |
| 5 | 16 | /// |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
17 | /// `Mapping` is not a super-trait to allow more general use. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
18 | pub trait Support<F: Num, const N: usize>: Sized + Sync + Send + 'static { |
| 5 | 19 | /// Return a cube containing the support of the function represented by `self`. |
| 20 | /// | |
| 21 | /// The hint may be larger than the actual support, but must contain it. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
22 | fn support_hint(&self) -> Cube<F, N>; |
| 0 | 23 | |
| 5 | 24 | /// Indicate whether `x` is in the support of the function represented by `self`. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
25 | fn in_support(&self, x: &Loc<F, N>) -> bool; |
| 0 | 26 | |
| 5 | 27 | // Indicate whether `cube` is fully in the support of the function represented by `self`. |
| 0 | 28 | //fn fully_in_support(&self, cube : &Cube<F,N>) -> bool; |
| 29 | ||
| 5 | 30 | /// Return an optional hint for bisecting the support. |
| 31 | /// | |
| 32 | /// The output along each axis a possible coordinate at which to bisect `cube`. | |
| 33 | /// | |
| 34 | /// This is useful for nonsmooth functions to make finite element models as used by | |
| 35 | /// [`BTFN`][super::btfn::BTFN] minimisation/maximisation compatible with points of | |
| 36 | /// non-differentiability. | |
| 37 | /// | |
| 38 | /// The default implementation returns `[None; N]`. | |
| 0 | 39 | #[inline] |
| 5 | 40 | #[allow(unused_variables)] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
41 | fn bisection_hint(&self, cube: &Cube<F, N>) -> [Option<F>; N] { |
| 5 | 42 | [None; N] |
| 0 | 43 | } |
| 44 | ||
| 5 | 45 | /// Translate `self` by `x`. |
| 0 | 46 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
47 | fn shift(self, x: Loc<F, N>) -> Shift<Self, F, N> { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
48 | Shift { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
49 | shift: x, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
50 | base_fn: self, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
51 | } |
| 0 | 52 | } |
| 53 | } | |
| 54 | ||
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
55 | /// Trait for globally analysing a property `A` of a [`Mapping`]. |
| 5 | 56 | /// |
| 57 | /// Typically `A` is an [`Aggregator`][super::aggregator::Aggregator] such as | |
| 58 | /// [`Bounds`][super::aggregator::Bounds]. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
59 | pub trait GlobalAnalysis<F: Num, A> { |
| 5 | 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`. | |
| 0 | 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 | ||
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
76 | /// Trait for locally analysing a property `A` of a [`Mapping`] (implementing [`Support`]) |
| 5 | 77 | /// within a [`Cube`]. |
| 78 | /// | |
| 79 | /// Typically `A` is an [`Aggregator`][super::aggregator::Aggregator] such as | |
| 80 | /// [`Bounds`][super::aggregator::Bounds]. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
81 | pub trait LocalAnalysis<F: Num, A, const N: usize>: GlobalAnalysis<F, A> + Support<F, N> { |
| 5 | 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`. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
87 | fn local_analysis(&self, cube: &Cube<F, N>) -> A; |
| 0 | 88 | } |
| 89 | ||
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
90 | /// Trait for determining the upper and lower bounds of an float-valued [`Mapping`]. |
| 5 | 91 | /// |
| 0 | 92 | /// This is a blanket-implemented alias for [`GlobalAnalysis`]`<F, Bounds<F>>` |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
93 | /// [`Mapping`] is not a supertrait to allow flexibility in the implementation of either |
| 0 | 94 | /// reference or non-reference arguments. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
95 | pub trait Bounded<F: Float>: GlobalAnalysis<F, Bounds<F>> { |
| 0 | 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 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
103 | impl<F: Float, T: GlobalAnalysis<F, Bounds<F>>> Bounded<F> for T {} |
| 0 | 104 | |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
105 | /// Shift of [`Support`] and [`Mapping`]; output of [`Support::shift`]. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
106 | #[derive(Copy, Clone, Debug, Serialize)] // Serialize! but not implemented by Loc. |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
107 | pub struct Shift<T, F, const N: usize> { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
108 | shift: Loc<F, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
109 | base_fn: T, |
| 0 | 110 | } |
| 111 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
112 | impl<'a, T, V: Space, F: Float, const N: usize> Mapping<Loc<F, N>> for Shift<T, F, N> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
113 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
114 | T: Mapping<Loc<F, N>, Codomain = V>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
115 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
116 | type Codomain = V; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
117 | |
| 0 | 118 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
119 | fn apply<I: Instance<Loc<F, N>>>(&self, x: I) -> Self::Codomain { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
120 | self.base_fn.apply(x.own() - &self.shift) |
| 0 | 121 | } |
| 122 | } | |
| 123 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
124 | impl<'a, T, V: Space, F: Float, const N: usize> DifferentiableImpl<Loc<F, N>> for Shift<T, F, N> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
125 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
126 | T: DifferentiableMapping<Loc<F, N>, DerivativeDomain = V>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
127 | { |
|
47
a0db98c16ab5
Some Differentiable simplifications and clarifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
30
diff
changeset
|
128 | type Derivative = V; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
129 | |
|
30
9f2214c961cb
Implement Differentiable for Weighted and Shift
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
130 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
131 | fn differential_impl<I: Instance<Loc<F, N>>>(&self, x: I) -> Self::Derivative { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
132 | self.base_fn.differential(x.own() - &self.shift) |
|
30
9f2214c961cb
Implement Differentiable for Weighted and Shift
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
133 | } |
|
9f2214c961cb
Implement Differentiable for Weighted and Shift
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
134 | } |
|
9f2214c961cb
Implement Differentiable for Weighted and Shift
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
135 | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
136 | impl<'a, T, F: Float, const N: usize> Support<F, N> for Shift<T, F, N> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
137 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
138 | T: Support<F, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
139 | { |
| 0 | 140 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
141 | fn support_hint(&self) -> Cube<F, N> { |
| 0 | 142 | self.base_fn.support_hint().shift(&self.shift) |
| 143 | } | |
| 144 | ||
| 145 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
146 | fn in_support(&self, x: &Loc<F, N>) -> bool { |
| 0 | 147 | self.base_fn.in_support(&(x - &self.shift)) |
| 148 | } | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
149 | |
| 0 | 150 | // fn fully_in_support(&self, _cube : &Cube<F,N>) -> bool { |
| 151 | // //self.base_fn.fully_in_support(cube.shift(&vectorneg(self.shift))) | |
| 152 | // todo!("Not implemented, but not used at the moment") | |
| 153 | // } | |
| 154 | ||
| 155 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
156 | fn bisection_hint(&self, cube: &Cube<F, N>) -> [Option<F>; N] { |
| 0 | 157 | let base_hint = self.base_fn.bisection_hint(cube); |
| 158 | map2(base_hint, &self.shift, |h, s| h.map(|z| z + *s)) | |
| 159 | } | |
| 160 | } | |
| 161 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
162 | impl<'a, T, F: Float, const N: usize> GlobalAnalysis<F, Bounds<F>> for Shift<T, F, N> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
163 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
164 | T: LocalAnalysis<F, Bounds<F>, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
165 | { |
| 0 | 166 | #[inline] |
| 167 | fn global_analysis(&self) -> Bounds<F> { | |
| 168 | self.base_fn.global_analysis() | |
| 169 | } | |
| 170 | } | |
| 171 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
172 | impl<'a, T, F: Float, const N: usize> LocalAnalysis<F, Bounds<F>, N> for Shift<T, F, N> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
173 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
174 | T: LocalAnalysis<F, Bounds<F>, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
175 | { |
| 0 | 176 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
177 | fn local_analysis(&self, cube: &Cube<F, N>) -> Bounds<F> { |
| 0 | 178 | self.base_fn.local_analysis(&cube.shift(&(-self.shift))) |
| 179 | } | |
| 180 | } | |
| 181 | ||
| 182 | macro_rules! impl_shift_norm { | |
| 183 | ($($norm:ident)*) => { $( | |
| 184 | impl<'a, T, F : Float, const N : usize> Norm<F, $norm> for Shift<T,F,N> | |
| 185 | where T : Norm<F, $norm> { | |
| 186 | #[inline] | |
| 187 | fn norm(&self, n : $norm) -> F { | |
| 188 | self.base_fn.norm(n) | |
| 189 | } | |
| 190 | } | |
| 191 | )* } | |
| 192 | } | |
| 193 | ||
| 194 | impl_shift_norm!(L1 L2 Linfinity); | |
| 195 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
196 | impl<'a, T, F: Float, C, const N: usize> Support<F, N> for Weighted<T, C> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
197 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
198 | T: Support<F, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
199 | C: Constant<Type = F>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
200 | { |
| 0 | 201 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
202 | fn support_hint(&self) -> Cube<F, N> { |
| 0 | 203 | self.base_fn.support_hint() |
| 204 | } | |
| 205 | ||
| 206 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
207 | fn in_support(&self, x: &Loc<F, N>) -> bool { |
| 0 | 208 | self.base_fn.in_support(x) |
| 209 | } | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
210 | |
| 0 | 211 | // fn fully_in_support(&self, cube : &Cube<F,N>) -> bool { |
| 212 | // self.base_fn.fully_in_support(cube) | |
| 213 | // } | |
| 214 | ||
| 215 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
216 | fn bisection_hint(&self, cube: &Cube<F, N>) -> [Option<F>; N] { |
| 0 | 217 | self.base_fn.bisection_hint(cube) |
| 218 | } | |
| 219 | } | |
| 220 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
221 | impl<'a, T, F: Float, C> GlobalAnalysis<F, Bounds<F>> for Weighted<T, C> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
222 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
223 | T: GlobalAnalysis<F, Bounds<F>>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
224 | C: Constant<Type = F>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
225 | { |
| 0 | 226 | #[inline] |
| 227 | fn global_analysis(&self) -> Bounds<F> { | |
| 228 | let Bounds(lower, upper) = self.base_fn.global_analysis(); | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
229 | debug_assert!(lower <= upper); |
| 0 | 230 | match self.weight.value() { |
| 231 | w if w < F::ZERO => Bounds(w * upper, w * lower), | |
| 232 | w => Bounds(w * lower, w * upper), | |
| 233 | } | |
| 234 | } | |
| 235 | } | |
| 236 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
237 | impl<'a, T, F: Float, C, const N: usize> LocalAnalysis<F, Bounds<F>, N> for Weighted<T, C> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
238 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
239 | T: LocalAnalysis<F, Bounds<F>, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
240 | C: Constant<Type = F>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
241 | { |
| 0 | 242 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
243 | fn local_analysis(&self, cube: &Cube<F, N>) -> Bounds<F> { |
| 0 | 244 | let Bounds(lower, upper) = self.base_fn.local_analysis(cube); |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
245 | debug_assert!(lower <= upper); |
| 0 | 246 | match self.weight.value() { |
| 247 | w if w < F::ZERO => Bounds(w * upper, w * lower), | |
| 248 | w => Bounds(w * lower, w * upper), | |
| 249 | } | |
| 250 | } | |
| 251 | } | |
| 252 | ||
| 253 | macro_rules! make_weighted_scalarop_rhs { | |
| 254 | ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => { | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
255 | impl<F: Float, T> std::ops::$trait_assign<F> for Weighted<T, F> { |
| 0 | 256 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
257 | fn $fn_assign(&mut self, t: F) { |
| 0 | 258 | self.weight.$fn_assign(t); |
| 259 | } | |
| 260 | } | |
| 261 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
262 | impl<'a, F: Float, T> std::ops::$trait<F> for Weighted<T, F> { |
| 0 | 263 | type Output = Self; |
| 264 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
265 | fn $fn(mut self, t: F) -> Self { |
| 0 | 266 | self.weight.$fn_assign(t); |
| 267 | self | |
| 268 | } | |
| 269 | } | |
| 270 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
271 | impl<'a, F: Float, T> std::ops::$trait<F> for &'a Weighted<T, F> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
272 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
273 | T: Clone, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
274 | { |
| 0 | 275 | type Output = Weighted<T, F>; |
| 276 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
277 | fn $fn(self, t: F) -> Self::Output { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
278 | Weighted { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
279 | weight: self.weight.$fn(t), |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
280 | base_fn: self.base_fn.clone(), |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
281 | } |
| 0 | 282 | } |
| 283 | } | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
284 | }; |
| 0 | 285 | } |
| 286 | ||
| 287 | make_weighted_scalarop_rhs!(Mul, mul, MulAssign, mul_assign); | |
| 288 | make_weighted_scalarop_rhs!(Div, div, DivAssign, div_assign); | |
| 289 | ||
| 290 | macro_rules! impl_weighted_norm { | |
| 291 | ($($norm:ident)*) => { $( | |
| 292 | impl<'a, T, F : Float> Norm<F, $norm> for Weighted<T,F> | |
| 293 | where T : Norm<F, $norm> { | |
| 294 | #[inline] | |
| 295 | fn norm(&self, n : $norm) -> F { | |
| 296 | self.base_fn.norm(n) * self.weight.abs() | |
| 297 | } | |
| 298 | } | |
| 299 | )* } | |
| 300 | } | |
| 301 | ||
| 302 | impl_weighted_norm!(L1 L2 Linfinity); | |
| 303 | ||
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
304 | /// Normalisation of [`Support`] and [`Mapping`] to L¹ norm 1. |
| 5 | 305 | /// |
| 0 | 306 | /// Currently only scalar-valued functions are supported. |
| 307 | #[derive(Copy, Clone, Debug, Serialize, PartialEq)] | |
| 5 | 308 | pub struct Normalised<T>( |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
309 | /// The base [`Support`] or [`Mapping`]. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
310 | pub T, |
| 5 | 311 | ); |
| 0 | 312 | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
313 | impl<'a, T, F: Float, const N: usize> Mapping<Loc<F, N>> for Normalised<T> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
314 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
315 | T: Norm<F, L1> + Mapping<Loc<F, N>, Codomain = F>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
316 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
317 | type Codomain = F; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
47
diff
changeset
|
318 | |
| 0 | 319 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
320 | fn apply<I: Instance<Loc<F, N>>>(&self, x: I) -> Self::Codomain { |
| 0 | 321 | let w = self.0.norm(L1); |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
322 | if w == F::ZERO { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
323 | F::ZERO |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
324 | } else { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
325 | self.0.apply(x) / w |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
326 | } |
| 0 | 327 | } |
| 328 | } | |
| 329 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
330 | impl<'a, T, F: Float, const N: usize> Support<F, N> for Normalised<T> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
331 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
332 | T: Norm<F, L1> + Support<F, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
333 | { |
| 0 | 334 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
335 | fn support_hint(&self) -> Cube<F, N> { |
| 0 | 336 | self.0.support_hint() |
| 337 | } | |
| 338 | ||
| 339 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
340 | fn in_support(&self, x: &Loc<F, N>) -> bool { |
| 0 | 341 | self.0.in_support(x) |
| 342 | } | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
343 | |
| 0 | 344 | // fn fully_in_support(&self, cube : &Cube<F,N>) -> bool { |
| 345 | // self.0.fully_in_support(cube) | |
| 346 | // } | |
| 347 | ||
| 348 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
349 | fn bisection_hint(&self, cube: &Cube<F, N>) -> [Option<F>; N] { |
| 0 | 350 | self.0.bisection_hint(cube) |
| 351 | } | |
| 352 | } | |
| 353 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
354 | impl<'a, T, F: Float> GlobalAnalysis<F, Bounds<F>> for Normalised<T> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
355 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
356 | T: Norm<F, L1> + GlobalAnalysis<F, Bounds<F>>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
357 | { |
| 0 | 358 | #[inline] |
| 359 | fn global_analysis(&self) -> Bounds<F> { | |
| 360 | let Bounds(lower, upper) = self.0.global_analysis(); | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
361 | debug_assert!(lower <= upper); |
| 0 | 362 | let w = self.0.norm(L1); |
| 363 | debug_assert!(w >= F::ZERO); | |
| 364 | Bounds(w * lower, w * upper) | |
| 365 | } | |
| 366 | } | |
| 367 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
368 | impl<'a, T, F: Float, const N: usize> LocalAnalysis<F, Bounds<F>, N> for Normalised<T> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
369 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
370 | T: Norm<F, L1> + LocalAnalysis<F, Bounds<F>, N>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
371 | { |
| 0 | 372 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
373 | fn local_analysis(&self, cube: &Cube<F, N>) -> Bounds<F> { |
| 0 | 374 | let Bounds(lower, upper) = self.0.local_analysis(cube); |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
375 | debug_assert!(lower <= upper); |
| 0 | 376 | let w = self.0.norm(L1); |
| 377 | debug_assert!(w >= F::ZERO); | |
| 378 | Bounds(w * lower, w * upper) | |
| 379 | } | |
| 380 | } | |
| 381 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
382 | impl<'a, T, F: Float> Norm<F, L1> for Normalised<T> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
383 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
384 | T: Norm<F, L1>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
385 | { |
| 0 | 386 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
387 | fn norm(&self, _: L1) -> F { |
| 0 | 388 | let w = self.0.norm(L1); |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
389 | if w == F::ZERO { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
390 | F::ZERO |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
391 | } else { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
392 | F::ONE |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
393 | } |
| 0 | 394 | } |
| 395 | } | |
| 396 | ||
| 397 | macro_rules! impl_normalised_norm { | |
| 398 | ($($norm:ident)*) => { $( | |
| 399 | impl<'a, T, F : Float> Norm<F, $norm> for Normalised<T> | |
| 400 | where T : Norm<F, $norm> + Norm<F, L1> { | |
| 401 | #[inline] | |
| 402 | fn norm(&self, n : $norm) -> F { | |
| 403 | let w = self.0.norm(L1); | |
| 404 | if w == F::ZERO { F::ZERO } else { self.0.norm(n) / w } | |
| 405 | } | |
| 406 | } | |
| 407 | )* } | |
| 408 | } | |
| 409 | ||
| 410 | impl_normalised_norm!(L2 Linfinity); | |
| 411 | ||
| 412 | /* | |
| 413 | impl<F : Num, S : Support<F, N>, const N : usize> LocalAnalysis<F, NullAggregator, N> for S { | |
| 414 | fn local_analysis(&self, _cube : &Cube<F, N>) -> NullAggregator { NullAggregator } | |
| 415 | } | |
| 416 | ||
| 417 | impl<F : Float, S : Bounded<F>, const N : usize> LocalAnalysis<F, Bounds<F>, N> for S { | |
| 418 | #[inline] | |
| 419 | fn local_analysis(&self, cube : &Cube<F, N>) -> Bounds<F> { | |
| 420 | self.bounds(cube) | |
| 421 | } | |
| 422 | }*/ | |
| 423 | ||
| 5 | 424 | /// Generator of [`Support`]-implementing component functions based on low storage requirement |
| 425 | /// [ids][`Self::Id`]. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
426 | pub trait SupportGenerator<F: Float, const N: usize>: |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
427 | MulAssign<F> + DivAssign<F> + Neg<Output = Self> + Clone + Sync + Send + 'static |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
428 | { |
| 5 | 429 | /// The identification type |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
430 | type Id: 'static + Copy; |
|
75
e9f4550cfa18
Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents:
68
diff
changeset
|
431 | /// The type of the [`Support`] (often also a [`Mapping`]). |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
432 | type SupportType: 'static + Support<F, N>; |
| 5 | 433 | /// An iterator over all the [`Support`]s of the generator. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
434 | type AllDataIter<'a>: Iterator<Item = (Self::Id, Self::SupportType)> |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
435 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
436 | Self: 'a; |
| 0 | 437 | |
| 5 | 438 | /// Returns the component identified by `id`. |
| 439 | /// | |
| 440 | /// Panics if `id` is an invalid identifier. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
441 | fn support_for(&self, id: Self::Id) -> Self::SupportType; |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
442 | |
| 5 | 443 | /// Returns the number of different components in this generator. |
| 0 | 444 | fn support_count(&self) -> usize; |
| 445 | ||
| 5 | 446 | /// Returns an iterator over all pairs of `(id, support)`. |
| 0 | 447 | fn all_data(&self) -> Self::AllDataIter<'_>; |
| 448 | } |