src/bisection_tree/btfn.rs

branch
dev
changeset 27
00029c20c0ee
parent 13
465fa2121ccb
child 29
7fd0984743b5
equal deleted inserted replaced
26:cc68841e758f 27:00029c20c0ee
2 use numeric_literals::replace_float_literals; 2 use numeric_literals::replace_float_literals;
3 use std::iter::Sum; 3 use std::iter::Sum;
4 use std::marker::PhantomData; 4 use std::marker::PhantomData;
5 use std::sync::Arc; 5 use std::sync::Arc;
6 use crate::types::Float; 6 use crate::types::Float;
7 use crate::mapping::{Apply, Mapping}; 7 use crate::mapping::{Apply, Mapping, Differentiate};
8 //use crate::linops::{Apply, Linear}; 8 //use crate::linops::{Apply, Linear};
9 use crate::sets::Set; 9 use crate::sets::Set;
10 use crate::sets::Cube; 10 use crate::sets::Cube;
11 use crate::loc::Loc; 11 use crate::loc::Loc;
12 use super::support::*; 12 use super::support::*;
384 } 384 }
385 } 385 }
386 386
387 make_btfn_unaryop!(Neg, neg); 387 make_btfn_unaryop!(Neg, neg);
388 388
389
390
391 // 389 //
392 // Mapping 390 // Apply, Mapping, Differentiate
393 // 391 //
394 392
395 impl<'a, F : Float, G, BT, V, const N : usize> Apply<&'a Loc<F, N>> 393 impl<'a, F : Float, G, BT, V, const N : usize> Apply<&'a Loc<F, N>>
396 for BTFN<F, G, BT, N> 394 for BTFN<F, G, BT, N>
397 where BT : BTImpl<F, N>, 395 where BT : BTImpl<F, N>,
419 fn apply(&self, x : Loc<F, N>) -> Self::Output { 417 fn apply(&self, x : Loc<F, N>) -> Self::Output {
420 self.bt.iter_at(&x) 418 self.bt.iter_at(&x)
421 .map(|&d| self.generator.support_for(d).apply(x)).sum() 419 .map(|&d| self.generator.support_for(d).apply(x)).sum()
422 } 420 }
423 } 421 }
422
423 impl<'a, F : Float, G, BT, V, const N : usize> Differentiate<&'a Loc<F, N>>
424 for BTFN<F, G, BT, N>
425 where BT : BTImpl<F, N>,
426 G : SupportGenerator<F, N, Id=BT::Data>,
427 G::SupportType : LocalAnalysis<F, BT::Agg, N> + Differentiate<&'a Loc<F, N>, Output = V>,
428 V : Sum {
429
430 type Output = V;
431
432 fn differential(&self, x : &'a Loc<F, N>) -> Self::Output {
433 self.bt.iter_at(x)
434 .map(|&d| self.generator.support_for(d).differential(x))
435 .sum()
436 }
437 }
438
439 impl<F : Float, G, BT, V, const N : usize> Differentiate<Loc<F, N>>
440 for BTFN<F, G, BT, N>
441 where BT : BTImpl<F, N>,
442 G : SupportGenerator<F, N, Id=BT::Data>,
443 G::SupportType : LocalAnalysis<F, BT::Agg, N> + Differentiate<Loc<F, N>, Output = V>,
444 V : Sum {
445
446 type Output = V;
447
448 fn differential(&self, x : Loc<F, N>) -> Self::Output {
449 self.bt.iter_at(&x)
450 .map(|&d| self.generator.support_for(d).differential(x))
451 .sum()
452 }
453 }
454
455 //
456 // GlobalAnalysis
457 //
424 458
425 impl<F : Float, G, BT, const N : usize> GlobalAnalysis<F, BT::Agg> 459 impl<F : Float, G, BT, const N : usize> GlobalAnalysis<F, BT::Agg>
426 for BTFN<F, G, BT, N> 460 for BTFN<F, G, BT, N>
427 where BT : BTImpl<F, N>, 461 where BT : BTImpl<F, N>,
428 G : SupportGenerator<F, N, Id=BT::Data>, 462 G : SupportGenerator<F, N, Id=BT::Data>,

mercurial