]> git.proxmox.com Git - proxmox-backup.git/commitdiff
statistics: covariance(): avoid allocation
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 9 Jun 2020 11:57:24 +0000 (13:57 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 9 Jun 2020 11:57:27 +0000 (13:57 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/tools/statistics.rs

index bdbea5d6c41b7669c5c0b058ad32329fc11aa5a0..2a0e429c81da81fbdc09178249677a0aa58b79fc 100644 (file)
@@ -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::<Vec<f64>>());
+    }).sum();
 
     Some(covariance/(len_x as f64))
 }