diff -r 3f3e00e81755 -r edb95d2b83cc src/mapping.rs --- a/src/mapping.rs Sat Nov 09 20:54:32 2024 -0500 +++ b/src/mapping.rs Sun Nov 10 09:02:57 2024 -0500 @@ -74,6 +74,14 @@ fn differential(&self, x : X) -> Self::Derivative; } +impl<'g, X, G : Differentiable> Differentiable for &'g G { + type Derivative = G::Derivative; + #[inline] + fn differential(&self, x : X) -> Self::Derivative { + (*self).differential(x) + } +} + /// A differentiable mapping from `Domain` to [`Mapping::Codomain`], with differentials /// `Differential`. /// @@ -99,7 +107,7 @@ + for<'a> Differentiable<&'a Domain,Derivative=Derivative> { type DerivativeDomain = Derivative; type Differential = Differential; - type DifferentialRef<'b> = Differential> where Self : 'b; + type DifferentialRef<'b> = Differential where Self : 'b; /// Form the differential mapping of `self`. fn diff(self) -> Self::Differential { @@ -108,7 +116,7 @@ /// Form the differential mapping of `self`. fn diff_ref(&self) -> Self::DifferentialRef<'_> { - Differential{ g : Ref(self), _space : PhantomData } + Differential{ g : self, _space : PhantomData } } } @@ -171,6 +179,12 @@ _space : PhantomData } +impl> Differential { + pub fn base_fn(&self) -> &G { + &self.g + } +} + impl> Apply for Differential { type Output = G::DerivativeDomain; @@ -258,9 +272,9 @@ } /// Flatten the codomain from [`Loc`]`` to `F`. - fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain, N> { + fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain { assert!(slice < N); - SlicedCodomain{ g : Ref(self), slice, _phantoms : PhantomData } + SlicedCodomain{ g : self, slice, _phantoms : PhantomData } } } @@ -268,23 +282,3 @@ SliceCodomain for G {} - -/// Helper struct for doing operations on references of mappings while avoiding -/// conflicting implementations that `&'g G` would cause. -pub struct Ref<'g, G>(&'g G); - -impl<'g, X, G : Apply> Apply for Ref<'g, G> { - type Output = G::Output; - #[inline] - fn apply(&self, x : X) -> Self::Output { - self.0.apply(x) - } -} - -impl<'g, X, G : Differentiable> Differentiable for Ref<'g, G> { - type Derivative = G::Derivative; - #[inline] - fn differential(&self, x : X) -> Self::Derivative { - self.0.differential(x) - } -}