Skip to content

Commit

Permalink
Check grid compatibility in Grid::merge
Browse files Browse the repository at this point in the history
  • Loading branch information
t7phy committed Jan 20, 2025
1 parent 6bcfc1c commit 072ebc5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Kinematics {

/// TODO
#[repr(C)]
#[derive(Clone, Deserialize, Serialize)]
#[derive(Clone, Deserialize, PartialEq, Serialize)]
pub enum ScaleFuncForm {
/// TODO
NoScale,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl ScaleFuncForm {
}

/// TODO
#[derive(Clone, Deserialize, Serialize)]
#[derive(Clone, Deserialize, PartialEq, Serialize)]
pub struct Scales {
/// TODO
pub ren: ScaleFuncForm,
Expand Down
27 changes: 25 additions & 2 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<Order> = Vec::new();
let mut new_bins = 0;
let mut new_entries: Vec<Channel> = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions pineappl/src/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 072ebc5

Please sign in to comment.