Skip to content

Commit

Permalink
Fix compilation problems and some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Sep 18, 2024
1 parent 9135e11 commit 3fac121
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pineappl/src/empty_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod tests {
fn create_empty() {
let mut subgrid = EmptySubgridV1;
assert!(subgrid.is_empty());
subgrid.merge(&mut EmptySubgridV1.into(), false);
subgrid.merge(&mut EmptySubgridV1.into(), None);
subgrid.scale(2.0);
subgrid.symmetrize(1, 2);
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion pineappl/src/packed_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ mod tests {
assert_eq!(grid2.indexed_iter().nth(2), Some((vec![0, 3, 1], 2.0)));
assert_eq!(grid2.indexed_iter().nth(3), Some((vec![0, 3, 4], 4.0)));

grid1.merge(&mut grid2, false);
grid1.merge(&mut grid2, None);

// the luminosity function is symmetric, so after symmetrization the result must be
// unchanged
Expand Down
30 changes: 20 additions & 10 deletions pineappl/src/subgrid.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Module containing the trait `Subgrid` and supporting structs.

use float_cmp::approx_eq;
use super::empty_subgrid::EmptySubgridV1;
use super::lagrange_subgrid::LagrangeSubgridV2;
use super::packed_subgrid::PackedQ1X2SubgridV1;
use enum_dispatch::enum_dispatch;
// use float_cmp::approx_eq;
// use ndarray::Array3;
use super::evolution::EVOLVE_INFO_TOL_ULPS;
// use super::evolution::EVOLVE_INFO_TOL_ULPS;
use super::interpolation::Interp;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand All @@ -21,30 +21,39 @@ pub enum NodeValues {
}

impl NodeValues {
/// TODO
pub fn extend(&mut self, other: &Self) {
match (self, other) {
(NodeValues::UseFromGrid, NodeValues::UseFromGrid) => (),
(NodeValues::UseThese(a), NodeValues::UseThese(b)) => a.extend_from_slice(b),
(NodeValues::UseThese(a), NodeValues::UseThese(b)) => {
a.extend_from_slice(b);
a.sort_by(|lhs, rhs| lhs.partial_cmp(rhs).unwrap());
// TODO: use some tolerance
a.dedup();
}
_ => unimplemented!(),
}
}

/// TODO
pub fn len(&self) -> usize {
match self {
NodeValues::UseFromGrid => unimplemented!(),
NodeValues::UseThese(a) => a.len(),
}
}

/// TODO
pub fn find(&self, value: f64) -> Option<usize> {
match self {
NodeValues::UseFromGrid => unimplemented!(),
NodeValues::UseThese(a) => a
.iter()
.position(|&x| approx_eq!(f64, x, value, ulps = EVOLVE_INFO_TOL_ULPS)),
NodeValues::UseThese(a) => a.iter().position(|&x|
// approx_eq!(f64, x, value, ulps = EVOLVE_INFO_TOL_ULPS)
x == value),
}
}

/// TODO
pub fn get(&self, index: usize) -> f64 {
match self {
NodeValues::UseFromGrid => unimplemented!(),
Expand All @@ -57,10 +66,11 @@ impl PartialEq for NodeValues {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(NodeValues::UseFromGrid, NodeValues::UseFromGrid) => true,
(NodeValues::UseThese(a), NodeValues::UseThese(b)) => a
.iter()
.zip(b)
.all(|(&a, &b)| approx_eq!(f64, a, b, ulps = EVOLVE_INFO_TOL_ULPS)),
(NodeValues::UseThese(a), NodeValues::UseThese(b)) => a.iter().zip(b).all(
// TODO: use some tolerance
|(&a, &b)| a == b,
//approx_eq!(f64, a, b, ulps = EVOLVE_INFO_TOL_ULPS)
),
// TODO: the remaining cases could still be the same, but we don't know the values from `UseFromGrid`.
_ => false,
}
Expand Down

0 comments on commit 3fac121

Please sign in to comment.