src/seminorms.rs

Thu, 26 Feb 2026 13:05:07 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 26 Feb 2026 13:05:07 -0500
branch
dev
changeset 66
fe47ad484deb
parent 61
4f468d35fa29
permissions
-rw-r--r--

Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.

0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*! This module implements the convolution operators $𝒟$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 The principal data type of the module is [`ConvolutionOp`] and the main abstraction
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 the trait [`DiscreteMeasureOp`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 */
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
7 use crate::measures::{DeltaMeasure, DiscreteMeasure, Radon, SpikeIter, RNDM};
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
8 use alg_tools::bisection_tree::*;
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: 54
diff changeset
9 use alg_tools::bounds::Bounded;
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: 54
diff changeset
10 use alg_tools::error::DynResult;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
11 use alg_tools::instance::Instance;
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
12 use alg_tools::iter::{FilterMapX, Mappable};
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
13 use alg_tools::linops::{BoundedLinear, Linear, Mapping};
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 use alg_tools::loc::Loc;
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 use alg_tools::mapping::RealMapping;
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 use alg_tools::nalgebra_support::ToNalgebraRealField;
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: 54
diff changeset
17 use alg_tools::norms::{Linfinity, Norm, NormExponent};
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
18 use alg_tools::sets::Cube;
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
19 use alg_tools::types::*;
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
20 use itertools::Itertools;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 use nalgebra::DMatrix;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
22 use std::iter::Zip;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 use std::marker::PhantomData;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
24 use std::ops::RangeFrom;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 /// Abstraction for operators $𝒟 ∈ 𝕃(𝒵(Ω); C_c(Ω))$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 ///
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 /// Here $𝒵(Ω) ⊂ ℳ(Ω)$ is the space of sums of delta measures, presented by [`DiscreteMeasure`].
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
29 pub trait DiscreteMeasureOp<Domain, F>:
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
30 BoundedLinear<DiscreteMeasure<Domain, F>, Radon, Linfinity, F>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
31 where
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
32 F: Float + ToNalgebraRealField,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
33 Domain: 'static + Clone + PartialEq,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
34 {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 /// The output type of [`Self::preapply`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 type PreCodomain;
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 /// Creates a finite-dimensional presentatin of the operator restricted to a fixed support.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 ///
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 /// <p>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 /// This returns the matrix $C_*𝒟C$, where $C ∈ 𝕃(ℝ^n; 𝒵(Ω))$, $Ca = ∑_{i=1}^n α_i δ_{x_i}$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 /// for a $x_1, …, x_n$ the coordinates given by the iterator `I`, and $a=(α_1,…,α_n)$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43 /// Here $C_* ∈ 𝕃(C_c(Ω); ℝ^n) $ stands for the preadjoint.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 /// </p>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
45 fn findim_matrix<'a, I>(&self, points: I) -> DMatrix<F::MixedType>
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
46 where
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
47 I: ExactSizeIterator<Item = &'a Domain> + Clone;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
49 /// [`Mapping`] that typically returns an uninitialised [`PreBTFN`]
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 /// instead of a full [`BTFN`].
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
51 fn preapply(&self, μ: DiscreteMeasure<Domain, F>) -> Self::PreCodomain;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 // Blanket implementation of a measure as a linear functional over a predual
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
55 // (that by assumption is a linear functional over a measure).
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56 /*impl<F, Domain, Predual> Linear<Predual>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57 for DiscreteMeasure<Domain, F>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 where F : Float + ToNalgebraRealField,
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
59 Predual : Linear<DiscreteMeasure<Domain, F>, Codomain=F> {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 type Codomain = F;
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 #[inline]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 fn apply(&self, ω : &Predual) -> F {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 ω.apply(self)
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 }*/
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68 //
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 // Convolutions for discrete measures
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 //
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 /// A trait alias for simple convolution kernels.
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: 54
diff changeset
73 pub trait SimpleConvolutionKernel<const N: usize, F: Float = f64>:
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: 54
diff changeset
74 RealMapping<N, F> + Support<N, F> + Bounded<F> + Clone + 'static
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
75 {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
76 }
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77
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: 54
diff changeset
78 impl<T, F: Float, const N: usize> SimpleConvolutionKernel<N, F> for T where
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: 54
diff changeset
79 T: RealMapping<N, F> + Support<N, F> + Bounded<F> + Clone + 'static
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
80 {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
81 }
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
82
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
83 /// [`SupportGenerator`] for [`ConvolutionOp`].
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
84 #[derive(Clone, Debug)]
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: 54
diff changeset
85 pub struct ConvolutionSupportGenerator<K, const N: usize, F: Float = f64>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
86 where
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: 54
diff changeset
87 K: SimpleConvolutionKernel<N, F>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
88 {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
89 kernel: K,
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: 54
diff changeset
90 centres: RNDM<N, F>,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
91 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
92
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: 54
diff changeset
93 impl<F: Float, K, const N: usize> ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
94 where
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: 54
diff changeset
95 K: SimpleConvolutionKernel<N, F>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
96 {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
97 /// Construct the convolution kernel corresponding to `δ`, i.e., one centered at `δ.x` and
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
98 /// weighted by `δ.α`.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99 #[inline]
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
100 fn construct_kernel<'a>(
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
101 &'a self,
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: 54
diff changeset
102 δ: &'a DeltaMeasure<Loc<N, F>, 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: 54
diff changeset
103 ) -> Weighted<Shift<K, N, F>, F> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
104 self.kernel.clone().shift(δ.x).weigh(δ.α)
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
106
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
107 /// This is a helper method for the implementation of [`ConvolutionSupportGenerator::all_data`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 /// It filters out `δ` with zero weight, and otherwise returns the corresponding convolution
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 /// kernel. The `id` is passed through as-is.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110 #[inline]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111 fn construct_kernel_and_id_filtered<'a>(
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
112 &'a self,
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: 54
diff changeset
113 (id, δ): (usize, &'a DeltaMeasure<Loc<N, F>, 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: 54
diff changeset
114 ) -> Option<(usize, Weighted<Shift<K, N, F>, F>)> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 (δ.α != F::ZERO).then(|| (id.into(), self.construct_kernel(δ)))
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
116 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
118
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: 54
diff changeset
119 impl<F: Float, K, const N: usize> SupportGenerator<N, F> for ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
120 where
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: 54
diff changeset
121 K: SimpleConvolutionKernel<N, F>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
122 {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
123 type Id = usize;
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: 54
diff changeset
124 type SupportType = Weighted<Shift<K, N, F>, F>;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
125 type AllDataIter<'a> = FilterMapX<
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
126 'a,
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: 54
diff changeset
127 Zip<RangeFrom<usize>, SpikeIter<'a, Loc<N, F>, F>>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
128 Self,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
129 (Self::Id, Self::SupportType),
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
130 >;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
131
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
132 #[inline]
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
133 fn support_for(&self, d: Self::Id) -> Self::SupportType {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
134 self.construct_kernel(&self.centres[d])
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
136
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
137 #[inline]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 fn support_count(&self) -> usize {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
139 self.centres.len()
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
140 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
142 #[inline]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
143 fn all_data(&self) -> Self::AllDataIter<'_> {
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
144 (0..)
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
145 .zip(self.centres.iter_spikes())
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
146 .filter_mapX(self, Self::construct_kernel_and_id_filtered)
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
147 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
148 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
149
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
150 /// Representation of a convolution operator $𝒟$.
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
151 #[derive(Clone, Debug)]
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
152 pub struct ConvolutionOp<F, K, BT, const N: usize>
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
153 where
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
154 F: Float + ToNalgebraRealField,
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: 54
diff changeset
155 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
156 K: SimpleConvolutionKernel<N, F>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
157 {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
158 /// Depth of the [`BT`] bisection tree for the outputs [`Mapping::apply`].
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
159 depth: BT::Depth,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
160 /// Domain of the [`BT`] bisection tree for the outputs [`Mapping::apply`].
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: 54
diff changeset
161 domain: Cube<N, F>,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
162 /// The convolution kernel
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
163 kernel: K,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
164 _phantoms: PhantomData<(F, BT)>,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
166
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
167 impl<F, K, BT, const N: usize> ConvolutionOp<F, K, BT, N>
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
168 where
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
169 F: Float + ToNalgebraRealField,
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: 54
diff changeset
170 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
171 K: SimpleConvolutionKernel<N, F>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
172 {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
173 /// Creates a new convolution operator $𝒟$ with `kernel` on `domain`.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
174 ///
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
175 /// The output of [`Mapping::apply`] is a [`BT`] of given `depth`.
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: 54
diff changeset
176 pub fn new(depth: BT::Depth, domain: Cube<N, F>, kernel: K) -> Self {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
177 ConvolutionOp {
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
178 depth: depth,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
179 domain: domain,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
180 kernel: kernel,
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
181 _phantoms: PhantomData,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
182 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
183 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
184
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
185 /// Returns the support generator for this convolution operator.
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: 54
diff changeset
186 fn support_generator(&self, μ: RNDM<N, F>) -> ConvolutionSupportGenerator<K, N, F> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
187 // TODO: can we avoid cloning μ?
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
188 ConvolutionSupportGenerator {
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
189 kernel: self.kernel.clone(),
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
190 centres: μ,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
191 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
192 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
193
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
194 /// Returns a reference to the kernel of this convolution operator.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
195 pub fn kernel(&self) -> &K {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 &self.kernel
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
197 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
198 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
199
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: 54
diff changeset
200 impl<F, K, BT, const N: usize> Mapping<RNDM<N, F>> for ConvolutionOp<F, K, BT, N>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
201 where
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
202 F: Float + ToNalgebraRealField,
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: 54
diff changeset
203 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
204 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
205 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
206 {
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: 54
diff changeset
207 type Codomain = BTFN<F, ConvolutionSupportGenerator<K, N, F>, BT, N>;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
208
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
209 fn apply<I>(&self, μ: I) -> Self::Codomain
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
210 where
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: 54
diff changeset
211 I: Instance<RNDM<N, F>>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
212 {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
213 let g = self.support_generator(μ.own());
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
214 BTFN::construct(self.domain.clone(), self.depth, g)
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
215 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
216 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
217
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
218 /// [`ConvolutionOp`]s as linear operators over [`DiscreteMeasure`]s.
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: 54
diff changeset
219 impl<F, K, BT, const N: usize> Linear<RNDM<N, F>> for ConvolutionOp<F, K, BT, N>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
220 where
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
221 F: Float + ToNalgebraRealField,
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: 54
diff changeset
222 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
223 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
224 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
225 {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
226 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
227
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: 54
diff changeset
228 impl<F, K, BT, const N: usize> BoundedLinear<RNDM<N, F>, Radon, Linfinity, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
229 for ConvolutionOp<F, K, BT, N>
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
230 where
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
231 F: Float + ToNalgebraRealField,
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: 54
diff changeset
232 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
233 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
234 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
235 {
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: 54
diff changeset
236 fn opnorm_bound(&self, _: Radon, _: Linfinity) -> DynResult<F> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
237 // With μ = ∑_i α_i δ_{x_i}, we have
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
238 // |𝒟μ|_∞
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
239 // = sup_z |∑_i α_i φ(z - x_i)|
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
240 // ≤ sup_z ∑_i |α_i| |φ(z - x_i)|
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
241 // ≤ ∑_i |α_i| |φ|_∞
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
242 // = |μ|_ℳ |φ|_∞
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: 54
diff changeset
243 Ok(self.kernel.bounds().uniform())
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
244 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
245 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
246
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: 54
diff changeset
247 impl<'a, F, K, BT, const N: usize> NormExponent for &'a ConvolutionOp<F, K, BT, N>
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: 54
diff changeset
248 where
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: 54
diff changeset
249 F: Float + ToNalgebraRealField,
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: 54
diff changeset
250 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
251 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
252 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
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: 54
diff changeset
253 {
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: 54
diff changeset
254 }
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: 54
diff changeset
255
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: 54
diff changeset
256 impl<'a, F, K, BT, const N: usize> Norm<&'a ConvolutionOp<F, K, BT, N>, F> for RNDM<N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
257 where
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
258 F: Float + ToNalgebraRealField,
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: 54
diff changeset
259 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
260 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
261 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
262 {
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: 54
diff changeset
263 fn norm(&self, op𝒟: &'a ConvolutionOp<F, K, BT, N>) -> 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: 54
diff changeset
264 self.apply(op𝒟.apply(self)).sqrt()
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: 54
diff changeset
265 }
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: 54
diff changeset
266 }
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: 54
diff changeset
267
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: 54
diff changeset
268 impl<F, K, BT, const N: usize> DiscreteMeasureOp<Loc<N, F>, F> for ConvolutionOp<F, K, BT, N>
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: 54
diff changeset
269 where
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: 54
diff changeset
270 F: Float + ToNalgebraRealField,
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: 54
diff changeset
271 BT: BTImpl<N, F, Data = usize>,
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: 54
diff changeset
272 K: SimpleConvolutionKernel<N, 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: 54
diff changeset
273 Weighted<Shift<K, N, F>, F>: LocalAnalysis<F, BT::Agg, N>,
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: 54
diff changeset
274 {
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: 54
diff changeset
275 type PreCodomain = PreBTFN<F, ConvolutionSupportGenerator<K, N, F>, N>;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
276
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
277 fn findim_matrix<'a, I>(&self, points: I) -> DMatrix<F::MixedType>
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
278 where
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: 54
diff changeset
279 I: ExactSizeIterator<Item = &'a Loc<N, F>> + Clone,
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
280 {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
281 // TODO: Preliminary implementation. It be best to use sparse matrices or
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
282 // possibly explicit operators without matrices
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
283 let n = points.len();
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
284 let points_clone = points.clone();
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
285 let pairs = points.cartesian_product(points_clone);
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
286 let kernel = &self.kernel;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
287 let values = pairs.map(|(x, y)| kernel.apply(y - x).to_nalgebra_mixed());
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
288 DMatrix::from_iterator(n, n, values)
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
289 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
290
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
291 /// A version of [`Mapping::apply`] that does not instantiate the [`BTFN`] codomain with
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
292 /// a bisection tree, instead returning a [`PreBTFN`]. This can improve performance when
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
293 /// the output is to be added as the right-hand-side operand to a proper BTFN.
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: 54
diff changeset
294 fn preapply(&self, μ: RNDM<N, F>) -> Self::PreCodomain {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
295 BTFN::new_pre(self.support_generator(μ))
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
296 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
297 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
298
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
299 /// Generates an scalar operation (e.g. [`std::ops::Mul`], [`std::ops::Div`])
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
300 /// for [`ConvolutionSupportGenerator`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
301 macro_rules! make_convolutionsupportgenerator_scalarop_rhs {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
302 ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => {
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: 54
diff changeset
303 impl<F: Float, K: SimpleConvolutionKernel<N, F>, const N: usize> std::ops::$trait_assign<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: 54
diff changeset
304 for ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
305 {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
306 fn $fn_assign(&mut self, t: F) {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
307 self.centres.$fn_assign(t);
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
308 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
309 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
310
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: 54
diff changeset
311 impl<F: Float, K: SimpleConvolutionKernel<N, F>, const N: usize> std::ops::$trait<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: 54
diff changeset
312 for ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
313 {
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: 54
diff changeset
314 type Output = ConvolutionSupportGenerator<K, N, F>;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
315 fn $fn(mut self, t: F) -> Self::Output {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
316 std::ops::$trait_assign::$fn_assign(&mut self.centres, t);
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
317 self
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
318 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
319 }
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: 54
diff changeset
320 impl<'a, F: Float, K: SimpleConvolutionKernel<N, F>, const N: usize> std::ops::$trait<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: 54
diff changeset
321 for &'a ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
322 {
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: 54
diff changeset
323 type Output = ConvolutionSupportGenerator<K, N, F>;
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
324 fn $fn(self, t: F) -> Self::Output {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
325 ConvolutionSupportGenerator {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
326 kernel: self.kernel.clone(),
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
327 centres: (&self.centres).$fn(t),
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
328 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
329 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
330 }
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
331 };
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
332 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
333
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
334 make_convolutionsupportgenerator_scalarop_rhs!(Mul, mul, MulAssign, mul_assign);
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
335 make_convolutionsupportgenerator_scalarop_rhs!(Div, div, DivAssign, div_assign);
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
336
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
337 /// Generates an unary operation (e.g. [`std::ops::Neg`]) for [`ConvolutionSupportGenerator`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
338 macro_rules! make_convolutionsupportgenerator_unaryop {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
339 ($trait:ident, $fn:ident) => {
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: 54
diff changeset
340 impl<F: Float, K: SimpleConvolutionKernel<N, F>, const N: usize> std::ops::$trait
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: 54
diff changeset
341 for ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
342 {
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: 54
diff changeset
343 type Output = ConvolutionSupportGenerator<K, N, F>;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
344 fn $fn(mut self) -> Self::Output {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
345 self.centres = self.centres.$fn();
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
346 self
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
347 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
348 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
349
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: 54
diff changeset
350 impl<'a, F: Float, K: SimpleConvolutionKernel<N, F>, const N: usize> std::ops::$trait
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: 54
diff changeset
351 for &'a ConvolutionSupportGenerator<K, N, F>
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
352 {
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: 54
diff changeset
353 type Output = ConvolutionSupportGenerator<K, N, F>;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
354 fn $fn(self) -> Self::Output {
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
355 ConvolutionSupportGenerator {
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
356 kernel: self.kernel.clone(),
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
357 centres: (&self.centres).$fn(),
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
358 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
359 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
360 }
54
b3312eee105c Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
361 };
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
362 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
363
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
364 make_convolutionsupportgenerator_unaryop!(Neg, neg);

mercurial