--- a/src/bisection_tree/either.rs Tue Feb 20 12:33:16 2024 -0500 +++ b/src/bisection_tree/either.rs Mon Feb 03 19:22:16 2025 -0500 @@ -3,8 +3,14 @@ use std::sync::Arc; use crate::types::*; -use crate::mapping::Apply; -use crate::iter::{Mappable,MapF,MapZ}; +use crate::mapping::{ + Instance, + Mapping, + DifferentiableImpl, + DifferentiableMapping, + Space, +}; +use crate::iter::{Mappable, MapF, MapZ}; use crate::sets::Cube; use crate::loc::Loc; @@ -177,12 +183,17 @@ } } -impl<F, S1, S2, X> Apply<X> for EitherSupport<S1, S2> -where S1 : Apply<X, Output=F>, - S2 : Apply<X, Output=F> { - type Output = F; +impl<F, S1, S2, X> Mapping<X> for EitherSupport<S1, S2> +where + F : Space, + X : Space, + S1 : Mapping<X, Codomain=F>, + S2 : Mapping<X, Codomain=F>, +{ + type Codomain = F; + #[inline] - fn apply(&self, x : X) -> F { + fn apply<I : Instance<X>>(&self, x : I) -> F { match self { EitherSupport::Left(ref a) => a.apply(x), EitherSupport::Right(ref b) => b.apply(x), @@ -190,6 +201,24 @@ } } +impl<X, S1, S2, O> DifferentiableImpl<X> for EitherSupport<S1, S2> +where + O : Space, + X : Space, + S1 : DifferentiableMapping<X, DerivativeDomain=O>, + S2 : DifferentiableMapping<X, DerivativeDomain=O>, +{ + type Derivative = O; + + #[inline] + fn differential_impl<I : Instance<X>>(&self, x : I) -> O { + match self { + EitherSupport::Left(ref a) => a.differential(x), + EitherSupport::Right(ref b) => b.differential(x), + } + } +} + macro_rules! make_either_scalarop_rhs { ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => { impl<F : Float, G1, G2>