From 6aa3ba4668df63d22b41b0c82ee59e4e65df5280 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Wed, 19 Jan 2022 15:38:59 +0100 Subject: [PATCH 1/5] Skip zero convolutions --- pineappl/src/grid.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index d754d521..b205fd4f 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1429,6 +1429,17 @@ impl Grid { "[{elapsed_precise}] {bar:50.cyan/blue} {pos:>7}/{len:7} - ETA: {eta_precise} {msg}", )); + // which (tgt_pid, src_pid) tuples are non-zero in general? + let non_zero_pid_indices: Vec<_> = (0..operator.dim().0) + .cartesian_product(0..operator.dim().1) + .filter(|&(tgt_pid_idx, src_pid_idx)| { + operator + .slice(s![tgt_pid_idx, src_pid_idx, .., .., ..]) + .iter() + .any(|&value| value != 0.0) + }) + .collect(); + // iterate over all bins, which are mapped one-to-one from the target to the source grid for bin in 0..self.bin_info().bins() { // iterate over the source grid luminosities @@ -1595,6 +1606,18 @@ impl Grid { 0 }; + // if `op1` and `op2` below are zero there's no work to do + // TODO: ideally we change the for loops instead of vetoing here + if non_zero_pid_indices + .iter() + .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx)) + || non_zero_pid_indices + .iter() + .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx)) + { + continue; + } + // create target subgrid let mut tgt_array = SparseArray3::new(1, tgt_x1_grid.len(), tgt_x2_grid.len()); From c406c09afdea3b531be61f7d4fc4d03ede0c6959 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Wed, 19 Jan 2022 16:20:56 +0100 Subject: [PATCH 2/5] Add missing negations --- pineappl/src/grid.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index b205fd4f..792407fc 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1608,10 +1608,10 @@ impl Grid { // if `op1` and `op2` below are zero there's no work to do // TODO: ideally we change the for loops instead of vetoing here - if non_zero_pid_indices + if !non_zero_pid_indices .iter() .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx)) - || non_zero_pid_indices + || !non_zero_pid_indices .iter() .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx)) { From 505ec024211257795f9d677e00513a57e094874e Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Mon, 24 Jan 2022 12:27:55 +0100 Subject: [PATCH 3/5] Check whether op is applied before skipping --- pineappl/src/grid.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 792407fc..056ffd11 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1608,12 +1608,12 @@ impl Grid { // if `op1` and `op2` below are zero there's no work to do // TODO: ideally we change the for loops instead of vetoing here - if !non_zero_pid_indices + if (has_pdf1 && !non_zero_pid_indices .iter() - .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx)) - || !non_zero_pid_indices + .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx))) + || (has_pdf2 && !non_zero_pid_indices .iter() - .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx)) + .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx))) { continue; } From f7f94c64c3eb422ca8bcb27a3c13ce4cd648f5bc Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Wed, 26 Jan 2022 10:50:07 +0100 Subject: [PATCH 4/5] Run `cargo fmt` --- pineappl/src/grid.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 056ffd11..02e3e1cf 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1608,12 +1608,14 @@ impl Grid { // if `op1` and `op2` below are zero there's no work to do // TODO: ideally we change the for loops instead of vetoing here - if (has_pdf1 && !non_zero_pid_indices - .iter() - .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx))) - || (has_pdf2 && !non_zero_pid_indices + if (has_pdf1 + && !non_zero_pid_indices .iter() - .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx))) + .any(|&tuple| tuple == (tgt_pid1_idx, src_pid1_idx))) + || (has_pdf2 + && !non_zero_pid_indices + .iter() + .any(|&tuple| tuple == (tgt_pid2_idx, src_pid2_idx))) { continue; } From b7014fdc4ecf9ed3ef15f08cc47ee5761ed0b471 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Wed, 26 Jan 2022 11:14:30 +0100 Subject: [PATCH 5/5] Move invariant code outside of loops --- pineappl/src/grid.rs | 59 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 02e3e1cf..3784e1d5 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1440,6 +1440,39 @@ impl Grid { }) .collect(); + // the x1 and x2 grid values are the same across all non-zero subgrids + let first_non_zero_grid = self + .subgrids + .iter() + .filter(|subgrid| !subgrid.is_empty()) + .next() + .unwrap_or_else(|| unreachable!()); + // source x1/x2 grid might differ and be differently sorted than the operator + let x1_grid: Vec<_> = first_non_zero_grid + .x1_grid() + .iter() + .map(|x| { + eko_info + .grid_axes + .x_grid + .iter() + .position(|xi| approx_eq!(f64, *xi, *x, ulps = 64)) + .unwrap_or_else(|| unreachable!()) + }) + .collect(); + let x2_grid: Vec<_> = first_non_zero_grid + .x2_grid() + .iter() + .map(|x| { + eko_info + .grid_axes + .x_grid + .iter() + .position(|xi| approx_eq!(f64, *xi, *x, ulps = 64)) + .unwrap_or_else(|| unreachable!()) + }) + .collect(); + // iterate over all bins, which are mapped one-to-one from the target to the source grid for bin in 0..self.bin_info().bins() { // iterate over the source grid luminosities @@ -1488,32 +1521,6 @@ impl Grid { let src_subgrid = &self.subgrids[[order, bin, src_lumi]]; - // source x1/x2 grid might differ and be differently sorted than the operator - let x1_grid: Vec<_> = src_subgrid - .x1_grid() - .iter() - .map(|x| { - eko_info - .grid_axes - .x_grid - .iter() - .position(|xi| approx_eq!(f64, *xi, *x, ulps = 64)) - .unwrap_or_else(|| unreachable!()) - }) - .collect(); - let x2_grid: Vec<_> = src_subgrid - .x2_grid() - .iter() - .map(|x| { - eko_info - .grid_axes - .x_grid - .iter() - .position(|xi| approx_eq!(f64, *xi, *x, ulps = 64)) - .unwrap_or_else(|| unreachable!()) - }) - .collect(); - for ((iq2, ix1, ix2), &value) in src_subgrid.iter() { let scale = src_subgrid.mu2_grid()[iq2].fac; let src_iq2 = src_array_q2_grid