--- a/src/bisection_tree/btfn.rs Fri Apr 28 08:27:17 2023 +0300 +++ b/src/bisection_tree/btfn.rs Fri Apr 28 08:32:15 2023 +0300 @@ -4,7 +4,7 @@ use std::marker::PhantomData; use std::sync::Arc; use crate::types::Float; -use crate::mapping::{Apply, Mapping}; +use crate::mapping::{Apply, Mapping, Differentiate}; //use crate::linops::{Apply, Linear}; use crate::sets::Set; use crate::sets::Cube; @@ -386,10 +386,8 @@ make_btfn_unaryop!(Neg, neg); - - // -// Mapping +// Apply, Mapping, Differentiate // impl<'a, F : Float, G, BT, V, const N : usize> Apply<&'a Loc<F, N>> @@ -422,6 +420,42 @@ } } +impl<'a, F : Float, G, BT, V, const N : usize> Differentiate<&'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> + Differentiate<&'a Loc<F, N>, Output = V>, + V : Sum { + + type Output = V; + + fn differential(&self, x : &'a Loc<F, N>) -> Self::Output { + self.bt.iter_at(x) + .map(|&d| self.generator.support_for(d).differential(x)) + .sum() + } +} + +impl<F : Float, G, BT, V, const N : usize> Differentiate<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> + Differentiate<Loc<F, N>, Output = V>, + V : Sum { + + type Output = V; + + fn differential(&self, x : Loc<F, N>) -> Self::Output { + self.bt.iter_at(&x) + .map(|&d| self.generator.support_for(d).differential(x)) + .sum() + } +} + +// +// GlobalAnalysis +// + impl<F : Float, G, BT, const N : usize> GlobalAnalysis<F, BT::Agg> for BTFN<F, G, BT, N> where BT : BTImpl<F, N>,