diff -r 1a38447a89fa -r 9226980e45a7 src/bisection_tree/btfn.rs --- a/src/bisection_tree/btfn.rs Sat Dec 14 09:31:27 2024 -0500 +++ b/src/bisection_tree/btfn.rs Tue Dec 31 08:30:02 2024 -0500 @@ -4,7 +4,10 @@ use std::marker::PhantomData; use std::sync::Arc; use crate::types::Float; -use crate::mapping::{Apply, Mapping, Differentiable}; +use crate::mapping::{ + Instance, Mapping, DifferentiableImpl, DifferentiableMapping, Space, + BasicDecomposition, +}; //use crate::linops::{Apply, Linear}; use crate::sets::Set; use crate::sets::Cube; @@ -40,10 +43,22 @@ } impl +Space for BTFN +where + G : SupportGenerator, + G::SupportType : LocalAnalysis, + BT : BTImpl +{ + type Decomp = BasicDecomposition; +} + +impl BTFN -where G : SupportGenerator, - G::SupportType : LocalAnalysis, - BT : BTImpl { +where + G : SupportGenerator, + G::SupportType : LocalAnalysis, + BT : BTImpl +{ /// Create a new BTFN from a support generator and a pre-initialised bisection tree. /// @@ -390,64 +405,40 @@ // Apply, Mapping, Differentiate // -impl<'a, F : Float, G, BT, V, const N : usize> Apply<&'a Loc> +impl Mapping> for BTFN -where BT : BTImpl, - G : SupportGenerator, - G::SupportType : LocalAnalysis + Apply<&'a Loc, Output = V>, - V : Sum { +where + BT : BTImpl, + G : SupportGenerator, + G::SupportType : LocalAnalysis + Mapping, Codomain = V>, + V : Sum + Space, +{ - type Output = V; + type Codomain = V; - fn apply(&self, x : &'a Loc) -> Self::Output { - self.bt.iter_at(x) - .map(|&d| self.generator.support_for(d).apply(x)).sum() + fn apply>>(&self, x : I) -> Self::Codomain { + let xc = x.cow(); + self.bt.iter_at(&*xc) + .map(|&d| self.generator.support_for(d).apply(&*xc)).sum() } } -impl Apply> +impl DifferentiableImpl> for BTFN -where BT : BTImpl, - G : SupportGenerator, - G::SupportType : LocalAnalysis + Apply, Output = V>, - V : Sum { - - type Output = V; - - fn apply(&self, x : Loc) -> Self::Output { - self.bt.iter_at(&x) - .map(|&d| self.generator.support_for(d).apply(x)).sum() - } -} - -impl<'a, F : Float, G, BT, V, const N : usize> Differentiable<&'a Loc> -for BTFN -where BT : BTImpl, - G : SupportGenerator, - G::SupportType : LocalAnalysis + Differentiable<&'a Loc, Derivative = V>, - V : Sum { +where + BT : BTImpl, + G : SupportGenerator, + G::SupportType : LocalAnalysis + + DifferentiableMapping, DerivativeDomain = V>, + V : Sum + Space, +{ type Derivative = V; - fn differential(&self, x : &'a Loc) -> Self::Derivative { - self.bt.iter_at(x) - .map(|&d| self.generator.support_for(d).differential(x)) - .sum() - } -} - -impl Differentiable> -for BTFN -where BT : BTImpl, - G : SupportGenerator, - G::SupportType : LocalAnalysis + Differentiable, Derivative = V>, - V : Sum { - - type Derivative = V; - - fn differential(&self, x : Loc) -> Self::Derivative { - self.bt.iter_at(&x) - .map(|&d| self.generator.support_for(d).differential(x)) + fn differential_impl>>(&self, x :I) -> Self::Derivative { + let xc = x.cow(); + self.bt.iter_at(&*xc) + .map(|&d| self.generator.support_for(d).differential(&*xc)) .sum() } } @@ -840,7 +831,7 @@ impl BTFN where BT : BTSearch>, G : SupportGenerator, - G::SupportType : Mapping,Codomain=F> + G::SupportType : Mapping, Codomain=F> + LocalAnalysis, N>, Cube : P2Minimise, F> {