Mon, 13 Apr 2026 22:29:26 -0500
Automatic transport disabling after sufficient failures, for efficiency
| 35 | 1 | //! Implementation of the linear function |
| 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 | 9 | use numeric_literals::replace_float_literals; |
| 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 | 14 | use alg_tools::maputil::array_init; |
| 15 | ||
| 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 | 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 | 21 | } |
| 22 | ||
| 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 | 25 | type Codomain = F; |
| 26 | ||
| 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 | 29 | x.eval(|x| self.v.dot(x)) |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 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 | 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 | 37 | array_init(|| [F::NEG_INFINITY, F::INFINITY]).into() |
| 38 | } | |
| 39 | ||
| 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 | 42 | true |
| 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 | 45 | /*fn fully_in_support(&self, _cube : &Cube<F,N>) -> bool { |
| 46 | todo!("Not implemented, but not used at the moment") | |
| 47 | }*/ | |
| 48 | ||
| 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 | 51 | [None; N] |
| 52 | } | |
| 53 | } | |
| 54 | ||
| 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 | 57 | #[inline] |
| 58 | fn global_analysis(&self) -> Bounds<F> { | |
| 59 | Bounds(F::NEG_INFINITY, F::INFINITY) | |
| 60 | } | |
| 61 | } | |
| 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 | 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 | 72 | Bounds(lower, upper) |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 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 | 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 | 80 | self.bounds().upper() |
| 81 | } | |
| 82 | } |