--- 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<F : Float, G, BT, const N : usize> +Space for BTFN<F, G, BT, N> +where + G : SupportGenerator<F, N, Id=BT::Data>, + G::SupportType : LocalAnalysis<F, BT::Agg, N>, + BT : BTImpl<F, N> +{ + type Decomp = BasicDecomposition; +} + +impl<F : Float, G, BT, const N : usize> BTFN<F, G, BT, N> -where G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : LocalAnalysis<F, BT::Agg, N>, - BT : BTImpl<F, N> { +where + G : SupportGenerator<F, N, Id=BT::Data>, + G::SupportType : LocalAnalysis<F, BT::Agg, N>, + BT : BTImpl<F, N> +{ /// 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<F, N>> +impl<F : Float, G, BT, V, const N : usize> Mapping<Loc<F, N>> for BTFN<F, G, BT, N> -where BT : BTImpl<F, N>, - G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : LocalAnalysis<F, BT::Agg, N> + Apply<&'a Loc<F, N>, Output = V>, - V : Sum { +where + BT : BTImpl<F, N>, + G : SupportGenerator<F, N, Id=BT::Data>, + G::SupportType : LocalAnalysis<F, BT::Agg, N> + Mapping<Loc<F, N>, Codomain = V>, + V : Sum + Space, +{ - type Output = V; + type Codomain = V; - fn apply(&self, x : &'a Loc<F, N>) -> Self::Output { - self.bt.iter_at(x) - .map(|&d| self.generator.support_for(d).apply(x)).sum() + fn apply<I : Instance<Loc<F,N>>>(&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<F : Float, G, BT, V, const N : usize> Apply<Loc<F, N>> +impl<F : Float, G, BT, V, const N : usize> DifferentiableImpl<Loc<F, N>> for BTFN<F, G, BT, N> -where BT : BTImpl<F, N>, - G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : LocalAnalysis<F, BT::Agg, N> + Apply<Loc<F, N>, Output = V>, - V : Sum { - - type Output = V; - - fn apply(&self, x : Loc<F, N>) -> 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<F, N>> -for BTFN<F, G, BT, N> -where BT : BTImpl<F, N>, - G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : LocalAnalysis<F, BT::Agg, N> + Differentiable<&'a Loc<F, N>, Derivative = V>, - V : Sum { +where + BT : BTImpl<F, N>, + G : SupportGenerator<F, N, Id=BT::Data>, + G::SupportType : LocalAnalysis<F, BT::Agg, N> + + DifferentiableMapping<Loc<F, N>, DerivativeDomain = V>, + V : Sum + Space, +{ type Derivative = V; - fn differential(&self, x : &'a Loc<F, N>) -> Self::Derivative { - self.bt.iter_at(x) - .map(|&d| self.generator.support_for(d).differential(x)) - .sum() - } -} - -impl<F : Float, G, BT, V, const N : usize> Differentiable<Loc<F, N>> -for BTFN<F, G, BT, N> -where BT : BTImpl<F, N>, - G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : LocalAnalysis<F, BT::Agg, N> + Differentiable<Loc<F, N>, Derivative = V>, - V : Sum { - - type Derivative = V; - - fn differential(&self, x : Loc<F, N>) -> Self::Derivative { - self.bt.iter_at(&x) - .map(|&d| self.generator.support_for(d).differential(x)) + fn differential_impl<I : Instance<Loc<F, N>>>(&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<F : Float, G, BT, const N : usize> BTFN<F, G, BT, N> where BT : BTSearch<F, N, Agg=Bounds<F>>, G : SupportGenerator<F, N, Id=BT::Data>, - G::SupportType : Mapping<Loc<F, N>,Codomain=F> + G::SupportType : Mapping<Loc<F, N>, Codomain=F> + LocalAnalysis<F, Bounds<F>, N>, Cube<F, N> : P2Minimise<Loc<F, N>, F> {