diff -r d14c877e14b7 -r b3c35d16affe src/bisection_tree/btfn.rs --- a/src/bisection_tree/btfn.rs Tue Feb 20 12:33:16 2024 -0500 +++ b/src/bisection_tree/btfn.rs Mon Feb 03 19:22:16 2025 -0500 @@ -4,7 +4,10 @@ use std::marker::PhantomData; use std::sync::Arc; use crate::types::Float; -use crate::mapping::{Apply, Mapping}; +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. /// @@ -386,42 +401,52 @@ make_btfn_unaryop!(Neg, neg); - - // -// Mapping +// 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 { +where + BT : BTImpl, + G : SupportGenerator, + G::SupportType : LocalAnalysis + + DifferentiableMapping, DerivativeDomain = V>, + V : Sum + Space, +{ - type Output = V; + type Derivative = V; - fn apply(&self, x : Loc) -> Self::Output { - self.bt.iter_at(&x) - .map(|&d| self.generator.support_for(d).apply(x)).sum() + 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() } } +// +// GlobalAnalysis +// + impl GlobalAnalysis for BTFN where BT : BTImpl, @@ -480,7 +505,7 @@ /// /// `U` is the domain, generally [`Loc`]``, and `F` the type of floating point numbers. /// `Self` is generally a set of `U`, for example, [`Cube`]``. -pub trait P2Minimise : Set { +pub trait P2Minimise : Set { /// Minimise `g` over the set presented by `Self`. /// /// The function returns `(x, v)` where `x` is the minimiser `v` an approximation of `g(x)`. @@ -806,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> {