| 5 use crate::direct_product::Pair; |
5 use crate::direct_product::Pair; |
| 6 use crate::error::DynResult; |
6 use crate::error::DynResult; |
| 7 use crate::euclidean::StaticEuclidean; |
7 use crate::euclidean::StaticEuclidean; |
| 8 use crate::instance::Instance; |
8 use crate::instance::Instance; |
| 9 pub use crate::mapping::{ClosedSpace, Composition, DifferentiableImpl, Mapping, Space}; |
9 pub use crate::mapping::{ClosedSpace, Composition, DifferentiableImpl, Mapping, Space}; |
| 10 use crate::norms::{HasDual, Linfinity, Norm, NormExponent, PairNorm, L1, L2}; |
10 use crate::norms::{HasDual, Linfinity, NormExponent, PairNorm, L1, L2}; |
| 11 use crate::types::*; |
11 use crate::types::*; |
| 12 use numeric_literals::replace_float_literals; |
12 use numeric_literals::replace_float_literals; |
| 13 use serde::Serialize; |
13 use serde::Serialize; |
| 14 use std::marker::PhantomData; |
14 use std::marker::PhantomData; |
| 15 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; |
15 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; |
| 126 |
126 |
| 127 /// Bounded linear operators |
127 /// Bounded linear operators |
| 128 pub trait BoundedLinear<X, XExp, CodExp, F = f64>: Linear<X> |
128 pub trait BoundedLinear<X, XExp, CodExp, F = f64>: Linear<X> |
| 129 where |
129 where |
| 130 F: Num, |
130 F: Num, |
| 131 X: Space + Norm<XExp, F>, |
131 X: Space, |
| 132 XExp: NormExponent, |
132 XExp: NormExponent, |
| 133 CodExp: NormExponent, |
133 CodExp: NormExponent, |
| 134 { |
134 { |
| 135 /// A bound on the operator norm $\|A\|$ for the linear operator $A$=`self`. |
135 /// A bound on the operator norm $\|A\|$ for the linear operator $A$=`self`. |
| 136 /// This is not expected to be the norm, just any bound on it that can be |
136 /// This is not expected to be the norm, just any bound on it that can be |
| 249 } |
249 } |
| 250 } |
250 } |
| 251 |
251 |
| 252 impl<F, X, E> BoundedLinear<X, E, E, F> for IdOp<X> |
252 impl<F, X, E> BoundedLinear<X, E, E, F> for IdOp<X> |
| 253 where |
253 where |
| 254 X: Space + Clone + Norm<E, F>, |
254 X: Space + Clone, |
| 255 F: Num, |
255 F: Num, |
| 256 E: NormExponent, |
256 E: NormExponent, |
| 257 { |
257 { |
| 258 fn opnorm_bound(&self, _xexp: E, _codexp: E) -> DynResult<F> { |
258 fn opnorm_bound(&self, _xexp: E, _codexp: E) -> DynResult<F> { |
| 259 Ok(F::ONE) |
259 Ok(F::ONE) |
| 325 } |
325 } |
| 326 |
326 |
| 327 impl<X, F, E1, E2> BoundedLinear<X, E1, E2, F> for SimpleZeroOp |
327 impl<X, F, E1, E2> BoundedLinear<X, E1, E2, F> for SimpleZeroOp |
| 328 where |
328 where |
| 329 F: Num, |
329 F: Num, |
| 330 X: VectorSpace<Field = F> + Norm<E1, F>, |
330 X: VectorSpace<Field = F>, |
| 331 E1: NormExponent, |
331 E1: NormExponent, |
| 332 E2: NormExponent, |
332 E2: NormExponent, |
| 333 { |
333 { |
| 334 fn opnorm_bound(&self, _xexp: E1, _codexp: E2) -> DynResult<F> { |
334 fn opnorm_bound(&self, _xexp: E1, _codexp: E2) -> DynResult<F> { |
| 335 Ok(F::ZERO) |
335 Ok(F::ZERO) |
| 504 } |
504 } |
| 505 } |
505 } |
| 506 |
506 |
| 507 impl<X, Y, OY, O, F, E1, E2> BoundedLinear<X, E1, E2, F> for ZeroOp<X, Y, OY, O, F> |
507 impl<X, Y, OY, O, F, E1, E2> BoundedLinear<X, E1, E2, F> for ZeroOp<X, Y, OY, O, F> |
| 508 where |
508 where |
| 509 X: Space + Instance<X> + Norm<E1, F>, |
509 X: Space + Instance<X>, |
| 510 Y: VectorSpace<Field = F>, |
510 Y: VectorSpace<Field = F>, |
| 511 Y::PrincipalV: Clone, |
511 Y::PrincipalV: Clone, |
| 512 F: Float, |
512 F: Float, |
| 513 E1: NormExponent, |
513 E1: NormExponent, |
| 514 E2: NormExponent, |
514 E2: NormExponent, |
| 603 } |
603 } |
| 604 |
604 |
| 605 impl<F, S, T, X, Z, Xexp, Yexp, Zexp> BoundedLinear<X, Xexp, Yexp, F> for Composition<S, T, Zexp> |
605 impl<F, S, T, X, Z, Xexp, Yexp, Zexp> BoundedLinear<X, Xexp, Yexp, F> for Composition<S, T, Zexp> |
| 606 where |
606 where |
| 607 F: Num, |
607 F: Num, |
| 608 X: Space + Norm<Xexp, F>, |
608 X: Space, |
| 609 Z: Space + Norm<Zexp, F>, |
609 Z: Space, |
| 610 Xexp: NormExponent, |
610 Xexp: NormExponent, |
| 611 Yexp: NormExponent, |
611 Yexp: NormExponent, |
| 612 Zexp: NormExponent, |
612 Zexp: NormExponent, |
| 613 T: BoundedLinear<X, Xexp, Zexp, F, Codomain = Z>, |
613 T: BoundedLinear<X, Xexp, Zexp, F, Codomain = Z>, |
| 614 S: BoundedLinear<Z, Zexp, Yexp, F>, |
614 S: BoundedLinear<Z, Zexp, Yexp, F>, |
| 1002 ($expj:ty) => { |
1002 ($expj:ty) => { |
| 1003 impl<F, A, B, S, T, ExpA, ExpB, ExpR> |
1003 impl<F, A, B, S, T, ExpA, ExpB, ExpR> |
| 1004 BoundedLinear<Pair<A, B>, PairNorm<ExpA, ExpB, $expj>, ExpR, F> for RowOp<S, T> |
1004 BoundedLinear<Pair<A, B>, PairNorm<ExpA, ExpB, $expj>, ExpR, F> for RowOp<S, T> |
| 1005 where |
1005 where |
| 1006 F: Float, |
1006 F: Float, |
| 1007 A: Space + Norm<ExpA, F>, |
1007 A: Space, |
| 1008 B: Space + Norm<ExpB, F>, |
1008 B: Space, |
| 1009 S: BoundedLinear<A, ExpA, ExpR, F>, |
1009 S: BoundedLinear<A, ExpA, ExpR, F>, |
| 1010 T: BoundedLinear<B, ExpB, ExpR, F>, |
1010 T: BoundedLinear<B, ExpB, ExpR, F>, |
| 1011 S::Codomain: Add<T::Codomain>, |
1011 S::Codomain: Add<T::Codomain>, |
| 1012 <S::Codomain as Add<T::Codomain>>::Output: ClosedSpace, |
1012 <S::Codomain as Add<T::Codomain>>::Output: ClosedSpace, |
| 1013 ExpA: NormExponent, |
1013 ExpA: NormExponent, |
| 1029 |
1029 |
| 1030 impl<F, A, S, T, ExpA, ExpS, ExpT> BoundedLinear<A, ExpA, PairNorm<ExpS, ExpT, $expj>, F> |
1030 impl<F, A, S, T, ExpA, ExpS, ExpT> BoundedLinear<A, ExpA, PairNorm<ExpS, ExpT, $expj>, F> |
| 1031 for ColOp<S, T> |
1031 for ColOp<S, T> |
| 1032 where |
1032 where |
| 1033 F: Float, |
1033 F: Float, |
| 1034 A: Space + Norm<ExpA, F>, |
1034 A: Space, |
| 1035 S: BoundedLinear<A, ExpA, ExpS, F>, |
1035 S: BoundedLinear<A, ExpA, ExpS, F>, |
| 1036 T: BoundedLinear<A, ExpA, ExpT, F>, |
1036 T: BoundedLinear<A, ExpA, ExpT, F>, |
| 1037 ExpA: NormExponent, |
1037 ExpA: NormExponent, |
| 1038 ExpS: NormExponent, |
1038 ExpS: NormExponent, |
| 1039 ExpT: NormExponent, |
1039 ExpT: NormExponent, |