Skip to content

Commit

Permalink
Get rid of a few unwrap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Oct 18, 2024
1 parent f62412e commit a884201
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions pineappl/src/convolutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> ConvolutionCache<'a> {
}
}

pub(crate) fn setup(&mut self, grid: &Grid, xi: &[(f64, f64, f64)]) -> Result<(), ()> {
pub(crate) fn setup(&mut self, grid: &Grid, xi: &[(f64, f64, f64)]) {
self.perm = grid
.convolutions()
.iter()
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'a> ConvolutionCache<'a> {
.flat_map(|(_, node_values)| node_values)
})
.collect();
x_grid.sort_by(|a, b| a.partial_cmp(b).unwrap_or_else(|| unreachable!()));
x_grid.sort_by(f64::total_cmp);
x_grid.dedup();

let mut mur2_grid: Vec<_> = grid
Expand All @@ -106,7 +106,7 @@ impl<'a> ConvolutionCache<'a> {
})
.flat_map(|ren| xi.iter().map(move |(xir, _, _)| xir * xir * ren))
.collect();
mur2_grid.sort_by(|a, b| a.partial_cmp(b).unwrap_or_else(|| unreachable!()));
mur2_grid.sort_by(f64::total_cmp);
mur2_grid.dedup();

let mut muf2_grid: Vec<_> = grid
Expand All @@ -121,7 +121,7 @@ impl<'a> ConvolutionCache<'a> {
})
.flat_map(|fac| xi.iter().map(move |(_, xif, _)| xif * xif * fac))
.collect();
muf2_grid.sort_by(|a, b| a.partial_cmp(b).unwrap_or_else(|| unreachable!()));
muf2_grid.sort_by(f64::total_cmp);
muf2_grid.dedup();

let mut mua2_grid: Vec<_> = grid
Expand All @@ -136,16 +136,14 @@ impl<'a> ConvolutionCache<'a> {
})
.flat_map(|frg| xi.iter().map(move |(_, _, xia)| xia * xia * frg))
.collect();
mua2_grid.sort_by(|a, b| a.partial_cmp(b).unwrap_or_else(|| unreachable!()));
mua2_grid.sort_by(f64::total_cmp);
mua2_grid.dedup();

self.alphas_cache = mur2_grid.iter().map(|&mur2| (self.alphas)(mur2)).collect();
self.mur2_grid = mur2_grid;
self.muf2_grid = muf2_grid;
self.mua2_grid = mua2_grid;
self.x_grid = x_grid;

Ok(())
}

/// TODO
Expand Down
4 changes: 2 additions & 2 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Grid {
channel_mask: &[bool],
xi: &[(f64, f64, f64)],
) -> Vec<f64> {
convolution_cache.setup(self, xi).unwrap();
convolution_cache.setup(self, xi);

let bin_indices = if bin_indices.is_empty() {
(0..self.bin_info().bins()).collect()
Expand Down Expand Up @@ -336,7 +336,7 @@ impl Grid {
channel: usize,
(xir, xif, xia): (f64, f64, f64),
) -> ArrayD<f64> {
convolution_cache.setup(self, &[(xir, xif, xia)]).unwrap();
convolution_cache.setup(self, &[(xir, xif, xia)]);

let normalizations = self.bin_info().normalizations();
let pdg_channels = self.channels_pdg();
Expand Down

0 comments on commit a884201

Please sign in to comment.