src/dataterm.rs

Thu, 26 Feb 2026 11:38:43 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 26 Feb 2026 11:38:43 -0500
branch
dev
changeset 61
4f468d35fa29
parent 35
b087e3eab191
permissions
-rw-r--r--

General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.

32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Basid definitions for data terms
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 */
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
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
5 //use numeric_literals::replace_float_literals;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
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
7 use alg_tools::convex::Norm222;
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::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
9 //use alg_tools::instance::{Instance, Space};
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
10 //use alg_tools::linops::GEMV;
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 use alg_tools::mapping::DataTerm;
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::norms::{NormMapping, L1};
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13
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
14 //use crate::types::*;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15
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
16 /*
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 /// Calculates the residual $Aμ-b$.
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 #[replace_float_literals(F::cast_from(literal))]
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 pub(crate) fn calculate_residual<
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 X: Space,
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
21 I: Instance<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
22 F: Float,
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
23 V: Euclidean<F> + Clone,
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 A: GEMV<F, X, Codomain = V>,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 >(
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
26 μ: I,
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
27 opA: &A,
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 b: &V,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 ) -> V {
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 let mut r = b.clone();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 opA.gemv(&mut r, 1.0, μ, -1.0);
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 r
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 /// Calculates the residual $A(μ+μ_delta)-b$.
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 #[replace_float_literals(F::cast_from(literal))]
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 pub(crate) fn calculate_residual2<
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
38 F: Float,
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
39 X: Space,
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
40 I: Instance<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
41 J: Instance<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
42 V: Euclidean<F> + Clone,
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
43 A: GEMV<F, X, Codomain = V>,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 >(
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
45 μ: I,
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
46 μ_delta: J,
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
47 opA: &A,
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
48 b: &V,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 ) -> V {
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 let mut r = b.clone();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 opA.gemv(&mut r, 1.0, μ, -1.0);
34
efa60bc4f743 Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
52 opA.gemv(&mut r, 1.0, μ_delta, 1.0);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 r
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 }
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
55 */
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56
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
57 pub type L1DataTerm<F, Domain, A> = DataTerm<F, Domain, A, NormMapping<F, L1>>;
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
58 pub type QuadraticDataTerm<F, Domain, A> = DataTerm<F, Domain, A, Norm222<F>>;

mercurial