| 8 use crate::norms::{Linfinity, Norm, NormExponent, PairNorm, L1, L2}; |
8 use crate::norms::{Linfinity, Norm, NormExponent, PairNorm, L1, L2}; |
| 9 use crate::types::*; |
9 use crate::types::*; |
| 10 use numeric_literals::replace_float_literals; |
10 use numeric_literals::replace_float_literals; |
| 11 use serde::Serialize; |
11 use serde::Serialize; |
| 12 use std::marker::PhantomData; |
12 use std::marker::PhantomData; |
| |
13 use std::ops::Mul; |
| 13 |
14 |
| 14 /// Trait for linear operators on `X`. |
15 /// Trait for linear operators on `X`. |
| 15 pub trait Linear<X: Space>: Mapping<X> {} |
16 pub trait Linear<X: Space>: Mapping<X> {} |
| 16 |
17 |
| 17 // impl<X: Space, A: Linear<X>> DifferentiableImpl<X> for A { |
18 // impl<X: Space, A: Linear<X>> DifferentiableImpl<X> for A { |
| 726 } |
727 } |
| 727 |
728 |
| 728 pairnorm!(L1); |
729 pairnorm!(L1); |
| 729 pairnorm!(L2); |
730 pairnorm!(L2); |
| 730 pairnorm!(Linfinity); |
731 pairnorm!(Linfinity); |
| |
732 |
| |
733 /// The simplest linear mapping, scaling by a scalar. |
| |
734 /// |
| |
735 /// TODO: redefined/replace [`Weighted`] by composition with [`Scaled`]. |
| |
736 pub struct Scaled<F: Float>(pub F); |
| |
737 |
| |
738 impl<Domain, F> Mapping<Domain> for Scaled<F> |
| |
739 where |
| |
740 F: Float, |
| |
741 Domain: Space + ClosedMul<F>, |
| |
742 { |
| |
743 type Codomain = <Domain as Mul<F>>::Output; |
| |
744 |
| |
745 /// Compute the value of `self` at `x`. |
| |
746 fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { |
| |
747 x.own() * self.0 |
| |
748 } |
| |
749 } |
| |
750 |
| |
751 impl<Domain, F> Linear<Domain> for Scaled<F> |
| |
752 where |
| |
753 F: Float, |
| |
754 Domain: Space + ClosedMul<F>, |
| |
755 { |
| |
756 } |