diff -r 1a38447a89fa -r 9226980e45a7 src/bisection_tree/support.rs --- a/src/bisection_tree/support.rs Sat Dec 14 09:31:27 2024 -0500 +++ b/src/bisection_tree/support.rs Tue Dec 31 08:30:02 2024 -0500 @@ -6,7 +6,9 @@ use std::ops::{MulAssign,DivAssign,Neg}; use crate::types::{Float, Num}; use crate::maputil::map2; -use crate::mapping::{Apply, Differentiable}; +use crate::mapping::{ + Instance, Mapping, DifferentiableImpl, DifferentiableMapping, Space +}; use crate::sets::Cube; use crate::loc::Loc; use super::aggregator::Bounds; @@ -127,39 +129,23 @@ base_fn : T, } -impl<'a, T, V, F : Float, const N : usize> Apply<&'a Loc> for Shift -where T : Apply, Output=V> { - type Output = V; +impl<'a, T, V : Space, F : Float, const N : usize> Mapping> for Shift +where T : Mapping, Codomain=V> { + type Codomain = V; + #[inline] - fn apply(&self, x : &'a Loc) -> Self::Output { - self.base_fn.apply(x - &self.shift) + fn apply>>(&self, x : I) -> Self::Codomain { + self.base_fn.apply(x.own() - &self.shift) } } -impl<'a, T, V, F : Float, const N : usize> Apply> for Shift -where T : Apply, Output=V> { - type Output = V; - #[inline] - fn apply(&self, x : Loc) -> Self::Output { - self.base_fn.apply(x - &self.shift) - } -} - -impl<'a, T, V, F : Float, const N : usize> Differentiable<&'a Loc> for Shift -where T : Differentiable, Derivative=V> { +impl<'a, T, V : Space, F : Float, const N : usize> DifferentiableImpl> for Shift +where T : DifferentiableMapping, DerivativeDomain=V> { type Derivative = V; + #[inline] - 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, Derivative=V> { - type Derivative = V; - #[inline] - fn differential(&self, x : Loc) -> Self::Derivative { - self.base_fn.differential(x - &self.shift) + fn differential_impl>>(&self, x : I) -> Self::Derivative { + self.base_fn.differential(x.own() - &self.shift) } } @@ -228,46 +214,26 @@ pub base_fn : T, } -impl<'a, T, V, F : Float, C, const N : usize> Apply<&'a Loc> for Weighted -where T : for<'b> Apply<&'b Loc, Output=V>, - V : std::ops::Mul, +impl<'a, T, V, F : Float, C, const N : usize> Mapping> for Weighted +where T : Mapping, Codomain=V>, + V : Space + std::ops::Mul, C : Constant { - type Output = V; + type Codomain = V; + #[inline] - fn apply(&self, x : &'a Loc) -> Self::Output { + fn apply>>(&self, x : I) -> Self::Codomain { self.base_fn.apply(x) * self.weight.value() } } -impl<'a, T, V, F : Float, C, const N : usize> Apply> for Weighted -where T : Apply, Output=V>, - V : std::ops::Mul, - C : Constant { - type Output = V; - #[inline] - fn apply(&self, x : Loc) -> Self::Output { - self.base_fn.apply(x) * self.weight.value() - } -} - -impl<'a, T, V, F : Float, C, const N : usize> Differentiable<&'a Loc> for Weighted -where T : for<'b> Differentiable<&'b Loc, Derivative=V>, - V : std::ops::Mul, +impl<'a, T, V, F : Float, C, const N : usize> DifferentiableImpl> for Weighted +where T : DifferentiableMapping, DerivativeDomain=V>, + V : Space + std::ops::Mul, C : Constant { type Derivative = V; + #[inline] - 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, Derivative=V>, - V : std::ops::Mul, - C : Constant { - type Derivative = V; - #[inline] - fn differential(&self, x : Loc) -> Self::Derivative { + fn differential_impl>>(&self, x : I) -> Self::Derivative { self.base_fn.differential(x) * self.weight.value() } } @@ -380,21 +346,12 @@ pub T ); -impl<'a, T, F : Float, const N : usize> Apply<&'a Loc> for Normalised -where T : Norm + for<'b> Apply<&'b Loc, Output=F> { - type Output = F; +impl<'a, T, F : Float, const N : usize> Mapping> for Normalised +where T : Norm + Mapping, Codomain=F> { + type Codomain = F; + #[inline] - fn apply(&self, x : &'a Loc) -> Self::Output { - let w = self.0.norm(L1); - if w == F::ZERO { F::ZERO } else { self.0.apply(x) / w } - } -} - -impl<'a, T, F : Float, const N : usize> Apply> for Normalised -where T : Norm + Apply, Output=F> { - type Output = F; - #[inline] - fn apply(&self, x : Loc) -> Self::Output { + fn apply>>(&self, x : I) -> Self::Codomain { let w = self.0.norm(L1); if w == F::ZERO { F::ZERO } else { self.0.apply(x) / w } }