Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ba5f35

Browse files
committedApr 24, 2019
deviation: fix definition of sq_l2_dist
1 parent 8221576 commit 9ba5f35

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎src/deviation.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ where
6161

6262
Zip::from(self).and(other).apply(|self_i, other_i| {
6363
let (a, b) = (self_i.clone(), other_i.clone());
64-
r += (a - b).abs();
64+
let abs_diff = (a - b).abs();
65+
r += abs_diff.clone() * abs_diff;
6566
});
6667

6768
r
@@ -79,6 +80,7 @@ where
7980
mod tests {
8081
use super::*;
8182
use ndarray::array;
83+
use num_traits::Pow;
8284

8385
#[test]
8486
fn test_count_eq() {
@@ -111,12 +113,12 @@ mod tests {
111113
let a = array![1., 2., 3., 4., 5., 6., 7.];
112114
let b = array![1., 3., 3., 4., 6., 7., 8.];
113115

114-
assert_eq!(a.sq_l2_dist(&b), (&a - &b).mapv(f64::abs).sum());
116+
assert_eq!(a.sq_l2_dist(&b), (&a - &b).mapv(f64::abs).mapv(|n| n.pow(2)).sum());
115117

116118
let a = array![[1, 2], [3, 4], [5, 6]];
117119
let b = array![[1, 3], [3, 4], [6, 7]];
118120

119-
assert_eq!(a.sq_l2_dist(&b), (&a - &b).mapv(i32::abs).sum());
121+
assert_eq!(a.sq_l2_dist(&b), (&a - &b).mapv(i32::abs).mapv(|n| n.pow(2)).sum());
120122
}
121123

122124
#[test]

0 commit comments

Comments
 (0)
Please sign in to comment.