--- a/src/mapping.rs Tue Apr 29 00:03:12 2025 -0500 +++ b/src/mapping.rs Tue Apr 29 07:55:18 2025 -0500 @@ -9,6 +9,7 @@ use crate::types::{ClosedMul, Float, Num}; use std::borrow::Cow; use std::marker::PhantomData; +use std::ops::Mul; /// A mapping from `Domain` to `Self::Codomain`. pub trait Mapping<Domain: Space> { @@ -283,8 +284,39 @@ } } +/// Helper trait for implementing [`DifferentiableMapping`] +impl<S, T, X, E, Y> DifferentiableImpl<X> for Composition<S, T, E> +where + X: Space, + T: DifferentiableImpl<X> + Mapping<X>, + S: DifferentiableImpl<T::Codomain>, + E: Copy, + //Composition<S::Derivative, T::Derivative, E>: Space, + S::Derivative: Mul<T::Derivative, Output = Y>, + Y: Space, +{ + //type Derivative = Composition<S::Derivative, T::Derivative, E>; + type Derivative = Y; + + /// Compute the differential of `self` at `x`, consuming the input. + fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative { + // Composition { + // outer: self + // .outer + // .differential_impl(self.inner.apply(x.ref_instance())), + // inner: self.inner.differential_impl(x), + // intermediate_norm_exponent: self.intermediate_norm_exponent, + // } + self.outer + .differential_impl(self.inner.apply(x.ref_instance())) + * self.inner.differential_impl(x) + } +} + mod quadratic; pub use quadratic::Quadratic; +mod dataterm; +pub use dataterm::DataTerm; /// Trait for indicating that `Self` is Lipschitz with respect to the (semi)norm `D`. pub trait Lipschitz<M> {