src/mapping.rs

branch
dev
changeset 150
c4e394a9c84c
parent 133
2b13f8a0c8ba
child 151
402d717bb5c0
--- a/src/mapping.rs	Mon Sep 01 00:04:22 2025 -0500
+++ b/src/mapping.rs	Mon Sep 01 13:51:03 2025 -0500
@@ -4,7 +4,7 @@
 
 use crate::error::DynResult;
 use crate::instance::MyCow;
-pub use crate::instance::{BasicDecomposition, Decomposition, Instance, Space};
+pub use crate::instance::{BasicDecomposition, ClosedSpace, Decomposition, Instance, Space};
 use crate::loc::Loc;
 use crate::norms::{Norm, NormExponent};
 use crate::operator_arithmetic::{Constant, Weighted};
@@ -14,7 +14,7 @@
 
 /// A mapping from `Domain` to `Self::Codomain`.
 pub trait Mapping<Domain: Space> {
-    type Codomain: Space;
+    type Codomain: ClosedSpace;
 
     /// Compute the value of `self` at `x`.
     fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain;
@@ -25,11 +25,7 @@
     where
         Self: Sized,
     {
-        Composition {
-            outer: self,
-            inner: other,
-            intermediate_norm_exponent: (),
-        }
+        Composition { outer: self, inner: other, intermediate_norm_exponent: () }
     }
 
     #[inline]
@@ -43,11 +39,7 @@
         Domain: Norm<E, F>,
         F: Num,
     {
-        Composition {
-            outer: self,
-            inner: other,
-            intermediate_norm_exponent: norm,
-        }
+        Composition { outer: self, inner: other, intermediate_norm_exponent: norm }
     }
 
     /// Multiply `self` by the scalar `a`.
@@ -58,10 +50,7 @@
         C: Constant,
         Self::Codomain: ClosedMul<C::Type>,
     {
-        Weighted {
-            weight: a,
-            base_fn: self,
-        }
+        Weighted { weight: a, base_fn: self }
     }
 }
 
@@ -86,7 +75,7 @@
 ///
 /// This is automatically implemented when [`DifferentiableImpl`] is.
 pub trait DifferentiableMapping<Domain: Space>: Mapping<Domain> {
-    type DerivativeDomain: Space;
+    type DerivativeDomain: ClosedSpace;
     type Differential<'b>: Mapping<Domain, Codomain = Self::DerivativeDomain>
     where
         Self: 'b;
@@ -115,7 +104,7 @@
 
 /// Helper trait for implementing [`DifferentiableMapping`]
 pub trait DifferentiableImpl<X: Space>: Sized {
-    type Derivative: Space;
+    type Derivative: ClosedSpace;
 
     /// Compute the differential of `self` at `x`, consuming the input.
     fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative;
@@ -138,17 +127,11 @@
     }
 
     fn diff(self) -> Differential<'static, Domain, Self> {
-        Differential {
-            g: MyCow::Owned(self),
-            _space: PhantomData,
-        }
+        Differential { g: MyCow::Owned(self), _space: PhantomData }
     }
 
     fn diff_ref(&self) -> Differential<'_, Domain, Self> {
-        Differential {
-            g: MyCow::Borrowed(self),
-            _space: PhantomData,
-        }
+        Differential { g: MyCow::Borrowed(self), _space: PhantomData }
     }
 }
 
@@ -201,10 +184,7 @@
 pub trait FlattenCodomain<X: Space, F>: Mapping<X, Codomain = Loc<1, F>> + Sized {
     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`.
     fn flatten_codomain(self) -> FlattenedCodomain<X, F, Self> {
-        FlattenedCodomain {
-            g: self,
-            _phantoms: PhantomData,
-        }
+        FlattenedCodomain { g: self, _phantoms: PhantomData }
     }
 }
 
@@ -241,21 +221,13 @@
     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`.
     fn slice_codomain(self, slice: usize) -> SlicedCodomain<'static, X, F, Self, N> {
         assert!(slice < N);
-        SlicedCodomain {
-            g: MyCow::Owned(self),
-            slice,
-            _phantoms: PhantomData,
-        }
+        SlicedCodomain { g: MyCow::Owned(self), slice, _phantoms: PhantomData }
     }
 
     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`.
     fn slice_codomain_ref(&self, slice: usize) -> SlicedCodomain<'_, X, F, Self, N> {
         assert!(slice < N);
-        SlicedCodomain {
-            g: MyCow::Borrowed(self),
-            slice,
-            _phantoms: PhantomData,
-        }
+        SlicedCodomain { g: MyCow::Borrowed(self), slice, _phantoms: PhantomData }
     }
 }
 
@@ -294,7 +266,7 @@
     E: Copy,
     //Composition<S::Derivative, T::Derivative, E>: Space,
     S::Derivative: Mul<T::Derivative, Output = Y>,
-    Y: Space,
+    Y: ClosedSpace,
 {
     //type Derivative = Composition<S::Derivative, T::Derivative, E>;
     type Derivative = Y;

mercurial