diff --git a/pineappl/src/bin.rs b/pineappl/src/bin.rs index 3d45a597..0926b74d 100644 --- a/pineappl/src/bin.rs +++ b/pineappl/src/bin.rs @@ -806,16 +806,16 @@ mod test { ])) .unwrap(); - assert_eq!(limits.left(), 0.0); - assert_eq!(limits.right(), 2.0); + assert!((limits.left() - 0.0).abs() < f64::EPSILON); + assert!((limits.right() - 2.0).abs() < f64::EPSILON); assert_eq!(limits.bins(), 6); let non_consecutive_bins = BinLimits::new(vec![3.0, 4.0]); assert!(limits.merge(&non_consecutive_bins).is_err()); - assert_eq!(limits.left(), 0.0); - assert_eq!(limits.right(), 2.0); + assert!((limits.left() - 0.0).abs() < f64::EPSILON); + assert!((limits.right() - 2.0).abs() < f64::EPSILON); assert_eq!(limits.bins(), 6); // left merge @@ -828,8 +828,8 @@ mod test { ])) .is_err()); - assert_eq!(limits.left(), 0.0); - assert_eq!(limits.right(), 2.0); + assert!((limits.left() - 0.0).abs() < f64::EPSILON); + assert!((limits.right() - 2.0).abs() < f64::EPSILON); assert_eq!(limits.bins(), 6); } diff --git a/pineappl/src/convolutions.rs b/pineappl/src/convolutions.rs index ea726c44..57686828 100644 --- a/pineappl/src/convolutions.rs +++ b/pineappl/src/convolutions.rs @@ -307,7 +307,7 @@ impl<'a> LumiCache<'a> { .map(|Mu2 { ren, .. }| { self.mur2_grid .iter() - .position(|&mur2| mur2 == xir * xir * ren) + .position(|&mur2| (mur2 - xir * xir * ren).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()) }) .collect(); @@ -316,7 +316,7 @@ impl<'a> LumiCache<'a> { .map(|Mu2 { fac, .. }| { self.muf2_grid .iter() - .position(|&muf2| muf2 == xif * xif * fac) + .position(|&muf2| (muf2 - xif * xif * fac).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()) }) .collect(); @@ -325,7 +325,7 @@ impl<'a> LumiCache<'a> { .map(|x1| { self.x_grid .iter() - .position(|x| x1 == x) + .position(|x| (x1 - x).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()) }) .collect(); @@ -335,7 +335,7 @@ impl<'a> LumiCache<'a> { .map(|x2| { self.x_grid .iter() - .position(|x| x2 == x) + .position(|x| (x2 - x).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()) }) .collect(); diff --git a/pineappl/src/empty_subgrid.rs b/pineappl/src/empty_subgrid.rs index 79640e65..9a792fbd 100644 --- a/pineappl/src/empty_subgrid.rs +++ b/pineappl/src/empty_subgrid.rs @@ -82,7 +82,7 @@ mod tests { #[test] fn create_empty() { let mut subgrid = EmptySubgridV1; - assert_eq!(subgrid.convolve(&[], &[], &[], &mut |_, _, _| 0.0), 0.0,); + assert!((subgrid.convolve(&[], &[], &[], &mut |_, _, _| 0.0) - 0.0).abs() < f64::EPSILON); assert!(subgrid.is_empty()); subgrid.merge(&mut EmptySubgridV1.into(), false); subgrid.scale(2.0); diff --git a/pineappl/src/fk_table.rs b/pineappl/src/fk_table.rs index bf040da4..4c699104 100644 --- a/pineappl/src/fk_table.rs +++ b/pineappl/src/fk_table.rs @@ -326,7 +326,7 @@ impl TryFrom for FkTable { if muf2 < 0.0 { muf2 = mu2_grid[0].fac; - } else if muf2 != mu2_grid[0].fac { + } else if (muf2 - mu2_grid[0].fac).abs() > f64::EPSILON { return Err(TryFromGridError::MultipleScales); } } @@ -334,7 +334,7 @@ impl TryFrom for FkTable { for channel in grid.channels() { let entry = channel.entry(); - if entry.len() != 1 || entry[0].2 != 1.0 { + if entry.len() != 1 || (entry[0].2 - 1.0).abs() > f64::EPSILON { return Err(TryFromGridError::InvalidChannel); } } diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 19698d22..39d5250a 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -213,6 +213,7 @@ bitflags! { /// Main data structure of `PineAPPL`. This structure contains a `Subgrid` for each `LumiEntry`, /// bin, and coupling order it was created with. +#[allow(clippy::unsafe_derive_deserialize)] #[derive(Clone, Deserialize, Serialize)] pub struct Grid { subgrids: Array3, @@ -257,6 +258,7 @@ impl Grid { /// # Errors /// /// If `subgrid_type` is none of the values listed above, an error is returned. + #[allow(clippy::needless_pass_by_value)] pub fn with_subgrid_type( channels: Vec, orders: Vec, @@ -356,7 +358,9 @@ impl Grid { for ((ord, bin, chan), subgrid) in self.subgrids.indexed_iter() { let order = &self.orders[ord]; - if ((order.logxir > 0) && (xir == 1.0)) || ((order.logxif > 0) && (xif == 1.0)) { + if ((order.logxir > 0) && (xir - 1.0).abs() < f64::EPSILON) + || ((order.logxif > 0) && (xif - 1.0).abs() < f64::EPSILON) + { continue; } @@ -841,6 +845,7 @@ impl Grid { } /// Set the convolution type for this grid for the corresponding `index`. + #[allow(clippy::needless_pass_by_value)] pub fn set_convolution(&mut self, index: usize, convolution: Convolution) { // remove outdated metadata self.key_values_mut() @@ -1391,6 +1396,11 @@ impl Grid { /// Returns a [`GridError::EvolutionFailure`] if either the `operator` or its `info` is /// incompatible with this `Grid`. Returns a [`GridError::Other`] if the iterator from `slices` /// return an error. + /// + /// # Panics + /// + /// This function will panic if the dimension of the operators do not match the operator + /// information. pub fn evolve_with_slice_iter<'a, E: Into>( &self, slices: impl IntoIterator), E>>, @@ -1513,6 +1523,11 @@ impl Grid { /// Returns a [`GridError::EvolutionFailure`] if either the `operator` or its `info` is /// incompatible with this `Grid`. Returns a [`GridError::Other`] if the iterator from `slices` /// return an error. + /// + /// # Panics + /// + /// This function will panic if the dimension of the operators do not match the operator + /// information. pub fn evolve_with_slice_iter2<'a, E: Into>( &self, slices_a: impl IntoIterator), E>>, @@ -1661,6 +1676,7 @@ impl Grid { /// Deletes bins with the corresponding `bin_indices`. Repeated indices and indices larger or /// equal the bin length are ignored. + #[allow(clippy::range_plus_one)] pub fn delete_bins(&mut self, bin_indices: &[usize]) { let mut bin_indices: Vec<_> = bin_indices .iter() diff --git a/pineappl/src/import_only_subgrid.rs b/pineappl/src/import_only_subgrid.rs index 04624c09..02a3ac87 100644 --- a/pineappl/src/import_only_subgrid.rs +++ b/pineappl/src/import_only_subgrid.rs @@ -88,7 +88,7 @@ impl Subgrid for ImportOnlySubgridV1 { for (other_index, mu2) in other_grid.mu2_grid().iter().enumerate() { // the following should always be the case - assert_eq!(mu2.ren, mu2.fac); + assert!((mu2.ren - mu2.fac).abs() < f64::EPSILON); let q2 = &mu2.ren; let index = match self @@ -276,11 +276,11 @@ impl Subgrid for ImportOnlySubgridV2 { for ((i, j, k), value) in self.array.indexed_iter() { let target_j = x1_grid .iter() - .position(|&x| x == self.x1_grid[j]) + .position(|&x| (x - self.x1_grid[j]).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()); let target_k = x2_grid .iter() - .position(|&x| x == self.x2_grid[k]) + .position(|&x| (x - self.x2_grid[k]).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()); array[[i, target_j, target_k]] = value; @@ -313,12 +313,12 @@ impl Subgrid for ImportOnlySubgridV2 { let target_j = self .x1_grid .iter() - .position(|&x| x == rhs_x1[j]) + .position(|&x| (x - rhs_x1[j]).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()); let target_k = self .x2_grid .iter() - .position(|&x| x == rhs_x2[k]) + .position(|&x| (x - rhs_x2[k]).abs() < f64::EPSILON) .unwrap_or_else(|| unreachable!()); self.array[[index, target_j, target_k]] += value; diff --git a/pineappl/src/lagrange_subgrid.rs b/pineappl/src/lagrange_subgrid.rs index 8888d394..eefc13f0 100644 --- a/pineappl/src/lagrange_subgrid.rs +++ b/pineappl/src/lagrange_subgrid.rs @@ -14,7 +14,7 @@ use std::iter; use std::mem; fn weightfun(x: f64) -> f64 { - (x.sqrt() / (1.0 - 0.99 * x)).powi(3) + (x.sqrt() / 0.99f64.mul_add(-x, 1.0)).powi(3) } fn fx(y: f64) -> f64 { @@ -22,11 +22,11 @@ fn fx(y: f64) -> f64 { for _ in 0..100 { let x = (-yp).exp(); - let delta = y - yp - 5.0 * (1.0 - x); + let delta = 5.0f64.mul_add(-(1.0 - x), y - yp); if (delta).abs() < 1e-12 { return x; } - let deriv = -1.0 - 5.0 * x; + let deriv = 5.0f64.mul_add(-x, -1.0); yp -= delta / deriv; } @@ -451,7 +451,7 @@ impl LagrangeSubgridV2 { } fn gety1(&self, iy: usize) -> f64 { - if self.y1min == self.y1max { + if (self.y1min - self.y1max).abs() < f64::EPSILON { debug_assert_eq!(iy, 0); self.y1min } else { @@ -460,7 +460,7 @@ impl LagrangeSubgridV2 { } fn gety2(&self, iy: usize) -> f64 { - if self.y2min == self.y2max { + if (self.y2min - self.y2max).abs() < f64::EPSILON { debug_assert_eq!(iy, 0); self.y2min } else { @@ -469,7 +469,7 @@ impl LagrangeSubgridV2 { } fn gettau(&self, iy: usize) -> f64 { - if self.taumin == self.taumax { + if (self.taumin - self.taumax).abs() < f64::EPSILON { debug_assert_eq!(iy, 0); self.taumin } else { @@ -532,7 +532,9 @@ impl Subgrid for LagrangeSubgridV2 { if self.static_q2 == 0.0 { self.static_q2 = ntuple.q2; - } else if (self.static_q2 != -1.0) && (self.static_q2 != ntuple.q2) { + } else if ((self.static_q2 + 1.0).abs() > f64::EPSILON) + && ((self.static_q2 - ntuple.q2).abs() > f64::EPSILON) + { self.static_q2 = -1.0; } @@ -651,7 +653,9 @@ impl Subgrid for LagrangeSubgridV2 { self.increase_tau(new_itaumin, new_itaumax); } - if (other_grid.static_q2 == -1.0) || (self.static_q2 != other_grid.static_q2) { + if ((other_grid.static_q2 + 1.0).abs() > f64::EPSILON) + || ((self.static_q2 - other_grid.static_q2).abs() > f64::EPSILON) + { self.static_q2 = -1.0; } diff --git a/pineappl/src/pids.rs b/pineappl/src/pids.rs index 5d130d06..9ef3ee63 100644 --- a/pineappl/src/pids.rs +++ b/pineappl/src/pids.rs @@ -406,7 +406,7 @@ pub fn pdg_mc_ids_to_evol(tuples: &[(i32, f64)]) -> Option { .collect(); if let &[(pid, factor)] = non_zero.as_slice() { - if factor == 1.0 { + if (factor - 1.0).abs() < f64::EPSILON { return Some(pid); } } diff --git a/pineappl/src/sparse_array3.rs b/pineappl/src/sparse_array3.rs index 1debae7e..db408cc5 100644 --- a/pineappl/src/sparse_array3.rs +++ b/pineappl/src/sparse_array3.rs @@ -349,6 +349,7 @@ impl SparseArray3 { } /// Return an iterator over the elements, including zero elements. + #[allow(clippy::iter_without_into_iter)] pub fn iter_mut(&mut self) -> IterMut<'_, T> { self.entries.iter_mut() } diff --git a/pineappl/tests/drell_yan_lo.rs b/pineappl/tests/drell_yan_lo.rs index 21dad571..33b2d58b 100644 --- a/pineappl/tests/drell_yan_lo.rs +++ b/pineappl/tests/drell_yan_lo.rs @@ -25,6 +25,7 @@ fn int_photo(s: f64, t: f64, u: f64) -> f64 { } // Eq. (2.12) - quark-antiquark contribution to DY lepton pair production +#[allow(clippy::suboptimal_flops)] fn int_quark(s: f64, t: f64, u: f64, qq: f64, i3_wq: f64) -> f64 { let alphagf: f64 = 1.0 / 132.30818655547878; let mw = 80.35198454966643;