src/linops.rs

branch
dev
changeset 104
e7f1cb4bec78
parent 101
997961aa6eee
child 110
a1278320be26
--- a/src/linops.rs	Mon Apr 28 23:16:56 2025 -0500
+++ b/src/linops.rs	Tue Apr 29 00:03:12 2025 -0500
@@ -10,6 +10,7 @@
 use numeric_literals::replace_float_literals;
 use serde::Serialize;
 use std::marker::PhantomData;
+use std::ops::Mul;
 
 /// Trait for linear operators on `X`.
 pub trait Linear<X: Space>: Mapping<X> {}
@@ -728,3 +729,28 @@
 pairnorm!(L1);
 pairnorm!(L2);
 pairnorm!(Linfinity);
+
+/// The simplest linear mapping, scaling by a scalar.
+///
+/// TODO: redefined/replace [`Weighted`] by composition with [`Scaled`].
+pub struct Scaled<F: Float>(pub F);
+
+impl<Domain, F> Mapping<Domain> for Scaled<F>
+where
+    F: Float,
+    Domain: Space + ClosedMul<F>,
+{
+    type Codomain = <Domain as Mul<F>>::Output;
+
+    /// Compute the value of `self` at `x`.
+    fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain {
+        x.own() * self.0
+    }
+}
+
+impl<Domain, F> Linear<Domain> for Scaled<F>
+where
+    F: Float,
+    Domain: Space + ClosedMul<F>,
+{
+}

mercurial