T3: rayon-backed concurrency (opt-in) #2
@@ -262,17 +262,45 @@ impl<T: Time, D: Drift<T>, O: Observer<T>, K: Eq + Hash + Clone> History<T, D, O
|
|||||||
/// Note: `key(idx)` is O(n) per lookup; this method is therefore O(n²)
|
/// Note: `key(idx)` is O(n) per lookup; this method is therefore O(n²)
|
||||||
/// in the number of competitors. Acceptable for T2; T3 may optimize.
|
/// in the number of competitors. Acceptable for T2; T3 may optimize.
|
||||||
pub fn learning_curves(&self) -> HashMap<K, Vec<(T, Gaussian)>> {
|
pub fn learning_curves(&self) -> HashMap<K, Vec<(T, Gaussian)>> {
|
||||||
let mut data: HashMap<K, Vec<(T, Gaussian)>> = HashMap::new();
|
#[cfg(feature = "rayon")]
|
||||||
for slice in &self.time_slices {
|
{
|
||||||
for (idx, skill) in slice.skills.iter() {
|
use rayon::prelude::*;
|
||||||
if let Some(key) = self.keys.key(idx).cloned() {
|
|
||||||
data.entry(key)
|
let per_slice: Vec<Vec<(Index, T, Gaussian)>> = self
|
||||||
.or_default()
|
.time_slices
|
||||||
.push((slice.time, skill.posterior()));
|
.par_iter()
|
||||||
|
.map(|ts| {
|
||||||
|
ts.skills
|
||||||
|
.iter()
|
||||||
|
.map(|(idx, sk)| (idx, ts.time, sk.posterior()))
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut data: HashMap<K, Vec<(T, Gaussian)>> = HashMap::new();
|
||||||
|
for slice_contrib in per_slice {
|
||||||
|
for (idx, t, g) in slice_contrib {
|
||||||
|
if let Some(key) = self.keys.key(idx).cloned() {
|
||||||
|
data.entry(key).or_default().push((t, g));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "rayon"))]
|
||||||
|
{
|
||||||
|
let mut data: HashMap<K, Vec<(T, Gaussian)>> = HashMap::new();
|
||||||
|
for slice in &self.time_slices {
|
||||||
|
for (idx, skill) in slice.skills.iter() {
|
||||||
|
if let Some(key) = self.keys.key(idx).cloned() {
|
||||||
|
data.entry(key)
|
||||||
|
.or_default()
|
||||||
|
.push((slice.time, skill.posterior()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data
|
||||||
}
|
}
|
||||||
data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Skill estimate at the latest time slice the competitor appears in.
|
/// Skill estimate at the latest time slice the competitor appears in.
|
||||||
|
|||||||
Reference in New Issue
Block a user