From cdde66d277539306f0d662cc86588267e175571b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 9 Jun 2020 13:57:24 +0200 Subject: [PATCH] statistics: covariance(): avoid allocation Signed-off-by: Wolfgang Bumiller --- src/tools/statistics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/statistics.rs b/src/tools/statistics.rs index bdbea5d6..2a0e429c 100644 --- a/src/tools/statistics.rs +++ b/src/tools/statistics.rs @@ -70,11 +70,11 @@ where let mean_x = mean(x)?; let mean_y = mean(y)?; - let covariance = sum(&(0..len_x).map(|i| { + let covariance: f64 = (0..len_x).map(|i| { let x = x[i].to_f64().unwrap_or(0.0); let y = y[i].to_f64().unwrap_or(0.0); (x - mean_x)*(y - mean_y) - }).collect::>()); + }).sum(); Some(covariance/(len_x as f64)) }