From ab8e1fd68403f81caa8890ec867e0d8894d727b3 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Fri, 24 Apr 2026 13:56:29 +0200 Subject: [PATCH] feat(history): parallel log_evidence with deterministic sum Per-slice log_evidence contribution computed in parallel under --features rayon; final reduction is sequential .into_iter().sum() on Vec, preserving slice order so the sum is bit-identical to the sequential T2 baseline. Essential for the T3 acceptance criterion of identical posteriors across RAYON_NUM_THREADS values. Part of T3. --- src/history.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/history.rs b/src/history.rs index 920469c..6d4439c 100644 --- a/src/history.rs +++ b/src/history.rs @@ -332,10 +332,23 @@ impl, O: Observer, K: Eq + Hash + Clone> History f64 { - self.time_slices - .iter() - .map(|ts| ts.log_evidence(self.online, targets, forward, &self.agents)) - .sum() + #[cfg(feature = "rayon")] + { + use rayon::prelude::*; + let per_slice: Vec = self + .time_slices + .par_iter() + .map(|ts| ts.log_evidence(self.online, targets, forward, &self.agents)) + .collect(); + per_slice.into_iter().sum() + } + #[cfg(not(feature = "rayon"))] + { + self.time_slices + .iter() + .map(|ts| ts.log_evidence(self.online, targets, forward, &self.agents)) + .sum() + } } /// Total log-evidence across the history.