diff -r 848ecc05becf -r 05089fbc0310 src/linops.rs --- a/src/linops.rs Tue Dec 31 09:02:55 2024 -0500 +++ b/src/linops.rs Tue Dec 31 08:30:43 2024 -0500 @@ -6,10 +6,10 @@ use std::marker::PhantomData; use serde::Serialize; use crate::types::*; -pub use crate::mapping::{Mapping, Space}; +pub use crate::mapping::{Mapping, Space, Composition}; use crate::direct_product::Pair; use crate::instance::Instance; -use crate::norms::{NormExponent, PairNorm, L1, L2, Linfinity}; +use crate::norms::{NormExponent, PairNorm, L1, L2, Linfinity, Norm}; /// Trait for linear operators on `X`. pub trait Linear : Mapping @@ -58,7 +58,7 @@ pub trait BoundedLinear : Linear where F : Num, - X : Space, + X : Space + Norm, XExp : NormExponent, CodExp : NormExponent { @@ -152,7 +152,7 @@ impl BoundedLinear for IdOp where - X : Space + Clone, + X : Space + Clone + Norm, F : Num, E : NormExponent { @@ -173,6 +173,53 @@ fn preadjoint(&self) -> Self::Preadjoint<'_> { IdOp::new() } } + +impl Linear for Composition +where + X : Space, + T : Linear, + S : Linear +{ } + +impl GEMV for Composition +where + F : Num, + X : Space, + T : Linear, + S : GEMV, +{ + fn gemv>(&self, y : &mut Y, α : F, x : I, β : F) { + self.outer.gemv(y, α, self.inner.apply(x), β) + } + + /// Computes `y = Ax`, where `A` is `Self` + fn apply_mut>(&self, y : &mut Y, x : I){ + self.outer.apply_mut(y, self.inner.apply(x)) + } + + /// Computes `y += Ax`, where `A` is `Self` + fn apply_add>(&self, y : &mut Y, x : I){ + self.outer.apply_add(y, self.inner.apply(x)) + } +} + +impl BoundedLinear for Composition +where + F : Num, + X : Space + Norm, + Z : Space + Norm, + Xexp : NormExponent, + Yexp : NormExponent, + Zexp : NormExponent, + T : BoundedLinear, + S : BoundedLinear, +{ + fn opnorm_bound(&self, xexp : Xexp, yexp : Yexp) -> F { + let zexp = self.intermediate_norm_exponent; + self.outer.opnorm_bound(zexp, yexp) * self.inner.opnorm_bound(xexp, zexp) + } +} + /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$. pub struct RowOp(pub S, pub T); @@ -488,8 +535,8 @@ for RowOp where F : Float, - A : Space, - B : Space, + A : Space + Norm, + B : Space + Norm, S : BoundedLinear, T : BoundedLinear, S::Codomain : Add, @@ -516,7 +563,7 @@ for ColOp where F : Float, - A : Space, + A : Space + Norm, S : BoundedLinear, T : BoundedLinear, ExpA : NormExponent,