Skip to content

Commit

Permalink
Remove boilerplate code
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Aug 15, 2024
1 parent 803c460 commit 011125b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 38 deletions.
12 changes: 4 additions & 8 deletions pineappl_py/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ pub struct PyBinRemapper {
pub(crate) bin_remapper: BinRemapper,
}

impl PyBinRemapper {
pub(crate) fn new(bin_remapper: BinRemapper) -> Self {
Self { bin_remapper }
}
}

#[pymethods]
impl PyBinRemapper {
/// Constructor.
Expand All @@ -29,8 +23,10 @@ impl PyBinRemapper {
/// limits : list(tuple(float, float))
/// bin limits
#[new]
pub fn new_f64(normalizations: PyReadonlyArray1<f64>, limits: Vec<(f64, f64)>) -> Self {
Self::new(BinRemapper::new(normalizations.to_vec().unwrap(), limits).unwrap())
pub fn new(normalizations: PyReadonlyArray1<f64>, limits: Vec<(f64, f64)>) -> Self {
Self {
bin_remapper: BinRemapper::new(normalizations.to_vec().unwrap(), limits).unwrap(),
}
}
}

Expand Down
12 changes: 4 additions & 8 deletions pineappl_py/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ pub struct PyChannel {
pub(crate) entry: Channel,
}

impl PyChannel {
pub(crate) fn new(entry: Channel) -> Self {
Self { entry }
}
}

#[pymethods]
impl PyChannel {
/// Constructor.
Expand All @@ -33,8 +27,10 @@ impl PyChannel {
/// entry: list(tuple(int, int, float))
/// channel configuration
#[new]
pub fn new_entry(entry: Vec<(i32, i32, f64)>) -> Self {
Self::new(Channel::new(entry))
pub fn new(entry: Vec<(i32, i32, f64)>) -> Self {
Self {
entry: Channel::new(entry),
}
}

/// Get list representation.
Expand Down
24 changes: 11 additions & 13 deletions pineappl_py/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ pub struct PyGrid {
pub(crate) grid: Grid,
}

impl PyGrid {
pub(crate) fn new(grid: Grid) -> Self {
Self { grid }
}
}

#[pymethods]
impl PyGrid {
/// Constructor.
Expand All @@ -57,12 +51,14 @@ impl PyGrid {
bin_limits: PyReadonlyArray1<f64>,
subgrid_params: PySubgridParams,
) -> Self {
Self::new(Grid::new(
channels.iter().map(|pyc| pyc.entry.clone()).collect(),
orders.iter().map(|pyo| pyo.order.clone()).collect(),
bin_limits.to_vec().unwrap(),
subgrid_params.subgrid_params,
))
Self {
grid: Grid::new(
channels.iter().map(|pyc| pyc.entry.clone()).collect(),
orders.iter().map(|pyo| pyo.order.clone()).collect(),
bin_limits.to_vec().unwrap(),
subgrid_params.subgrid_params,
),
}
}

/// Add a point to the grid.
Expand Down Expand Up @@ -508,7 +504,9 @@ impl PyGrid {
/// grid
#[staticmethod]
pub fn read(path: PathBuf) -> Self {
Self::new(Grid::read(BufReader::new(File::open(path).unwrap())).unwrap())
Self {
grid: Grid::read(BufReader::new(File::open(path).unwrap())).unwrap(),
}
}

/// Write to file.
Expand Down
12 changes: 3 additions & 9 deletions pineappl_py/src/subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ pub struct PySubgridParams {
pub(crate) subgrid_params: SubgridParams,
}

impl PySubgridParams {
pub(crate) fn new(subgrid_params: SubgridParams) -> Self {
Self { subgrid_params }
}
}

impl Clone for PySubgridParams {
fn clone(&self) -> Self {
let mut subgrid_params = SubgridParams::default();
Expand All @@ -39,9 +33,9 @@ impl PySubgridParams {
/// Constructor using the defaults.
#[new]
pub fn default() -> Self {
let subgrid_params = SubgridParams::default();

Self::new(subgrid_params)
Self {
subgrid_params: SubgridParams::default(),
}
}

/// Set number of :math:`Q^2` bins.
Expand Down

0 comments on commit 011125b

Please sign in to comment.