attempt to reduce trait bounds

Thu, 06 Aug 2026 14:33:17 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 06 Aug 2026 14:33:17 -0500
changeset 96
5ba25d740dfc
parent 95
d9318317ccac
child 97
f91f382ba4ae

attempt to reduce trait bounds

src/forward_pdps.rs file | annotate | diff | comparison | revisions
src/run.rs file | annotate | diff | comparison | revisions
src/sliding_pdps.rs file | annotate | diff | comparison | revisions
--- a/src/forward_pdps.rs	Wed Aug 05 17:50:38 2026 -0500
+++ b/src/forward_pdps.rs	Thu Aug 06 14:33:17 2026 -0500
@@ -16,7 +16,10 @@
 use alg_tools::error::DynResult;
 use alg_tools::euclidean::ClosedEuclidean;
 use alg_tools::iterate::AlgIteratorFactory;
-use alg_tools::linops::{BoundedLinear, IdOp, SimplyAdjointable, Space, ZeroOp, AXPY, GEMV};
+use alg_tools::linops::{
+    BoundedLinear, IdOp, SimplyAdjointable, Space, StaticEuclideanOriginGenerator, ZeroOp, AXPY,
+    GEMV,
+};
 use alg_tools::mapping::{DifferentiableMapping, Instance};
 use alg_tools::nalgebra_support::ToNalgebraRealField;
 use alg_tools::norms::L2;
@@ -116,20 +119,19 @@
     domain: &mut impl AdmissibleDomain<U>,
 ) -> DynResult<MeasureZ<F, Z, U>>
 where
+    F: Float + ToNalgebraRealField,
     U: Space + Clone,
-    F: Float + ToNalgebraRealField,
     I: AlgIteratorFactory<IterInfo<F>>,
     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: ClosedMul<F>,
+    for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     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>
-        + SimplyAdjointable<Z, Y, Codomain = Y, AdjointCodomain = Z>,
-    KOpZ::SimpleAdjoint: GEMV<F, Y, Z>,
+        + GEMV<F, Z>
+        + SimplyAdjointable<Z, Y, AdjointCodomain = Z>,
+    KOpZ::SimpleAdjoint: GEMV<F, Y>,
     Y: ClosedEuclidean<F>,
     for<'b> &'b Y: Instance<Y>,
     Z: ClosedEuclidean<F> + AXPY,
@@ -347,20 +349,21 @@
     fnH: &H,
 ) -> DynResult<MeasureZ<F, Z, U>>
 where
+    F: Float + ToNalgebraRealField,
     U: Space + Clone,
-    F: Float + ToNalgebraRealField,
+    //for<'a> &'a U: Instance<U>,
     I: AlgIteratorFactory<IterInfo<F>>,
     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: ClosedMul<F>,
+    for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
+    //Pair<S, Z>: 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>
-        + SimplyAdjointable<Z, Y, Codomain = Y, AdjointCodomain = Z>,
-    KOpZ::SimpleAdjoint: GEMV<F, Y, Z>,
+        + GEMV<F, Z>
+        + SimplyAdjointable<Z, Y, AdjointCodomain = Z>,
+    KOpZ::SimpleAdjoint: GEMV<F, Y>,
     Y: ClosedEuclidean<F>,
     for<'b> &'b Y: Instance<Y>,
     Z: ClosedEuclidean<F> + AXPY,
@@ -404,8 +407,9 @@
     domain: &mut impl AdmissibleDomain<U>,
 ) -> DynResult<MeasureZ<F, Z, U>>
 where
+    F: Float + ToNalgebraRealField,
     U: Space + Clone,
-    F: Float + ToNalgebraRealField,
+    for<'a> &'a U: Instance<U>,
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
     S: ClosedMul<F>,
@@ -413,14 +417,13 @@
     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,
+    Z: ClosedEuclidean<F> + AXPY + Clone,
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
 {
-    let opKz = ZeroOp::new_dualisable(Loc([]), z.dual_origin());
+    let opKz: ZeroOp<Z, Loc<0, F>, _, _, F> =
+        ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, z.dual_origin());
     let fnH = Zero::new();
     // Convert config. We don't implement From (that could be done with the o2o crate), as σd0
     // needs to be chosen in a general case; for the problem of this fucntion, anything is valid.
@@ -456,21 +459,20 @@
     fnR: &R,
 ) -> DynResult<MeasureZ<F, Z, U>>
 where
+    F: Float + ToNalgebraRealField,
     U: Space + Clone,
-    F: Float + ToNalgebraRealField,
+    for<'a> &'a U: Instance<U>,
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<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>,
-    Z: ClosedEuclidean<F> + AXPY<Field = F> + Clone,
+    Z: ClosedEuclidean<F> + AXPY + Clone,
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
 {
     pointsource_fb_pair_dom(
         f,
--- a/src/run.rs	Wed Aug 05 17:50:38 2026 -0500
+++ b/src/run.rs	Thu Aug 06 14:33:17 2026 -0500
@@ -1412,8 +1412,8 @@
             (Option<DiscreteMeasure<U, F>>, Z, Y),
             String,
         ),
-    ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>,
-) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>
+    ) -> DynResult<MeasureZ<F, Z, U>>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
     F: Float + ToNalgebraRealField,
     U: Space + Clone + Dist<L2, F>,
