diff -r 212f75931da0 -r f75bf34adda0 src/mapping.rs --- a/src/mapping.rs Thu May 08 22:53:31 2025 -0500 +++ b/src/mapping.rs Sun May 11 02:03:45 2025 -0500 @@ -3,12 +3,12 @@ */ use crate::error::DynResult; +use crate::instance::MyCow; pub use crate::instance::{BasicDecomposition, Decomposition, Instance, Space}; use crate::loc::Loc; use crate::norms::{Norm, NormExponent}; use crate::operator_arithmetic::{Constant, Weighted}; use crate::types::{ClosedMul, Float, Num}; -use std::borrow::Cow; use std::marker::PhantomData; use std::ops::Mul; @@ -124,7 +124,7 @@ impl DifferentiableMapping for T where Domain: Space, - T: Clone + Mapping + DifferentiableImpl, + T: Mapping + DifferentiableImpl, { type DerivativeDomain = T::Derivative; type Differential<'b> @@ -139,26 +139,26 @@ fn diff(self) -> Differential<'static, Domain, Self> { Differential { - g: Cow::Owned(self), + g: MyCow::Owned(self), _space: PhantomData, } } fn diff_ref(&self) -> Differential<'_, Domain, Self> { Differential { - g: Cow::Borrowed(self), + g: MyCow::Borrowed(self), _space: PhantomData, } } } /// Container for the differential [`Mapping`] of a [`DifferentiableMapping`]. -pub struct Differential<'a, X, G: Clone> { - g: Cow<'a, G>, +pub struct Differential<'a, X, G> { + g: MyCow<'a, G>, _space: PhantomData, } -impl<'a, X, G: Clone> Differential<'a, X, G> { +impl<'a, X, G> Differential<'a, X, G> { pub fn base_fn(&self) -> &G { &self.g } @@ -167,7 +167,7 @@ impl<'a, X, G> Mapping for Differential<'a, X, G> where X: Space, - G: Clone + DifferentiableMapping, + G: DifferentiableMapping, { type Codomain = G::DerivativeDomain; @@ -211,8 +211,8 @@ impl>> FlattenCodomain for G {} /// Container for dimensional slicing [`Loc`]`` codomain of a [`Mapping`] to `F`. -pub struct SlicedCodomain<'a, X, F, G: Clone, const N: usize> { - g: Cow<'a, G>, +pub struct SlicedCodomain<'a, X, F, G, const N: usize> { + g: MyCow<'a, G>, slice: usize, _phantoms: PhantomData<(X, F)>, } @@ -221,7 +221,7 @@ where X: Space, F: Copy + Space, - G: Mapping> + Clone, + G: Mapping>, { type Codomain = F; @@ -236,13 +236,13 @@ /// An auto-trait for constructing a [`FlattenCodomain`] structure for /// flattening the codomain of a [`Mapping`] from [`Loc`]`` to `F`. pub trait SliceCodomain: - Mapping> + Clone + Sized + Mapping> + Sized { /// Flatten the codomain from [`Loc`]`` to `F`. fn slice_codomain(self, slice: usize) -> SlicedCodomain<'static, X, F, Self, N> { assert!(slice < N); SlicedCodomain { - g: Cow::Owned(self), + g: MyCow::Owned(self), slice, _phantoms: PhantomData, } @@ -252,14 +252,14 @@ fn slice_codomain_ref(&self, slice: usize) -> SlicedCodomain<'_, X, F, Self, N> { assert!(slice < N); SlicedCodomain { - g: Cow::Borrowed(self), + g: MyCow::Borrowed(self), slice, _phantoms: PhantomData, } } } -impl> + Clone, const N: usize> +impl>, const N: usize> SliceCodomain for G { } @@ -337,7 +337,7 @@ impl<'b, M, X, A> Lipschitz for Differential<'b, X, A> where X: Space, - A: LipschitzDifferentiableImpl + Clone, + A: LipschitzDifferentiableImpl, { type FloatType = A::FloatType;