Skip to content

Commit

Permalink
Add numerical tolerance in ImportSubgridV1::merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Oct 17, 2024
1 parent fdde7d3 commit 63924e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
13 changes: 8 additions & 5 deletions pineappl/src/import_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ impl Subgrid for ImportSubgridV1 {
rhs_node_values.swap(a, b);
}

// TODO: allow for some tolerance
if self.node_values() != rhs_node_values {
if new_node_values != rhs_node_values {
for (new, rhs) in new_node_values.iter_mut().zip(&rhs_node_values) {
new.extend(rhs);
new.sort_by(|lhs, rhs| lhs.partial_cmp(rhs).unwrap());
new.dedup();
new.sort_by(f64::total_cmp);
new.dedup_by(|&mut lhs, &mut rhs| {
approx_eq!(f64, lhs, rhs, ulps = EVOLVE_INFO_TOL_ULPS)
});
}

let mut array = PackedArray::new(new_node_values.iter().map(Vec::len).collect());
Expand Down Expand Up @@ -83,7 +84,9 @@ impl Subgrid for ImportSubgridV1 {
let target: Vec<_> = izip!(indices, &new_node_values, &rhs_node_values)
.map(|(index, new, rhs)| {
new.iter()
.position(|&value| value == rhs[index])
.position(|&value| {
approx_eq!(f64, value, rhs[index], ulps = EVOLVE_INFO_TOL_ULPS)
})
// UNWRAP: must succeed, `new_node_values` is the union of
// `lhs_node_values` and `rhs_node_values`
.unwrap()
Expand Down
18 changes: 9 additions & 9 deletions pineappl_cli/tests/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,17 @@ const IMPORT_APPLGRID_STR: &str = "b PineAPPL APPLgrid rel. diff
#[cfg(feature = "applgrid")]
const IMPORT_NEW_APPLGRID_STR: &str = "b PineAPPL APPLgrid rel. diff
--+-----------+-----------+--------------
0 6.2634897e2 6.2634897e2 1.7763568e-15
1 6.2847078e2 6.2847078e2 0.0000000e0
2 6.3163323e2 6.3163323e2 0.0000000e0
3 6.3586556e2 6.3586556e2 2.2204460e-16
4 6.4139163e2 6.4139163e2 1.5543122e-15
5 6.4848088e2 6.4848088e2 -2.3314684e-15
6 6.5354150e2 6.5354150e2 -3.6637360e-15
0 6.2634897e2 6.2634897e2 1.5543122e-15
1 6.2847078e2 6.2847078e2 -2.2204460e-16
2 6.3163323e2 6.3163323e2 -3.3306691e-16
3 6.3586556e2 6.3586556e2 -2.2204460e-16
4 6.4139163e2 6.4139163e2 1.3322676e-15
5 6.4848088e2 6.4848088e2 -2.6645353e-15
6 6.5354150e2 6.5354150e2 -3.7747583e-15
7 6.5377566e2 6.5377566e2 -1.7763568e-15
8 6.5094729e2 6.5094729e2 1.7763568e-15
8 6.5094729e2 6.5094729e2 1.5543122e-15
9 6.3588760e2 6.3588760e2 2.2204460e-15
10 5.9810718e2 5.9810718e2 1.9984014e-15
10 5.9810718e2 5.9810718e2 2.2204460e-15
";

const IMPORT_FILE_FORMAT_FAILURE_STR: &str = "Error: could not detect file format
Expand Down

0 comments on commit 63924e1

Please sign in to comment.