From 10cd889e6b53f5fff127e84ad52e06b5a0dfdd1c Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Wed, 26 Nov 2025 12:19:06 +0100 Subject: [PATCH 1/5] Replace `PartialEq` with a manual implementation --- pineappl/src/interpolation.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pineappl/src/interpolation.rs b/pineappl/src/interpolation.rs index 02211279f..1271a8b4f 100644 --- a/pineappl/src/interpolation.rs +++ b/pineappl/src/interpolation.rs @@ -3,6 +3,7 @@ use super::convert; use super::packed_array::PackedArray; use arrayvec::ArrayVec; +use float_cmp::approx_eq; use serde::{Deserialize, Serialize}; use std::mem; use std::ops::Range; @@ -89,7 +90,7 @@ pub enum InterpMeth { } /// TODO -#[derive(Clone, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Deserialize, Serialize)] pub struct Interp { min: f64, max: f64, @@ -100,6 +101,20 @@ pub struct Interp { interp_meth: InterpMeth, } +impl PartialEq for Interp { + fn eq(&self, other: &Self) -> bool { + self.nodes == other.nodes + && self.order == other.order + && self.reweight == other.reweight + && self.map == other.map + && self.interp_meth == other.interp_meth + && approx_eq!(f64, self.min, other.min, ulps = 1) + && approx_eq!(f64, self.max, other.max, ulps = 1) + } +} + +impl Eq for Interp {} + impl Interp { /// TODO /// From cc95c9f0e953a8c64b5a0b68b886d28c7d156105 Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Wed, 26 Nov 2025 22:09:05 +0100 Subject: [PATCH 2/5] Add a unit test --- pineappl/src/interpolation.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pineappl/src/interpolation.rs b/pineappl/src/interpolation.rs index 1271a8b4f..e404184a3 100644 --- a/pineappl/src/interpolation.rs +++ b/pineappl/src/interpolation.rs @@ -63,7 +63,7 @@ fn lagrange_weights(i: usize, n: usize, u: f64) -> f64 { /// TODO #[repr(C)] -#[derive(Clone, Copy, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] pub enum ReweightMeth { /// TODO ApplGridX, @@ -83,14 +83,14 @@ pub enum Map { /// TODO #[repr(C)] -#[derive(Clone, Copy, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] pub enum InterpMeth { /// TODO Lagrange, } /// TODO -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Interp { min: f64, max: f64, @@ -656,6 +656,32 @@ mod tests { } } + #[test] + fn compare_fields_with_nan() { + let interp_a = Interp::new( + 1e-3, + 1e4, + 50, + 3, + ReweightMeth::NoReweight, + Map::ApplGridH0, + InterpMeth::Lagrange, + ); + let interp_b = Interp::new( + 1e-3, + 1e4, + 50, + 3, + ReweightMeth::NoReweight, + Map::ApplGridH0, + InterpMeth::Lagrange, + ); + + assert!(interp_a.min.is_nan()); + assert!(interp_b.min.is_nan()); + assert_eq!(interp_a, interp_b); + } + #[test] fn interpolate_zero_and_outside() { let interps = vec![ From 430f7af87b9594a0c83efe00c39d90a5da1af3a5 Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Sat, 29 Nov 2025 17:02:55 +0100 Subject: [PATCH 3/5] Remove `interp_b` --- pineappl/src/interpolation.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pineappl/src/interpolation.rs b/pineappl/src/interpolation.rs index e404184a3..64006820d 100644 --- a/pineappl/src/interpolation.rs +++ b/pineappl/src/interpolation.rs @@ -658,16 +658,7 @@ mod tests { #[test] fn compare_fields_with_nan() { - let interp_a = Interp::new( - 1e-3, - 1e4, - 50, - 3, - ReweightMeth::NoReweight, - Map::ApplGridH0, - InterpMeth::Lagrange, - ); - let interp_b = Interp::new( + let interp = Interp::new( 1e-3, 1e4, 50, @@ -677,9 +668,8 @@ mod tests { InterpMeth::Lagrange, ); - assert!(interp_a.min.is_nan()); - assert!(interp_b.min.is_nan()); - assert_eq!(interp_a, interp_b); + assert!(interp.min.is_nan()); + assert_eq!(interp, interp); } #[test] From 96491f34d97b49bfa65a20e4e4fb2deaf6e65bb3 Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Wed, 3 Dec 2025 11:02:06 +0100 Subject: [PATCH 4/5] Clarified checks and added explanatory notes --- pineappl/src/interpolation.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pineappl/src/interpolation.rs b/pineappl/src/interpolation.rs index 64006820d..e2154ed74 100644 --- a/pineappl/src/interpolation.rs +++ b/pineappl/src/interpolation.rs @@ -668,7 +668,10 @@ mod tests { InterpMeth::Lagrange, ); + // Starting from below the valid domain of the map results in a NaN for `min`. assert!(interp.min.is_nan()); + // We also need to check `.min()` which minimises between `min` and `max` is NaN. + assert!(!interp.min().is_nan()); assert_eq!(interp, interp); } From ce3902fe891336f3dfe5a2b38013ccaf1026a802 Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Thu, 4 Dec 2025 20:27:28 +0100 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ef25cd9a..73bccfe0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- added a `pineappl_grid_delete_bins` method to the C-API + +### Fixed + +- fixed bugs in stopping condition of the Newton iteration method +- fixed a bug in comparing `interpolation::Interp` objects when one of the + boundaries is `NaN` + ## [1.2.0] - 22/08/2025 ### Added