Fri, 13 Oct 2023 14:15:56 -0500
diff_ref
src/mapping.rs | file | annotate | diff | comparison | revisions |
--- 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<Domain, Self> { Differential{ g : self, _space : PhantomData } } + + /// Form the differential mapping of `self`. + fn diff_ref(&self) -> Differential<Domain, Ref<'_, Self>> { + Differential{ g : Ref(self), _space : PhantomData } + } } @@ -242,9 +247,35 @@ assert!(slice < N); SlicedCodomain{ g : self, slice, _phantoms : PhantomData } } + + /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. + fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain<X, F, Ref<'_, Self>, N> { + assert!(slice < N); + SlicedCodomain{ g : Ref(self), slice, _phantoms : PhantomData } + } } impl<X, F : Copy, G : Sized + Mapping<X, Codomain=Loc<F, N>>, const N : usize> 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 Output = G::Output; + #[inline] + fn differential(&self, x : X) -> Self::Output { + self.0.differential(x) + } +}