@@ -1421,7 +1421,7 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     //Pair<S, Z>: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
@@ -1476,8 +1476,8 @@
             (Option<DiscreteMeasure<U, F>>, Z, Y),
             String,
         ),
-    ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>,
-) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>
+    ) -> DynResult<MeasureZ<F, Z, U>>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
     F: Float + ToNalgebraRealField,
     U: Space + Clone + Dist<L2, F>,
@@ -1485,7 +1485,7 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
     //Pair<S, Z>: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
@@ -1563,8 +1563,8 @@
             (Option<DiscreteMeasure<U, F>>, Z),
             String,
         ),
-    ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>,
-) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>
+    ) -> DynResult<MeasureZ<F, Z, U>>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
     F: Float + ToNalgebraRealField,
     U: Space + Clone + Dist<L2, F>,
@@ -1572,7 +1572,7 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
     Reg: SlidingRegTerm<U, F>,
     P: TransportProxPenalty<U, S, Reg, F>,
@@ -1581,8 +1581,6 @@
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
 {
     run_fb_pair_dom(f, reg, prox_penalty, fnR, init, &mut FullSpace, cont)
 }
@@ -1608,8 +1606,8 @@
             (Option<DiscreteMeasure<U, F>>, Z),
             String,
         ),
-    ) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>,
-) -> DynResult<Pair<DiscreteMeasure<U, F>, Z>>
+    ) -> DynResult<MeasureZ<F, Z, U>>,
+) -> DynResult<MeasureZ<F, Z, U>>
 where
     F: Float + ToNalgebraRealField,
     U: Space + Clone + Dist<L2, F>,
@@ -1617,7 +1615,7 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
     Reg: SlidingRegTerm<U, F>,
     P: TransportProxPenalty<U, S, Reg, F>,
@@ -1626,8 +1624,6 @@
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
 {
     let pt = P::prox_type();
 
--- a/src/sliding_pdps.rs	Wed Aug 05 17:50:38 2026 -0500
+++ b/src/sliding_pdps.rs	Thu Aug 06 14:33:17 2026 -0500
@@ -108,9 +108,8 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
-    //Pair<S, Z>: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
     Reg: SlidingRegTerm<U, F>,
     P: TransportProxPenalty<U, S, Reg, F>,
@@ -420,7 +419,7 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
     Reg: SlidingRegTerm<U, F>,
     P: TransportProxPenalty<U, S, Reg, F>,
@@ -429,15 +428,10 @@
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
-    // Loc<0, F>: StaticEuclidean<Field = F, PrincipalE = Loc<0, F>>
-    //     + Instance<Loc<0, F>>
-    //     + VectorSpace<Field = F>,
 {
     let opKz: ZeroOp<Z, Loc<0, F>, _, _, F> =
         ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, z.dual_origin());
-    let fnH = Zero::new();
+    let fnH = Zero::<Loc<0, F>, F>::new();
     // Convert config. We don't implement From (that could be done with the o2o crate), as σd0
     // needs to be chosen in a general case; for the problem of this fucntion, anything is valid.
     let &SlidingFBConfig { τ0, σp0, insertion, transport, guess } = config;
@@ -495,22 +489,11 @@
     I: AlgIteratorFactory<IterInfo<F>>,
     Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>
         + BoundedCurvature<F>,
-    S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F> + MinMaxMapping<U, F>,
+    S: ClosedMul<F>,
     for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
-    //Pair<S, Z>: ClosedMul<F>,
     DiscreteMeasure<U, F>: SpikeMerging<F>,
     Reg: SlidingRegTerm<U, F>,
     P: TransportProxPenalty<U, S, Reg, F>,
-    // KOpM : Linear<DiscreteMeasure<U, F>, Codomain=Y>
-    //     + GEMV<F, DiscreteMeasure<U, F>>
-    //     + Preadjointable<
-    //         DiscreteMeasure<U, F>, Y,
-    //         PreadjointCodomain = S,
-    //     >
-    //     + TransportLipschitz<L2Squared, FloatType=F>
-    //     + AdjointProductBoundedBy<DiscreteMeasure<U, F>, 𝒟, FloatType=F>,
-    // for<'b> KOpM::Preadjoint<'b> : GEMV<F, Y>,
-    // Since Z is Hilbert, we may just as well use adjoints for K_z.
     KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y>
         + GEMV<F, Z>
         + SimplyAdjointable<Z, Y, AdjointCodomain = Z>,
@@ -569,11 +552,6 @@
     for<'b> &'b Z: Instance<Z>,
     R: Prox<Z, Codomain = 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>>,
-    // Loc<0, F>: StaticEuclidean<Field = F, PrincipalE = Loc<0, F>>
-    //     + Instance<Loc<0, F>>
-    //     + VectorSpace<Field = F>,
 {
     let opKz: ZeroOp<Z, Loc<0, F>, _, _, F> =
         ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, z.dual_origin());

mercurial