Function lattice_qcd_rs::statistics::covariance_par_iter_val
source · pub fn covariance_par_iter_val<It1, It2, T>(
data_1: It1,
data_2: It2
) -> Option<T>where
T: Clone + Div<f64, Output = T> + Sum<T> + Sum<It1::Item> + Send + Mul<T, Output = T> + Sub<T, Output = T> + Zero,
It1: IndexedParallelIterator<Item = T> + Clone,
It2: IndexedParallelIterator<Item = T> + Clone,
Expand description
Computes the covariance between two [rayon::iter::IndexedParallelIterator] by value.
Returns None
if the par iters are not of the same length.
The alternative for iterators returning references is covariance_par_iter
.
Example
use lattice_qcd_rs::statistics::covariance_par_iter_val;
use rayon::prelude::*;
fn expensive_computation(input: &f64) -> f64 {
input + 1_f64
}
let vec = vec![1_f64, 2_f64, 3_f64, 4_f64];
let vec_2 = vec![1_f64, 2_f64, 3_f64];
let cov = covariance_par_iter_val(
vec.par_iter().map(|input| expensive_computation(input)),
vec_2.par_iter().map(|input| expensive_computation(input)),
);
assert!(cov.is_none());
let vec = vec![1_f64, 1_f64, 1_f64, 1_f64];
let vec_2 = vec![1_f64, 1_f64, 1_f64, 1_f64];
let cov = covariance_par_iter_val(
vec.par_iter().map(|input| expensive_computation(input)),
vec_2.par_iter().map(|input| expensive_computation(input)),
);
assert_eq!(cov, Some(0_f64));