Thu, 15 Jan 2026 16:12:47 -0500
apply_and_differential_impl
| src/mapping.rs | file | annotate | diff | comparison | revisions | |
| src/mapping/dataterm.rs | file | annotate | diff | comparison | revisions |
--- a/src/mapping.rs Mon Dec 08 15:23:42 2025 -0500 +++ b/src/mapping.rs Thu Jan 15 16:12:47 2026 -0500 @@ -83,6 +83,14 @@ /// Calculate differential at `x` fn differential<I: Instance<Domain>>(&self, x: I) -> Self::DerivativeDomain; + /// Calculate differential and value at `x` + fn apply_and_differential<I: Instance<Domain>>( + &self, + x: I, + ) -> (Self::Codomain, Self::DerivativeDomain) { + x.eval_ref(|xo| (self.apply(xo), self.differential(xo))) + } + /// Form the differential mapping of `self`. fn diff(self) -> Self::Differential<'static>; @@ -108,6 +116,16 @@ /// Compute the differential of `self` at `x`, consuming the input. fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative; + + fn apply_and_differential_impl<I: Instance<X>>( + &self, + x: I, + ) -> (Self::Codomain, Self::Derivative) + where + Self: Mapping<X>, + { + x.eval_ref(|xo| (self.apply(xo), self.differential_impl(xo))) + } } impl<T, Domain> DifferentiableMapping<Domain> for T @@ -126,6 +144,14 @@ self.differential_impl(x) } + #[inline] + fn apply_and_differential<I: Instance<Domain>>( + &self, + x: I, + ) -> (T::Codomain, Self::DerivativeDomain) { + self.apply_and_differential_impl(x) + } + fn diff(self) -> Differential<'static, Domain, Self> { Differential { g: MyCow::Owned(self), _space: PhantomData } }
--- a/src/mapping/dataterm.rs Mon Dec 08 15:23:42 2025 -0500 +++ b/src/mapping/dataterm.rs Thu Jan 15 16:12:47 2026 -0500 @@ -112,12 +112,11 @@ F: Float, X: Space, Y: Space + Instance<Y> + for<'a> Sub<&'a Y, Output = Y>, - //<A as Mapping<X>>::Codomain: Euclidean<F>, A: Linear<X, Codomain = Y> + Preadjointable<X, G::DerivativeDomain>, G::DerivativeDomain: Instance<G::DerivativeDomain>, A::PreadjointCodomain: ClosedSpace, - //<<A as Mapping<X>>::Codomain as Euclidean<F>>::Output: Instance<<A as Mapping<X>>::Codomain>, G: DifferentiableMapping<Y, Codomain = F>, + Self: Mapping<X, Codomain = F>, { type Derivative = A::PreadjointCodomain; @@ -129,7 +128,13 @@ //self.opA.preadjoint().apply(self.opA.apply(x) - self.b) self.opA .preadjoint() - .apply(self.g.diff_ref().apply(self.opA.apply(x) - &self.b)) + .apply(self.g.differential(self.opA.apply(x) - &self.b)) + } + + fn apply_and_differential_impl<I: Instance<X>>(&self, x: I) -> (F, Self::Derivative) { + let j = self.opA.apply(x) - &self.b; + let (v, d) = self.g.apply_and_differential(j); + (v, self.opA.preadjoint().apply(d)) } }