# HG changeset patch # User Tuomo Valkonen # Date 1697224556 18000 # Node ID 8de8a80852c2db2e2857df6243bc1f434f96af85 # Parent 239aa32f0e7df91fc40ae18bed0e0c8aebbb84f9 diff_ref diff -r 239aa32f0e7d -r 8de8a80852c2 src/mapping.rs --- a/src/mapping.rs Mon Oct 21 09:59:45 2024 -0500 +++ b/src/mapping.rs Fri Oct 13 14:15:56 2023 -0500 @@ -88,6 +88,11 @@ fn diff(self) -> Differential { Differential{ g : self, _space : PhantomData } } + + /// Form the differential mapping of `self`. + fn diff_ref(&self) -> Differential> { + Differential{ g : Ref(self), _space : PhantomData } + } } @@ -242,9 +247,35 @@ assert!(slice < N); SlicedCodomain{ g : self, slice, _phantoms : PhantomData } } + + /// Flatten the codomain from [`Loc`]`` to `F`. + fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain, N> { + assert!(slice < N); + SlicedCodomain{ g : Ref(self), slice, _phantoms : PhantomData } + } } impl>, const N : usize> 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 Output = G::Output; + #[inline] + fn differential(&self, x : X) -> Self::Output { + self.0.differential(x) + } +}