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<f64>, 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.
This commit is contained in:
2026-04-24 13:56:29 +02:00
parent f3c074c24c
commit ab8e1fd684

View File

@@ -332,10 +332,23 @@ impl<T: Time, D: Drift<T>, O: Observer<T>, K: Eq + Hash + Clone> History<T, D, O
} }
pub(crate) fn log_evidence_internal(&mut self, forward: bool, targets: &[Index]) -> f64 { pub(crate) fn log_evidence_internal(&mut self, forward: bool, targets: &[Index]) -> f64 {
self.time_slices #[cfg(feature = "rayon")]
.iter() {
.map(|ts| ts.log_evidence(self.online, targets, forward, &self.agents)) use rayon::prelude::*;
.sum() let per_slice: Vec<f64> = 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. /// Total log-evidence across the history.