Skip to content

Commit

Permalink
Fix remaining compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
t7phy committed Jul 24, 2024
1 parent f8da72e commit 03f2dc6
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 109 deletions.
29 changes: 19 additions & 10 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,25 +339,25 @@ impl Channel {
/// use pineappl::boc::Channel;
/// use pineappl::channel;
///
/// let entry = Channel::translate(&channel![103, 11, 1.0], &|evol_id| match evol_id {
/// let entry = Channel::translate(&channel![103, 11, 10], &|evol_id| match evol_id {
/// 103 => vec![(2, 1.0), (-2, -1.0), (1, -1.0), (-1, 1.0)],
/// _ => vec![(evol_id, 1.0)],
/// });
///
/// assert_eq!(entry, channel![2, 11, 1.0; -2, 11, -1.0; 1, 11, -1.0; -1, 11, 1.0]);
/// assert_eq!(entry, channel![2, 11, 10.0; -2, 11, -10.0; 1, 11, -10.0; -1, 11, 10.0]);
/// ```
pub fn translate(entry: &Self, translator: &dyn Fn(i32) -> Vec<(i32, f64)>) -> Self {
let mut result = Vec::new();

for &(pids, factor) in &entry.entry {
for (pids, factor) in &entry.entry {
for tuples in pids
.iter()
.map(|&pid| translator(pid))
.multi_cartesian_product()
{
result.push((
tuples.iter().map(|&(pid, _)| pid).collect(),
tuples.iter().map(|(_, f)| f).product::<f64>(),
tuples.iter().map(|(_, f)| factor * f).product::<f64>(),
));
}
}
Expand All @@ -382,11 +382,20 @@ impl Channel {
&self.entry
}

// /// Creates a new object with the initial states transposed.
// #[must_use]
// pub fn transpose(&self) -> Self {
// Self::new(self.entry.iter().map(|(a, b, c)| (*b, *a, *c)).collect())
// }
/// Create a new object with the PIDs at index `i` and `j` transposed.
#[must_use]
pub fn transpose(&self, i: usize, j: usize) -> Self {
Self::new(
self.entry
.iter()
.map(|(pids, c)| {
let mut transposed = pids.clone();
transposed.swap(i, j);
(transposed, *c)
})
.collect(),
)
}

/// If `other` is the same channel when only comparing PIDs and neglecting the factors, return
/// the number `f1 / f2`, where `f1` is the factor from `self` and `f2` is the factor from
Expand Down Expand Up @@ -498,7 +507,7 @@ impl FromStr for Channel {
#[macro_export]
macro_rules! channel {
($a:expr, $b:expr, $factor:expr $(; $c:expr, $d:expr, $fac:expr)*) => {
$crate::boc::Channel::new(vec![($a, $b, $factor), $(($c, $d, $fac)),*])
$crate::boc::Channel::new(vec![(vec![$a, $b], $factor), $((vec![$c, $d], $fac)),*])
};
}

Expand Down
66 changes: 30 additions & 36 deletions pineappl/src/evolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ fn ndarray_from_subgrid_orders_slice(
Ok((vec![x1_a, x1_b], (!zero).then_some(array)))
}

// TODO: merge this method into evolve_slice_with_two
pub(crate) fn evolve_slice_with_one(
grid: &Grid,
operator: &ArrayView4<f64>,
Expand All @@ -395,18 +396,22 @@ pub(crate) fn evolve_slice_with_one(
alphas_table: &AlphasTable,
) -> Result<(Array3<SubgridEnum>, Vec<Channel>), GridError> {
let gluon_has_pid_zero = gluon_has_pid_zero(grid);
let has_pdf1 = grid.convolutions()[0] != Convolution::None;

// UNWRAP: there must be exactly one convolution that's not None
let index = grid
.convolutions()
.iter()
.position(|c| *c != Convolution::None)
.unwrap();
let (pid_indices, pids) = pid_slices(operator, info, gluon_has_pid_zero, &|pid| {
grid.channels()
.iter()
.flat_map(Channel::entry)
.any(|&(a, b, _)| if has_pdf1 { a } else { b } == pid)
.any(|(pids, _)| pids[index] == pid)
})?;

let channels0 = channels0_with_one(&pids);
let mut sub_fk_tables = Vec::with_capacity(grid.bin_info().bins() * channels0.len());
let new_axis = if has_pdf1 { 2 } else { 1 };
let new_axis = 2 - index;

let mut last_x1 = Vec::new();
let mut ops = Vec::new();
Expand All @@ -429,7 +434,7 @@ pub(crate) fn evolve_slice_with_one(
continue;
};

let x1 = if has_pdf1 { x1.remove(0) } else { x1.remove(1) };
let x1 = x1.remove(index);

if x1.is_empty() {
continue;
Expand All @@ -445,12 +450,7 @@ pub(crate) fn evolve_slice_with_one(
last_x1 = x1;
}

for (&pid1, &factor) in
channel1
.entry()
.iter()
.map(|(a, b, f)| if has_pdf1 { (a, f) } else { (b, f) })
{
for (pid1, &factor) in channel1.entry().iter().map(|(pids, f)| (pids[index], f)) {
for (fk_table, op) in
channels0
.iter()
Expand Down Expand Up @@ -485,18 +485,22 @@ pub(crate) fn evolve_slice_with_one(
ren: info.fac0,
fac: info.fac0,
}],
if has_pdf1 { info.x0.clone() } else { vec![1.0] },
if has_pdf1 { vec![1.0] } else { info.x0.clone() },
if index == 0 {
info.x0.clone()
} else {
vec![1.0]
},
if index == 0 {
vec![1.0]
} else {
info.x0.clone()
},
)
.into()
}));
}

let pid = if grid.convolutions()[0] == Convolution::None {
grid.channels()[0].entry()[0].0
} else {
grid.channels()[0].entry()[0].1
};
let pid = grid.channels()[0].entry()[0].0[index];

Ok((
Array1::from_iter(sub_fk_tables)
Expand All @@ -506,8 +510,8 @@ pub(crate) fn evolve_slice_with_one(
.iter()
.map(|&a| {
channel![
if has_pdf1 { a } else { pid },
if has_pdf1 { pid } else { a },
if index == 0 { a } else { pid },
if index == 0 { pid } else { a },
1.0
]
})
Expand All @@ -532,12 +536,7 @@ pub(crate) fn evolve_slice_with_two(
grid.channels()
.iter()
.flat_map(Channel::entry)
.any(|tuple| match d {
// TODO: `Channel::entry` should return a tuple of a `Vec` and an `f64`
0 => tuple.0 == pid1,
1 => tuple.1 == pid1,
_ => unreachable!(),
})
.any(|(pids, _)| pids[d] == pid1)
})
})
.collect::<Result<Vec<_>, _>>()?
Expand Down Expand Up @@ -596,7 +595,7 @@ pub(crate) fn evolve_slice_with_two(
for (pids1, factor) in channel1
.entry()
.iter()
.map(|&(pida1, pidb1, factor)| ([pida1, pidb1], factor))
.map(|(pids1, factor)| ([pids1[0], pids1[1]], factor))
{
for (fk_table, ops) in
channels0
Expand All @@ -615,7 +614,7 @@ pub(crate) fn evolve_slice_with_two(
})
{
linalg::general_mat_mul(1.0, &array, &ops[1].t(), 0.0, &mut tmp);
linalg::general_mat_mul(factor, ops[0], &tmp, 1.0, fk_table);
linalg::general_mat_mul(*factor, ops[0], &tmp, 1.0, fk_table);
}
}
}
Expand Down Expand Up @@ -675,12 +674,7 @@ pub(crate) fn evolve_slice_with_two2(
grid.channels()
.iter()
.flat_map(Channel::entry)
.any(|tuple| match d {
// TODO: `Channel::entry` should return a tuple of a `Vec` and an `f64`
0 => tuple.0 == pid1,
1 => tuple.1 == pid1,
_ => unreachable!(),
})
.any(|(pids, _)| pids[d] == pid1)
})
})
.collect::<Result<Vec<_>, _>>()?
Expand Down Expand Up @@ -747,7 +741,7 @@ pub(crate) fn evolve_slice_with_two2(
for (pids1, factor) in channel1
.entry()
.iter()
.map(|&(pida1, pidb1, factor)| ([pida1, pidb1], factor))
.map(|(pids1, factor)| ([pids1[0], pids1[1]], factor))
{
for (fk_table, ops) in
channels0
Expand All @@ -768,7 +762,7 @@ pub(crate) fn evolve_slice_with_two2(
// tmp = array * ops[1]^T
linalg::general_mat_mul(1.0, &array, &ops[1].t(), 0.0, &mut tmp);
// fk_table += factor * ops[0] * tmp
linalg::general_mat_mul(factor, ops[0], &tmp, 1.0, fk_table);
linalg::general_mat_mul(*factor, ops[0], &tmp, 1.0, fk_table);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pineappl/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ impl FkTable {

/// Return the channel definition for this `FkTable`. All factors are `1.0`.
#[must_use]
pub fn channels(&self) -> Vec<(i32, i32)> {
pub fn channels(&self) -> Vec<Vec<i32>> {
self.grid
.channels()
.iter()
.map(|entry| (entry.entry()[0].0, entry.entry()[0].1))
.map(|entry| entry.entry()[0].0.clone())
.collect()
}

Expand Down Expand Up @@ -390,7 +390,7 @@ impl TryFrom<Grid> 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].1 != 1.0 {
return Err(TryFromGridError::InvalidChannel);
}
}
Expand Down
Loading

0 comments on commit 03f2dc6

Please sign in to comment.