From 011125b8509c5a4d3f8d61bae7b64fe9f9f608b9 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Thu, 15 Aug 2024 09:58:41 +0200 Subject: [PATCH] Remove boilerplate code --- pineappl_py/src/bin.rs | 12 ++++-------- pineappl_py/src/boc.rs | 12 ++++-------- pineappl_py/src/grid.rs | 24 +++++++++++------------- pineappl_py/src/subgrid.rs | 12 +++--------- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/pineappl_py/src/bin.rs b/pineappl_py/src/bin.rs index 445b9428..76cd5b47 100644 --- a/pineappl_py/src/bin.rs +++ b/pineappl_py/src/bin.rs @@ -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. @@ -29,8 +23,10 @@ impl PyBinRemapper { /// limits : list(tuple(float, float)) /// bin limits #[new] - pub fn new_f64(normalizations: PyReadonlyArray1, limits: Vec<(f64, f64)>) -> Self { - Self::new(BinRemapper::new(normalizations.to_vec().unwrap(), limits).unwrap()) + pub fn new(normalizations: PyReadonlyArray1, limits: Vec<(f64, f64)>) -> Self { + Self { + bin_remapper: BinRemapper::new(normalizations.to_vec().unwrap(), limits).unwrap(), + } } } diff --git a/pineappl_py/src/boc.rs b/pineappl_py/src/boc.rs index aadad461..124bd0c0 100644 --- a/pineappl_py/src/boc.rs +++ b/pineappl_py/src/boc.rs @@ -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. @@ -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. diff --git a/pineappl_py/src/grid.rs b/pineappl_py/src/grid.rs index 998cd729..98314b07 100644 --- a/pineappl_py/src/grid.rs +++ b/pineappl_py/src/grid.rs @@ -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. @@ -57,12 +51,14 @@ impl PyGrid { bin_limits: PyReadonlyArray1, 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. @@ -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. diff --git a/pineappl_py/src/subgrid.rs b/pineappl_py/src/subgrid.rs index 13dda42b..d0290961 100644 --- a/pineappl_py/src/subgrid.rs +++ b/pineappl_py/src/subgrid.rs @@ -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(); @@ -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.