src/bisection_tree/support.rs

Wed, 03 Sep 2025 20:19:41 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 03 Sep 2025 20:19:41 -0500
branch
dev
changeset 171
fa8df5a14486
parent 151
402d717bb5c0
permissions
-rw-r--r--

decompose

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

mercurial