# HG changeset patch # User Tuomo Valkonen # Date 1731202583 18000 # Node ID a0db98c16ab58e1e1da2fe5451a970ec5a90dff1 # Parent bd924d62d952b3391f6b9198cf4cc1513191dc87 Some Differentiable simplifications and clarifications diff -r bd924d62d952 -r a0db98c16ab5 src/bisection_tree/btfn.rs --- a/src/bisection_tree/btfn.rs Wed Nov 06 15:34:17 2024 -0500 +++ b/src/bisection_tree/btfn.rs Sat Nov 09 20:36:23 2024 -0500 @@ -424,12 +424,12 @@ for BTFN where BT : BTImpl, G : SupportGenerator, - G::SupportType : LocalAnalysis + Differentiable<&'a Loc, Output = V>, + G::SupportType : LocalAnalysis + Differentiable<&'a Loc, Derivative = V>, V : Sum { - type Output = V; + type Derivative = V; - fn differential(&self, x : &'a Loc) -> Self::Output { + fn differential(&self, x : &'a Loc) -> Self::Derivative { self.bt.iter_at(x) .map(|&d| self.generator.support_for(d).differential(x)) .sum() @@ -440,12 +440,12 @@ for BTFN where BT : BTImpl, G : SupportGenerator, - G::SupportType : LocalAnalysis + Differentiable, Output = V>, + G::SupportType : LocalAnalysis + Differentiable, Derivative = V>, V : Sum { - type Output = V; + type Derivative = V; - fn differential(&self, x : Loc) -> Self::Output { + fn differential(&self, x : Loc) -> Self::Derivative { self.bt.iter_at(&x) .map(|&d| self.generator.support_for(d).differential(x)) .sum() diff -r bd924d62d952 -r a0db98c16ab5 src/bisection_tree/either.rs --- a/src/bisection_tree/either.rs Wed Nov 06 15:34:17 2024 -0500 +++ b/src/bisection_tree/either.rs Sat Nov 09 20:36:23 2024 -0500 @@ -191,9 +191,9 @@ } impl Differentiable for EitherSupport -where S1 : Differentiable, - S2 : Differentiable { - type Output = F; +where S1 : Differentiable, + S2 : Differentiable { + type Derivative = F; #[inline] fn differential(&self, x : X) -> F { match self { diff -r bd924d62d952 -r a0db98c16ab5 src/bisection_tree/support.rs --- a/src/bisection_tree/support.rs Wed Nov 06 15:34:17 2024 -0500 +++ b/src/bisection_tree/support.rs Sat Nov 09 20:36:23 2024 -0500 @@ -146,19 +146,19 @@ } impl<'a, T, V, F : Float, const N : usize> Differentiable<&'a Loc> for Shift -where T : Differentiable, Output=V> { - type Output = V; +where T : Differentiable, Derivative=V> { + type Derivative = V; #[inline] - fn differential(&self, x : &'a Loc) -> Self::Output { + fn differential(&self, x : &'a Loc) -> Self::Derivative { self.base_fn.differential(x - &self.shift) } } impl<'a, T, V, F : Float, const N : usize> Differentiable> for Shift -where T : Differentiable, Output=V> { - type Output = V; +where T : Differentiable, Derivative=V> { + type Derivative = V; #[inline] - fn differential(&self, x : Loc) -> Self::Output { + fn differential(&self, x : Loc) -> Self::Derivative { self.base_fn.differential(x - &self.shift) } } @@ -251,23 +251,23 @@ } impl<'a, T, V, F : Float, C, const N : usize> Differentiable<&'a Loc> for Weighted -where T : for<'b> Differentiable<&'b Loc, Output=V>, +where T : for<'b> Differentiable<&'b Loc, Derivative=V>, V : std::ops::Mul, C : Constant { - type Output = V; + type Derivative = V; #[inline] - fn differential(&self, x : &'a Loc) -> Self::Output { + fn differential(&self, x : &'a Loc) -> Self::Derivative { self.base_fn.differential(x) * self.weight.value() } } impl<'a, T, V, F : Float, C, const N : usize> Differentiable> for Weighted -where T : Differentiable, Output=V>, +where T : Differentiable, Derivative=V>, V : std::ops::Mul, C : Constant { - type Output = V; + type Derivative = V; #[inline] - fn differential(&self, x : Loc) -> Self::Output { + fn differential(&self, x : Loc) -> Self::Derivative { self.base_fn.differential(x) * self.weight.value() } } diff -r bd924d62d952 -r a0db98c16ab5 src/mapping.rs --- a/src/mapping.rs Wed Nov 06 15:34:17 2024 -0500 +++ b/src/mapping.rs Sat Nov 09 20:36:23 2024 -0500 @@ -68,10 +68,10 @@ /// Trait for calculation the differential of `Self` as a mathematical function on `X`. pub trait Differentiable : Sized { - type Output; + type Derivative; /// Compute the differential of `self` at `x`. - fn differential(&self, x : X) -> Self::Output; + fn differential(&self, x : X) -> Self::Derivative; } /// A differentiable mapping from `Domain` to [`Mapping::Codomain`], with differentials @@ -80,8 +80,8 @@ /// This is automatically implemented when the relevant [`Differentiate`] are implemented. pub trait DifferentiableMapping : Mapping - + Differentiable - + for<'a> Differentiable<&'a Domain, Output=Self::Differential> { + + Differentiable + + for<'a> Differentiable<&'a Domain, Derivative=Self::Differential> { type Differential; /// Form the differential mapping of `self`. @@ -98,8 +98,8 @@ impl DifferentiableMapping for T where T : Mapping - + Differentiable - + for<'a> Differentiable<&'a Domain, Output=Differential> { + + Differentiable + + for<'a> Differentiable<&'a Domain, Derivative=Differential> { type Differential = Differential; } @@ -149,9 +149,9 @@ M :: Differential : std::iter::Sum, Domain : Copy { - type Output = M::Differential; + type Derivative = M::Differential; - fn differential(&self, x : Domain) -> Self::Output { + fn differential(&self, x : Domain) -> Self::Derivative { self.components.iter().map(|c| c.differential(x)).sum() } } @@ -273,9 +273,9 @@ } impl<'g, X, G : Differentiable> Differentiable for Ref<'g, G> { - type Output = G::Output; + type Derivative = G::Derivative; #[inline] - fn differential(&self, x : X) -> Self::Output { + fn differential(&self, x : X) -> Self::Derivative { self.0.differential(x) } }