Sun, 10 Nov 2024 09:02:57 -0500
Ref is not needed.
src/mapping.rs | file | annotate | diff | comparison | revisions |
--- 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<X>> Differentiable<X> 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<Domain, Self>; - type DifferentialRef<'b> = Differential<Domain, Ref<'b, Self>> where Self : 'b; + type DifferentialRef<'b> = Differential<Domain, &'b Self> 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<X> } +impl<X, G : DifferentiableMapping<X>> Differential<X, G> { + pub fn base_fn(&self) -> &G { + &self.g + } +} + impl<X, G : DifferentiableMapping<X>> Apply<X> for Differential<X, G> { type Output = G::DerivativeDomain; @@ -258,9 +272,9 @@ } /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. - fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain<X, F, Ref<'_, Self>, N> { + fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain<X, F, &'_ Self, N> { assert!(slice < N); - SlicedCodomain{ g : Ref(self), slice, _phantoms : PhantomData } + SlicedCodomain{ g : self, slice, _phantoms : PhantomData } } } @@ -268,23 +282,3 @@ SliceCodomain<X, F, N> 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<X>> Apply<X> 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<X>> Differentiable<X> for Ref<'g, G> { - type Derivative = G::Derivative; - #[inline] - fn differential(&self, x : X) -> Self::Derivative { - self.0.differential(x) - } -}