# HG changeset patch # User Tuomo Valkonen # Date 1768511567 18000 # Node ID a5ee4bfb0b8774074cc27ea169a3a7d64332b0a5 # Parent dccf609cd02060200e206b28d2e0e166bc8c445d apply_and_differential_impl diff -r dccf609cd020 -r a5ee4bfb0b87 src/mapping.rs --- 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>(&self, x: I) -> Self::DerivativeDomain; + /// Calculate differential and value at `x` + fn apply_and_differential>( + &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>(&self, x: I) -> Self::Derivative; + + fn apply_and_differential_impl>( + &self, + x: I, + ) -> (Self::Codomain, Self::Derivative) + where + Self: Mapping, + { + x.eval_ref(|xo| (self.apply(xo), self.differential_impl(xo))) + } } impl DifferentiableMapping for T @@ -126,6 +144,14 @@ self.differential_impl(x) } + #[inline] + fn apply_and_differential>( + &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 } } diff -r dccf609cd020 -r a5ee4bfb0b87 src/mapping/dataterm.rs --- 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 + for<'a> Sub<&'a Y, Output = Y>, - //>::Codomain: Euclidean, A: Linear + Preadjointable, G::DerivativeDomain: Instance, A::PreadjointCodomain: ClosedSpace, - //<>::Codomain as Euclidean>::Output: Instance<>::Codomain>, G: DifferentiableMapping, + Self: Mapping, { 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>(&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)) } }