src/kernels/linear.rs

Mon, 13 Apr 2026 22:29:26 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 13 Apr 2026 22:29:26 -0500
branch
dev
changeset 68
00d0881f89a6
parent 61
4f468d35fa29
permissions
-rw-r--r--

Automatic transport disabling after sufficient failures, for efficiency

35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 //! Implementation of the linear function
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
3 use alg_tools::bisection_tree::Support;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
4 use alg_tools::bounds::{Bounded, Bounds, GlobalAnalysis, LocalAnalysis};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
5 use alg_tools::loc::Loc;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
6 use alg_tools::norms::*;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
7 use alg_tools::sets::Cube;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
8 use alg_tools::types::*;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 use numeric_literals::replace_float_literals;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 use serde::Serialize;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
11
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
12 use alg_tools::euclidean::Euclidean;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
13 use alg_tools::mapping::{Instance, Mapping};
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 use alg_tools::maputil::array_init;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 /// Representation of the hat function $f(x)=1-\\|x\\|\_1/ε$ of `width` $ε$ on $ℝ^N$.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
17 #[derive(Copy, Clone, Serialize, Debug, Eq, PartialEq)]
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
18 pub struct Linear<const N: usize, F: Float = f64> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 /// The parameter $ε>0$.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
20 pub v: Loc<N, F>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
24 impl<F: Float, const N: usize> Mapping<Loc<N, F>> for Linear<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 type Codomain = F;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
28 fn apply<I: Instance<Loc<N, F>>>(&self, x: I) -> Self::Codomain {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 x.eval(|x| self.v.dot(x))
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
34 impl<'a, F: Float, const N: usize> Support<N, F> for Linear<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
36 fn support_hint(&self) -> Cube<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 array_init(|| [F::NEG_INFINITY, F::INFINITY]).into()
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
41 fn in_support(&self, _x: &Loc<N, F>) -> bool {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 true
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43 }
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
44
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
45 /*fn fully_in_support(&self, _cube : &Cube<F,N>) -> bool {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 todo!("Not implemented, but not used at the moment")
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47 }*/
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
50 fn bisection_hint(&self, _cube: &Cube<N, F>) -> [Option<F>; N] {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 [None; N]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
55 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
56 impl<'a, F: Float, const N: usize> GlobalAnalysis<F, Bounds<F>> for Linear<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57 #[inline]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 fn global_analysis(&self) -> Bounds<F> {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
59 Bounds(F::NEG_INFINITY, F::INFINITY)
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
63 impl<'a, F: Float, const N: usize> LocalAnalysis<F, Bounds<F>, N> for Linear<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
65 fn local_analysis(&self, cube: &Cube<N, F>) -> Bounds<F> {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
66 let (lower, upper) = cube
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
67 .iter_corners()
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
68 .map(|x| self.apply(x))
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
69 .fold((F::INFINITY, F::NEG_INFINITY), |(lower, upper), v| {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
70 (lower.min(v), upper.max(v))
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
71 });
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 Bounds(lower, upper)
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
74 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
76 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
77 impl<'a, F: Float, const N: usize> Norm<Linfinity, F> for Linear<N, F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
78 #[inline]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
79 fn norm(&self, _: Linfinity) -> F {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
80 self.bounds().upper()
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
81 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
82 }

mercurial