src/bisection_tree/refine.rs

changeset 199
32f5062ee477
parent 124
6aa955ad8122
--- a/src/bisection_tree/refine.rs	Fri May 15 14:46:30 2026 -0500
+++ b/src/bisection_tree/refine.rs	Tue Jul 07 11:53:22 2026 +0300
@@ -1,12 +1,12 @@
 use super::aggregator::*;
 use super::bt::*;
 use super::support::*;
-use crate::nanleast::NaNLeast;
 use crate::parallelism::TaskBudget;
 use crate::parallelism::{thread_pool, thread_pool_size};
 use crate::sets::Cube;
 use crate::types::*;
-use std::cmp::{max, Ord, Ordering, Ordering::*, PartialOrd};
+use num_traits::float::TotalOrder;
+use std::cmp::{Ord, Ordering, Ordering::*, PartialOrd};
 use std::collections::BinaryHeap;
 use std::marker::PhantomData;
 use std::sync::{Arc, Condvar, Mutex, MutexGuard};
@@ -19,7 +19,11 @@
 pub trait AggregatorSorting: Sync + Send + 'static {
     // Priority
     type Agg: Aggregator;
-    type Sort: Ord + Copy + std::fmt::Debug + Sync + Send;
+    /// This is temporarily a Float, after removal of NanLeast, to use [
+    /// `num_traits::float::TotalOrder`] and [`num_traits::float::Float::max`].
+    /// It should be generalised by introducing a general PseudoTotalOrder trait
+    /// (because Rust's standard one is not implemented for `Float`s)
+    type Sort: Float + Copy + std::fmt::Debug + Sync + Send;
 
     /// Returns lower sorting key
     fn sort_lower(aggregator: &Self::Agg) -> Self::Sort;
@@ -43,41 +47,41 @@
 
 impl<F: Float> AggregatorSorting for UpperBoundSorting<F> {
     type Agg = Bounds<F>;
-    type Sort = NaNLeast<F>;
+    type Sort = F;
 
     #[inline]
     fn sort_lower(aggregator: &Bounds<F>) -> Self::Sort {
-        NaNLeast(aggregator.lower())
+        aggregator.lower()
     }
 
     #[inline]
     fn sort_upper(aggregator: &Bounds<F>) -> Self::Sort {
-        NaNLeast(aggregator.upper())
+        aggregator.upper()
     }
 
     #[inline]
     fn bottom() -> Self::Sort {
-        NaNLeast(F::NEG_INFINITY)
+        F::NEG_INFINITY
     }
 }
 
 impl<F: Float> AggregatorSorting for LowerBoundSorting<F> {
     type Agg = Bounds<F>;
-    type Sort = NaNLeast<F>;
+    type Sort = F;
 
     #[inline]
     fn sort_upper(aggregator: &Bounds<F>) -> Self::Sort {
-        NaNLeast(-aggregator.lower())
+        -aggregator.lower()
     }
 
     #[inline]
     fn sort_lower(aggregator: &Bounds<F>) -> Self::Sort {
-        NaNLeast(-aggregator.upper())
+        -aggregator.upper()
     }
 
     #[inline]
     fn bottom() -> Self::Sort {
-        NaNLeast(F::NEG_INFINITY)
+        F::NEG_INFINITY
     }
 }
 
@@ -240,9 +244,11 @@
     #[inline]
     fn cmp(&self, other: &Self) -> Ordering {
         self.with_aggregator(|agg1| {
-            other.with_aggregator(|agg2| match S::sort_upper(agg1).cmp(&S::sort_upper(agg2)) {
-                Equal => S::sort_lower(agg1).cmp(&S::sort_lower(agg2)),
-                order => order,
+            other.with_aggregator(|agg2| {
+                match S::sort_upper(agg1).total_cmp(&S::sort_upper(agg2)) {
+                    Equal => S::sort_lower(agg1).total_cmp(&S::sort_lower(agg2)),
+                    order => order,
+                }
             })
         })
     }
@@ -318,12 +324,7 @@
     {
         // Insert all subnodes into the refinement heap.
         for (node, cube) in self.nodes_and_cubes_mut(&domain) {
-            container.push(RefinementInfo {
-                cube,
-                node,
-                refiner_info: None,
-                sorting: PhantomData,
-            });
+            container.push(RefinementInfo { cube, node, refiner_info: None, sorting: PhantomData });
         }
     }
 }
@@ -540,7 +541,12 @@
         // Do priority queue maintenance
         if container.insert_counter > container.heap_prune_threshold {
             // Make sure glb is good.
-            match container.heap.iter().map(|ri| ri.sort_lower()).reduce(max) {
+            match container
+                .heap
+                .iter()
+                .map(|ri| ri.sort_lower())
+                .reduce(num_traits::Float::max)
+            {
                 Some(glb) => {
                     container.glb = glb;
                     // Prune

mercurial