| 86 | 86 | 
| 87     /// Form the differential mapping of `self`. | 87     /// Form the differential mapping of `self`. | 
| 88     fn diff(self) -> Differential<Domain, Self> { | 88     fn diff(self) -> Differential<Domain, Self> { | 
| 89         Differential{ g : self, _space : PhantomData } | 89         Differential{ g : self, _space : PhantomData } | 
| 90     } | 90     } | 
|  | 91 | 
|  | 92     /// Form the differential mapping of `self`. | 
|  | 93     fn diff_ref(&self) -> Differential<Domain, Ref<'_, Self>> { | 
|  | 94         Differential{ g : Ref(self), _space : PhantomData } | 
|  | 95     } | 
| 91 } | 96 } | 
| 92 | 97 | 
| 93 | 98 | 
| 94 impl<Domain, Differential, T> DifferentiableMapping<Domain> for T | 99 impl<Domain, Differential, T> DifferentiableMapping<Domain> for T | 
| 95 where T : Mapping<Domain> | 100 where T : Mapping<Domain> | 
| 240     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. | 245     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. | 
| 241     fn slice_codomain(self, slice : usize) -> SlicedCodomain<X, F, Self, N> { | 246     fn slice_codomain(self, slice : usize) -> SlicedCodomain<X, F, Self, N> { | 
| 242         assert!(slice < N); | 247         assert!(slice < N); | 
| 243         SlicedCodomain{ g : self, slice, _phantoms : PhantomData } | 248         SlicedCodomain{ g : self, slice, _phantoms : PhantomData } | 
| 244     } | 249     } | 
|  | 250 | 
|  | 251     /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. | 
|  | 252     fn slice_codomain_ref(&self, slice : usize) -> SlicedCodomain<X, F, Ref<'_, Self>, N> { | 
|  | 253         assert!(slice < N); | 
|  | 254         SlicedCodomain{ g : Ref(self), slice, _phantoms : PhantomData } | 
|  | 255     } | 
| 245 } | 256 } | 
| 246 | 257 | 
| 247 impl<X, F : Copy, G : Sized + Mapping<X, Codomain=Loc<F, N>>, const N : usize> | 258 impl<X, F : Copy, G : Sized + Mapping<X, Codomain=Loc<F, N>>, const N : usize> | 
| 248 SliceCodomain<X, F, N> | 259 SliceCodomain<X, F, N> | 
| 249 for G {} | 260 for G {} | 
| 250 | 261 | 
|  | 262 | 
|  | 263 /// Helper struct for doing operations on references of mappings while avoiding | 
|  | 264 /// conflicting implementations that `&'g G` would cause. | 
|  | 265 pub struct Ref<'g, G>(&'g G); | 
|  | 266 | 
|  | 267 impl<'g, X, G : Apply<X>> Apply<X> for Ref<'g, G> { | 
|  | 268     type Output = G::Output; | 
|  | 269     #[inline] | 
|  | 270     fn apply(&self, x : X) -> Self::Output { | 
|  | 271         self.0.apply(x) | 
|  | 272     } | 
|  | 273 } | 
|  | 274 | 
|  | 275 impl<'g, X, G : Differentiable<X>> Differentiable<X> for Ref<'g, G> { | 
|  | 276     type Output = G::Output; | 
|  | 277     #[inline] | 
|  | 278     fn differential(&self, x : X) -> Self::Output { | 
|  | 279         self.0.differential(x) | 
|  | 280     } | 
|  | 281 } |