diff --git a/pineappl/src/boc.rs b/pineappl/src/boc.rs index 1e744746..a090ea4a 100644 --- a/pineappl/src/boc.rs +++ b/pineappl/src/boc.rs @@ -23,7 +23,7 @@ pub enum Kinematics { /// TODO #[repr(C)] -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone, Deserialize, PartialEq, Serialize)] pub enum ScaleFuncForm { /// TODO NoScale, @@ -160,7 +160,7 @@ impl ScaleFuncForm { } /// TODO -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone, Deserialize, PartialEq, Serialize)] pub struct Scales { /// TODO pub ren: ScaleFuncForm, diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 5c605610..99937703 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -68,6 +68,9 @@ pub enum GridError { /// Errors that do no originate from this crate itself. #[error(transparent)] Other(#[from] anyhow::Error), + /// TODO + #[error("{0}")] + General(String), } #[derive(Clone, Deserialize, Serialize)] @@ -546,13 +549,33 @@ impl Grid { /// /// # Errors /// - /// If the bin limits of `self` and `other` are different and if the bin limits of `other` can - /// not be merged with `self` an error is returned. + /// If `self` and `other` in have different convolutions, PID bases, kinematics, + /// interpolations, or scales an error is returned. If the bin limits of `self` and `other` + /// are different and if the bin limits of `other` cannot be merged with `self` an error is + /// returned. /// /// # Panics /// /// TODO pub fn merge(&mut self, mut other: Self) -> Result<(), GridError> { + if self.convolutions() != other.convolutions() { + return Err(GridError::General("convolutions do not match".to_owned())); + } + if self.pid_basis() != other.pid_basis() { + return Err(GridError::General("PID bases do not match".to_owned())); + } + // TODO: relax check if kinematic variables are permutations of each other + if self.kinematics() != other.kinematics() { + return Err(GridError::General("kinematics do not match".to_owned())); + } + // TODO: relax check if subgrid types don't use interpolation + if self.interpolations() != other.interpolations() { + return Err(GridError::General("interpolations do not match".to_owned())); + } + if self.scales() != other.scales() { + return Err(GridError::General("scales do not match".to_owned())); + } + let mut new_orders: Vec = Vec::new(); let mut new_bins = 0; let mut new_entries: Vec = Vec::new(); diff --git a/pineappl/src/interpolation.rs b/pineappl/src/interpolation.rs index 8f9230f7..9d5fce41 100644 --- a/pineappl/src/interpolation.rs +++ b/pineappl/src/interpolation.rs @@ -62,7 +62,7 @@ fn lagrange_weights(i: usize, n: usize, u: f64) -> f64 { /// TODO #[repr(C)] -#[derive(Clone, Copy, Deserialize, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] pub enum ReweightMeth { /// TODO ApplGridX, @@ -72,7 +72,7 @@ pub enum ReweightMeth { /// TODO #[repr(C)] -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub enum Map { /// TODO ApplGridF2, @@ -82,14 +82,14 @@ pub enum Map { /// TODO #[repr(C)] -#[derive(Clone, Copy, Deserialize, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] pub enum InterpMeth { /// TODO Lagrange, } /// TODO -#[derive(Clone, Deserialize, Serialize)] +#[derive(Clone, Deserialize, PartialEq, Serialize)] pub struct Interp { min: f64, max: f64,