src/bisection_tree/either.rs

branch
dev
changeset 81
d2acaaddd9af
parent 47
a0db98c16ab5
--- a/src/bisection_tree/either.rs	Sun Nov 10 09:02:57 2024 -0500
+++ b/src/bisection_tree/either.rs	Tue Dec 31 09:12:43 2024 -0500
@@ -29,12 +29,18 @@
     Right(B),
 }
 
+impl<A, B, F : Num> HasScalarField for EitherSupport<A, B>
+where A : HasScalarField<Field = F>,
+      B : HasScalarField<Field = F> {
+    type Field = F;
+}
+
 // We need type alias bounds to access associate types.
 #[allow(type_alias_bounds)]
 type BothAllDataIter<
-    'a, F,
-    G1 : SupportGenerator<F, N>,
-    G2 : SupportGenerator<F, N>,
+    'a,
+    G1 : SupportGenerator<N>,
+    G2 : SupportGenerator<N, RealField = G1::RealField>,
     const N : usize
 > = Chain<
     MapF<G1::AllDataIter<'a>, (usize, EitherSupport<G1::SupportType, G2::SupportType>)>,
@@ -46,8 +52,8 @@
     #[inline]
     fn map_left<F : Float, const N : usize>((d, support) : (G1::Id, G1::SupportType))
     -> (usize, EitherSupport<G1::SupportType, G2::SupportType>)
-    where G1 : SupportGenerator<F, N, Id=usize>,
-          G2 : SupportGenerator<F, N, Id=usize> {
+    where G1 : SupportGenerator<N, Id=usize, RealField =F>,
+          G2 : SupportGenerator<N, Id=usize, RealField = F> {
 
         let id : usize = d.into();
         (id.into(), EitherSupport::Left(support))
@@ -57,8 +63,8 @@
     #[inline]
     fn map_right<F : Float, const N : usize>(n0 : &usize, (d, support) : (G2::Id, G2::SupportType))
     -> (usize, EitherSupport<G1::SupportType, G2::SupportType>)
-    where G1 : SupportGenerator<F, N, Id=usize>,
-          G2 : SupportGenerator<F, N, Id=usize> {
+    where G1 : SupportGenerator<N, Id=usize, RealField = F>,
+          G2 : SupportGenerator<N, Id=usize, RealField = F> {
 
         let id : usize = d.into();
         ((n0+id).into(), EitherSupport::Right(support))
@@ -70,8 +76,8 @@
     #[inline]
     pub(super) fn all_left_data<F : Float, const N : usize>(&self)
     -> MapF<G1::AllDataIter<'_>, (usize, EitherSupport<G1::SupportType, G2::SupportType>)>
-    where G1 : SupportGenerator<F, N, Id=usize>,
-          G2 : SupportGenerator<F, N, Id=usize> {
+    where G1 : SupportGenerator<N, Id=usize, RealField = F>,
+          G2 : SupportGenerator<N, Id=usize, RealField = F> {
         self.0.all_data().mapF(Self::map_left)
     }
 
@@ -81,22 +87,29 @@
     #[inline]
     pub(super) fn all_right_data<F : Float, const N : usize>(&self)
     -> MapZ<G2::AllDataIter<'_>, usize, (usize, EitherSupport<G1::SupportType, G2::SupportType>)>
-    where G1 : SupportGenerator<F, N, Id=usize>,
-          G2 : SupportGenerator<F, N, Id=usize> {
+    where G1 : SupportGenerator<N, Id=usize, RealField=F>,
+          G2 : SupportGenerator<N, Id=usize, RealField=F> {
         let n0 = self.0.support_count();
         self.1.all_data().mapZ(n0, Self::map_right)
     }
 }
 
+impl<F : Float, G1, G2> HasScalarField for BothGenerators<G1, G2>
+where G1 : HasScalarField<Field=F>,
+      G2 : HasScalarField<Field=F> {
+    type Field = F;
+}
+
 impl<F : Float, G1, G2, const N : usize>
-SupportGenerator<F, N>
+SupportGenerator<N>
 for BothGenerators<G1, G2>
-where G1 : SupportGenerator<F, N, Id=usize>,
-      G2 : SupportGenerator<F, N, Id=usize> {
+where G1 : SupportGenerator<N, Id=usize> + HasRealField<RealField=F>,
+      G2 : SupportGenerator<N, Id=usize> + HasRealField<RealField=F>,
+      Self : HasRealField<RealField = F> {
 
     type Id = usize;
     type SupportType = EitherSupport<G1::SupportType, G2::SupportType>;
-    type AllDataIter<'a> = BothAllDataIter<'a, F, G1, G2, N> where G1 : 'a, G2 : 'a;
+    type AllDataIter<'a> = BothAllDataIter<'a, G1, G2, N> where G1 : 'a, G2 : 'a;
 
     #[inline]
     fn support_for(&self,  id : Self::Id)
@@ -120,9 +133,9 @@
     }
 }
 
-impl<F: Float, S1, S2, const N : usize> Support<F, N> for EitherSupport<S1, S2>
-where S1 : Support<F, N>,
-      S2 : Support<F, N> {
+impl<F: Float, S1, S2, const N : usize> Support<N> for EitherSupport<S1, S2>
+where S1 : Support<N, RealField = F>,
+      S2 : Support<N, RealField = F> {
 
     #[inline]
     fn support_hint(&self) -> Cube<F,N> {
@@ -149,10 +162,11 @@
     }
 }
 
-impl<F : Float, A, S1, S2, const N : usize> LocalAnalysis<F, A, N> for EitherSupport<S1, S2>
+impl<F : Float, A, S1, S2, const N : usize> LocalAnalysis<A, Cube<F, N>>
+for EitherSupport<S1, S2>
 where A : Aggregator,
-      S1 : LocalAnalysis<F, A, N>,
-      S2 : LocalAnalysis<F, A, N>, {
+      S1 : LocalAnalysis<A, Cube<F, N>>,
+      S2 : LocalAnalysis<A, Cube<F, N>> {
 
     #[inline]
     fn local_analysis(&self, cube : &Cube<F, N>) -> A {
@@ -163,10 +177,10 @@
     }
 }
 
-impl<F : Float, A, S1, S2> GlobalAnalysis<F, A> for EitherSupport<S1, S2>
+impl<A, S1, S2> GlobalAnalysis<A> for EitherSupport<S1, S2>
 where A : Aggregator,
-      S1 : GlobalAnalysis<F, A>,
-      S2 : GlobalAnalysis<F, A>, {
+      S1 : GlobalAnalysis<A>,
+      S2 : GlobalAnalysis<A>, {
 
     #[inline]
     fn global_analysis(&self) -> A {
@@ -190,9 +204,9 @@
     }
 }
 
-impl<F, S1, S2, X> Differentiable<X> for EitherSupport<S1, S2>
-where S1 : Differentiable<X, Derivative=F>,
-      S2 : Differentiable<X, Derivative=F> {
+impl<F : Float, S1, S2, X> Differentiable<X> for EitherSupport<S1, S2>
+where S1 : Differentiable<X, Derivative=F, RealField=F>,
+      S2 : Differentiable<X, Derivative=F, RealField=F> {
     type Derivative = F;
     #[inline]
     fn differential(&self, x : X) -> F {

mercurial