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:
@@ -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 {
|
||||
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<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.
|
||||
|
||||
Reference in New Issue
Block a user