Skip to content

Commit

Permalink
Merge pull request #150 from finnbear/fuzz_nearest_to_epsilon
Browse files Browse the repository at this point in the history
Avoid spurious failure in `nearest_to` fuzzer
  • Loading branch information
svenstaro authored Jan 26, 2025
2 parents e0b53e7 + 29ab709 commit e61924c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fuzz/fuzz_targets/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ impl<const D: usize> Workload<D> {
// assert_eq!(best, flat_best);
// as such we only assert for distance equivalence if they are not None
if let Some((best, flat_best)) = best.zip(flat_best) {
approx::assert_abs_diff_eq!(best.1, flat_best.1);
const EPSILON: f32 = 0.001;

approx::assert_abs_diff_eq!(best.1, flat_best.1, epsilon = EPSILON);

// Brute force search for the ground truth, shapes is not empty since the results are not None.
let mut bruteforce = (
Expand All @@ -368,8 +370,8 @@ impl<const D: usize> Workload<D> {
}
bruteforce = (bruteforce.0, bruteforce.1.sqrt());
// Again we only test for distances.
approx::assert_abs_diff_eq!(best.1, bruteforce.1);
approx::assert_abs_diff_eq!(flat_best.1, bruteforce.1);
approx::assert_abs_diff_eq!(best.1, bruteforce.1, epsilon = EPSILON);
approx::assert_abs_diff_eq!(flat_best.1, bruteforce.1, epsilon = EPSILON);
}
}

Expand Down

0 comments on commit e61924c

Please sign in to comment.