diff -r 495448cca603 -r 6aa955ad8122 src/bisection_tree/bt.rs --- a/src/bisection_tree/bt.rs Thu May 01 08:40:33 2025 -0500 +++ b/src/bisection_tree/bt.rs Thu May 01 13:06:58 2025 -0500 @@ -51,7 +51,7 @@ #[derive(Clone, Debug)] pub(super) struct Branches { /// Point for subdivision of the (unstored) [`Cube`] corresponding to the node. - pub(super) branch_at: Loc, + pub(super) branch_at: Loc, /// Subnodes pub(super) nodes: [Node; P], } @@ -184,7 +184,7 @@ /// /// This only takes the branch subdivision point $d$ into account, so is always succesfull. /// Thus, for this point, each branch corresponds to a quadrant of $ℝ^N$ relative to $d$. - fn get_node_index(&self, x: &Loc) -> usize { + fn get_node_index(&self, x: &Loc) -> usize { izip!(0..P, x.iter(), self.branch_at.iter()) .map(|(i, x_i, branch_i)| if x_i > branch_i { 1 << i } else { 0 }) .sum() @@ -195,25 +195,25 @@ /// This only takes the branch subdivision point $d$ into account, so is always succesfull. /// Thus, for this point, each branch corresponds to a quadrant of $ℝ^N$ relative to $d$. #[inline] - fn get_node(&self, x: &Loc) -> &Node { + fn get_node(&self, x: &Loc) -> &Node { &self.nodes[self.get_node_index(x)] } } /// An iterator over the $P=2^N$ subcubes of a [`Cube`] subdivided at a point `d`. pub(super) struct SubcubeIter<'b, F: Float, const N: usize, const P: usize> { - domain: &'b Cube, - branch_at: Loc, + domain: &'b Cube, + branch_at: Loc, index: usize, } /// Returns the `i`:th subcube of `domain` subdivided at `branch_at`. #[inline] fn get_subcube( - branch_at: &Loc, - domain: &Cube, + branch_at: &Loc, + domain: &Cube, i: usize, -) -> Cube { +) -> Cube { map2_indexed(branch_at, domain, move |j, &branch, &[start, end]| { if i & (1 << j) != 0 { [branch, end] @@ -225,7 +225,7 @@ } impl<'a, 'b, F: Float, const N: usize, const P: usize> Iterator for SubcubeIter<'b, F, N, P> { - type Item = Cube; + type Item = Cube; #[inline] fn next(&mut self) -> Option { if self.index < P { @@ -246,8 +246,8 @@ { /// Creates a new node branching structure, subdividing `domain` based on the /// [hint][Support::support_hint] of `support`. - pub(super) fn new_with + Support>( - domain: &Cube, + pub(super) fn new_with + Support>( + domain: &Cube, support: &S, ) -> Self { let hint = support.bisection_hint(domain); @@ -272,7 +272,7 @@ /// Returns an iterator over the subcubes of `domain` subdivided at the branching point /// of `self`. #[inline] - pub(super) fn iter_subcubes<'b>(&self, domain: &'b Cube) -> SubcubeIter<'b, F, N, P> { + pub(super) fn iter_subcubes<'b>(&self, domain: &'b Cube) -> SubcubeIter<'b, F, N, P> { SubcubeIter { domain: domain, branch_at: self.branch_at, @@ -283,7 +283,7 @@ /* /// Returns an iterator over all nodes and corresponding subcubes of `self`. #[inline] - pub(super) fn nodes_and_cubes<'a, 'b>(&'a self, domain : &'b Cube) + pub(super) fn nodes_and_cubes<'a, 'b>(&'a self, domain : &'b Cube) -> std::iter::Zip>, SubcubeIter<'b, F, N, P>> { self.nodes.iter().zip(self.iter_subcubes(domain)) } @@ -293,7 +293,7 @@ #[inline] pub(super) fn nodes_and_cubes_mut<'a, 'b>( &'a mut self, - domain: &'b Cube, + domain: &'b Cube, ) -> std::iter::Zip>, SubcubeIter<'b, F, N, P>> { let subcube_iter = self.iter_subcubes(domain); self.nodes.iter_mut().zip(subcube_iter) @@ -303,10 +303,10 @@ #[inline] fn recurse<'scope, 'smaller, 'refs>( &'smaller mut self, - domain: &'smaller Cube, + domain: &'smaller Cube, task_budget: TaskBudget<'scope, 'refs>, - guard: impl Fn(&Node, &Cube) -> bool + Send + 'smaller, - mut f: impl for<'a> FnMut(&mut Node, &Cube, TaskBudget<'smaller, 'a>) + guard: impl Fn(&Node, &Cube) -> bool + Send + 'smaller, + mut f: impl for<'a> FnMut(&mut Node, &Cube, TaskBudget<'smaller, 'a>) + Send + Copy + 'smaller, @@ -332,9 +332,9 @@ /// * `support` is the [`Support`] that is used determine with which subcubes of `domain` /// (at subdivision depth `new_leaf_depth`) the data `d` is to be associated with. /// - pub(super) fn insert<'refs, 'scope, M: Depth, S: LocalAnalysis + Support>( + pub(super) fn insert<'refs, 'scope, M: Depth, S: LocalAnalysis + Support>( &mut self, - domain: &Cube, + domain: &Cube, d: D, new_leaf_depth: M, support: &S, @@ -360,11 +360,11 @@ pub(super) fn convert_aggregator( self, generator: &G, - domain: &Cube, + domain: &Cube, ) -> Branches where ANew: Aggregator, - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis, { let branch_at = self.branch_at; @@ -387,10 +387,10 @@ pub(super) fn refresh_aggregator<'refs, 'scope, G>( &mut self, generator: &G, - domain: &Cube, + domain: &Cube, task_budget: TaskBudget<'scope, 'refs>, ) where - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis, { self.recurse( @@ -422,7 +422,7 @@ /* /// Get leaf data #[inline] - pub(super) fn get_leaf_data(&self, x : &Loc) -> Option<&Vec> { + pub(super) fn get_leaf_data(&self, x : &Loc) -> Option<&Vec> { match self.data { NodeOption::Uninitialised => None, NodeOption::Leaf(ref data) => Some(data), @@ -432,7 +432,7 @@ /// Get leaf data iterator #[inline] - pub(super) fn get_leaf_data_iter(&self, x: &Loc) -> Option> { + pub(super) fn get_leaf_data_iter(&self, x: &Loc) -> Option> { match self.data { NodeOption::Uninitialised => None, NodeOption::Leaf(ref data) => Some(data.iter()), @@ -459,9 +459,9 @@ /// If `self` is a [`NodeOption::Branches`], the data is passed to branches whose subcubes /// `support` intersects. If an [`NodeOption::Uninitialised`] node is encountered, a new leaf is /// created at a minimum depth of `new_leaf_depth`. - pub(super) fn insert<'refs, 'scope, M: Depth, S: LocalAnalysis + Support>( + pub(super) fn insert<'refs, 'scope, M: Depth, S: LocalAnalysis + Support>( &mut self, - domain: &Cube, + domain: &Cube, d: D, new_leaf_depth: M, support: &S, @@ -515,11 +515,11 @@ pub(super) fn convert_aggregator( mut self, generator: &G, - domain: &Cube, + domain: &Cube, ) -> Node where ANew: Aggregator, - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis, { // The mem::replace is needed due to the [`Drop`] implementation to extract self.data. @@ -561,10 +561,10 @@ pub(super) fn refresh_aggregator<'refs, 'scope, G>( &mut self, generator: &G, - domain: &Cube, + domain: &Cube, task_budget: TaskBudget<'scope, 'refs>, ) where - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis, { match &mut self.data { @@ -610,7 +610,7 @@ /// Basic interface to a [`BT`] bisection tree. /// /// Further routines are provided by the [`BTSearch`][super::refine::BTSearch] trait. -pub trait BTImpl: +pub trait BTImpl: std::fmt::Debug + Clone + GlobalAnalysis { /// The data type stored in the tree @@ -621,7 +621,7 @@ /// of the tree. type Agg: Aggregator; /// The type of the tree with the aggregator converted to `ANew`. - type Converted: BTImpl + type Converted: BTImpl where ANew: Aggregator; @@ -629,7 +629,7 @@ /// /// Every leaf node of the tree that intersects the `support` will contain a copy of /// `d`. - fn insert + Support>( + fn insert + Support>( &mut self, d: Self::Data, support: &S, @@ -642,7 +642,7 @@ fn convert_aggregator(self, generator: &G) -> Self::Converted where ANew: Aggregator, - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis; /// Refreshes the aggregator of the three after possible changes to the support generator. @@ -651,19 +651,19 @@ /// into corresponding [`Support`]s. fn refresh_aggregator(&mut self, generator: &G) where - G: SupportGenerator, + G: SupportGenerator, G::SupportType: LocalAnalysis; /// Returns an iterator over all [`Self::Data`] items at the point `x` of the domain. - fn iter_at(&self, x: &Loc) -> std::slice::Iter<'_, Self::Data>; + fn iter_at(&self, x: &Loc) -> std::slice::Iter<'_, Self::Data>; /* /// Returns all [`Self::Data`] items at the point `x` of the domain. - fn data_at(&self, x : &Loc) -> Arc>; + fn data_at(&self, x : &Loc) -> Arc>; */ /// Create a new tree on `domain` of indicated `depth`. - fn new(domain: Cube, depth: Self::Depth) -> Self; + fn new(domain: Cube, depth: Self::Depth) -> Self; } /// The main bisection tree structure. @@ -679,7 +679,7 @@ /// The depth of the tree (initial, before refinement) pub(super) depth: M, /// The domain of the toplevel node - pub(super) domain: Cube, + pub(super) domain: Cube, /// The toplevel node of the tree pub(super) topnode: >::Node, } @@ -693,7 +693,7 @@ type Node = Node; } - impl BTImpl for BT + impl BTImpl<$n, F> for BT where M : Depth, F : Float, D : 'static + Copy + Send + Sync + std::fmt::Debug, @@ -703,7 +703,7 @@ type Agg = A; type Converted = BT where ANew : Aggregator; - fn insert + Support>( + fn insert + Support< $n, F>>( &mut self, d : D, support : &S @@ -721,7 +721,7 @@ fn convert_aggregator(self, generator : &G) -> Self::Converted where ANew : Aggregator, - G : SupportGenerator, + G : SupportGenerator< $n, F, Id=D>, G::SupportType : LocalAnalysis { let topnode = self.topnode.convert_aggregator(generator, &self.domain); @@ -733,22 +733,22 @@ } fn refresh_aggregator(&mut self, generator : &G) - where G : SupportGenerator, + where G : SupportGenerator< $n, F, Id=Self::Data>, G::SupportType : LocalAnalysis { with_task_budget(|task_budget| self.topnode.refresh_aggregator(generator, &self.domain, task_budget) ) } - /*fn data_at(&self, x : &Loc) -> Arc> { + /*fn data_at(&self, x : &Loc<$n, F>) -> Arc> { self.topnode.get_leaf_data(x).unwrap_or_else(|| Arc::new(Vec::new())) }*/ - fn iter_at(&self, x : &Loc) -> std::slice::Iter<'_, D> { + fn iter_at(&self, x : &Loc<$n, F>) -> std::slice::Iter<'_, D> { self.topnode.get_leaf_data_iter(x).unwrap_or_else(|| [].iter()) } - fn new(domain : Cube, depth : M) -> Self { + fn new(domain : Cube<$n, F>, depth : M) -> Self { BT { depth : depth, domain : domain,