src/forward_pdps.rs

changeset 93
8f1e57821d76
parent 91
47d495348e38
child 95
d9318317ccac
--- a/src/forward_pdps.rs	Tue Aug 04 20:11:10 2026 -0500
+++ b/src/forward_pdps.rs	Thu Aug 06 11:14:15 2026 -0500
@@ -6,7 +6,7 @@
 use crate::domain::{AdmissibleDomain, FullSpace};
 use crate::fb::*;
 use crate::measures::merging::SpikeMerging;
-use crate::measures::{DiscreteMeasure, RNDM};
+use crate::measures::DiscreteMeasure;
 use crate::plot::Plotter;
 use crate::prox_penalty::{ProxPenalty, StepLengthBoundPair};
 use crate::regularisation::RegTerm;
@@ -16,8 +16,8 @@
 use alg_tools::error::DynResult;
 use alg_tools::euclidean::ClosedEuclidean;
 use alg_tools::iterate::AlgIteratorFactory;
-use alg_tools::linops::{BoundedLinear, IdOp, SimplyAdjointable, ZeroOp, AXPY, GEMV};
-use alg_tools::mapping::{DifferentiableMapping, DifferentiableRealMapping, Instance};
+use alg_tools::linops::{BoundedLinear, IdOp, SimplyAdjointable, Space, ZeroOp, AXPY, GEMV};
+use alg_tools::mapping::{DifferentiableMapping, Instance};
 use alg_tools::nalgebra_support::ToNalgebraRealField;
 use alg_tools::norms::L2;
 use anyhow::ensure;
@@ -48,7 +48,7 @@
     }
 }
 
-type MeasureZ<F, Z, const N: usize> = Pair<RNDM<N, F>, Z>;
+type MeasureZ<F, Z, U> = Pair<DiscreteMeasure<U, F>, Z>;
 
 /// Iteratively solve the pointsource localisation with an additional variable
 /// using primal-dual proximal splitting with a forward step.
@@ -89,6 +89,7 @@
 #[replace_float_literals(F::cast_from(literal))]
 pub fn pointsource_forward_pdps_pair_dom<
     F,
+    U,
     I,
     S,
     Dat,
@@ -100,7 +101,6 @@
     /*KOpM, */ KOpZ,
     H,
     Plot,
-    const N: usize,
 >(
     f: &Dat,
     reg: &Reg,
@@ -108,22 +108,23 @@
     config: &ForwardPDPSConfig<F>,
     iterator: I,
     mut plotter: Plot,
-    (μ0, mut z, mut y): (Option<RNDM<N, F>>, Z, Y),
+    (μ0, mut z, mut y): (Option<DiscreteMeasure<U, F>>, Z, Y),
     //opKμ : KOpM,
     opKz: &KOpZ,
     fnR: &R,
     fnH: &H,
-    domain: &mut impl AdmissibleDomain<Loc<N, F>>,
-) -> DynResult<MeasureZ<F, Z, N>>
+    domain: &mut impl AdmissibleDomain<U>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
+    U: Space + Clone,
     F: Float + ToNalgebraRealField,
     I: AlgIteratorFactory<IterInfo<F>>,
-    Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
+    Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
     //Pair<S, Z>: ClosedMul<F>, // Doesn't really need to be closed, if make this signature more complex…
-    S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
-    RNDM<N, F>: SpikeMerging<F>,
-    Reg: RegTerm<Loc<N, F>, F>,
-    P: ProxPenalty<Loc<N, F>, S, Reg, F>,
+    S: ClosedMul<F>,
+    DiscreteMeasure<U, F>: SpikeMerging<F>,
+    Reg: RegTerm<U, F>,
+    P: ProxPenalty<U, S, Reg, F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y>
         + GEMV<F, Z, Y>
@@ -136,7 +137,7 @@
     R: Prox<Z, Codomain = F>,
     H: Conjugable<Y, F, Codomain = F>,
     for<'b> H::Conjugate<'b>: Prox<Y>,
-    Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
+    Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>,
 {
     // Check parameters
     ensure!(
@@ -188,7 +189,7 @@
     let starH = fnH.conjugate();
 
     // Statistics
-    let full_stats = |μ: &RNDM<N, F>, z: &Z, ε, stats| IterInfo {
+    let full_stats = |μ: &DiscreteMeasure<U, F>, z: &Z, ε, stats| IterInfo {
         value: f.apply(Pair(μ, z))
             + fnR.apply(z)
             + reg.apply(μ)
@@ -250,7 +251,7 @@
                 ε,
                 ins,
                 &reg,
-                Some(|μ̃: &RNDM<N, F>| f.apply(Pair(μ̃, &z)) + reg.apply(μ̃)),
+                Some(|μ̃: &DiscreteMeasure<U, F>| f.apply(Pair(μ̃, &z)) + reg.apply(μ̃)),
             );
             // Prune. Do not prune new insertions on first round.
             stats.pruned += prune_with_stats(&mut μ, μ_base_len);
@@ -310,7 +311,7 @@
         ε = tolerance.update(ε, iter);
     }
 
-    let fit = |μ̃: &RNDM<N, F>| {
+    let fit = |μ̃: &DiscreteMeasure<U, F>| {
         f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/
         + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z))
         + reg.apply(μ̃)
@@ -324,6 +325,7 @@
 #[deprecated]
 pub fn pointsource_forward_pdps_pair<
     F,
+    U,
     I,
     S,
     Dat,
@@ -335,7 +337,6 @@
     /*KOpM, */ KOpZ,
     H,
     Plot,
-    const N: usize,
 >(
     f: &Dat,
     reg: &Reg,
@@ -343,21 +344,22 @@
     config: &ForwardPDPSConfig<F>,
     iterator: I,
     plotter: Plot,
-    init: (Option<RNDM<N, F>>, Z, Y),
+    init: (Option<DiscreteMeasure<U, F>>, Z, Y),
     //opKμ : KOpM,
     opKz: &KOpZ,
     fnR: &R,
     fnH: &H,
-) -> DynResult<MeasureZ<F, Z, N>>
+) -> DynResult<MeasureZ<F, Z, U>>
 where
+    U: Space + Clone,
     F: Float + ToNalgebraRealField,
     I: AlgIteratorFactory<IterInfo<F>>,
-    Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
+    Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
     //Pair<S, Z>: ClosedMul<F>, // Doesn't really need to be closed, if make this signature more complex…
-    S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
-    RNDM<N, F>: SpikeMerging<F>,
-    Reg: RegTerm<Loc<N, F>, F>,
-    P: ProxPenalty<Loc<N, F>, S, Reg, F>,
+    S: ClosedMul<F>,
+    DiscreteMeasure<U, F>: SpikeMerging<F>,
+    Reg: RegTerm<U, F>,
+    P: ProxPenalty<U, S, Reg, F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y>
         + GEMV<F, Z, Y>
@@ -370,7 +372,7 @@
     R: Prox<Z, Codomain = F>,
     H: Conjugable<Y, F, Codomain = F>,
     for<'b> H::Conjugate<'b>: Prox<Y>,
-    Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
+    Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>,
 {
     pointsource_forward_pdps_pair_dom(
         f,
@@ -393,31 +395,32 @@
 /// The implementation uses [`pointsource_forward_pdps_pair`] with appropriate dummy
 /// variables, operators, and functions.
 #[replace_float_literals(F::cast_from(literal))]
-pub fn pointsource_fb_pair_dom<F, I, S, Dat, Reg, P, Z, R, Plot, const N: usize>(
+pub fn pointsource_fb_pair_dom<F, U, I, S, Dat, Reg, P, Z, R, Plot>(
     f: &Dat,
     reg: &Reg,
     prox_penalty: &P,
     config: &FBConfig<F>,
     iterator: I,
     plotter: Plot,
-    (μ0, z): (Option<RNDM<N, F>>, Z),
+    (μ0, z): (Option<DiscreteMeasure<U, F>>, Z),
     //opKμ : KOpM,
     fnR: &R,
-    domain: &mut impl AdmissibleDomain<Loc<N, F>>,
-) -> DynResult<MeasureZ<F, Z, N>>
+    domain: &mut impl AdmissibleDomain<U>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
+    U: Space + Clone,
     F: Float + ToNalgebraRealField,
     I: AlgIteratorFactory<IterInfo<F>>,
-    Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
-    S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
-    RNDM<N, F>: SpikeMerging<F>,
-    Reg: RegTerm<Loc<N, F>, F>,
-    P: ProxPenalty<Loc<N, F>, S, Reg, F>,
+    Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
+    S: ClosedMul<F>,
+    DiscreteMeasure<U, F>: SpikeMerging<F>,
+    Reg: RegTerm<U, F>,
+    P: ProxPenalty<U, S, Reg, F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     Z: ClosedEuclidean<F> + AXPY<Field = F> + Clone,
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = F>,
-    Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
+    Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>,
     // We should not need to explicitly require this:
     for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>,
 {
@@ -445,30 +448,31 @@
 
 #[deprecated]
 #[replace_float_literals(F::cast_from(literal))]
-pub fn pointsource_fb_pair<F, I, S, Dat, Reg, P, Z, R, Plot, const N: usize>(
+pub fn pointsource_fb_pair<F, U, I, S, Dat, Reg, P, Z, R, Plot>(
     f: &Dat,
     reg: &Reg,
     prox_penalty: &P,
     config: &FBConfig<F>,
     iterator: I,
     plotter: Plot,
-    init: (Option<RNDM<N, F>>, Z),
+    init: (Option<DiscreteMeasure<U, F>>, Z),
     //opKμ : KOpM,
     fnR: &R,
-) -> DynResult<MeasureZ<F, Z, N>>
+) -> DynResult<MeasureZ<F, Z, U>>
 where
+    U: Space + Clone,
     F: Float + ToNalgebraRealField,
     I: AlgIteratorFactory<IterInfo<F>>,
-    Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
-    S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
-    RNDM<N, F>: SpikeMerging<F>,
-    Reg: RegTerm<Loc<N, F>, F>,
-    P: ProxPenalty<Loc<N, F>, S, Reg, F>,
+    Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
+    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F>,
+    DiscreteMeasure<U, F>: SpikeMerging<F>,
+    Reg: RegTerm<U, F>,
+    P: ProxPenalty<U, S, Reg, F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     Z: ClosedEuclidean<F> + AXPY<Field = F> + Clone,
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = F>,
-    Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
+    Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>,
     // We should not need to explicitly require this:
     for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>,
 {

mercurial