From ef962fa3896f6b8bb0c73b40794ff2e4969308e9 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 14 Oct 2023 13:21:20 +0200 Subject: [PATCH] Improve evolution performance for double-hadronic grids Instead of using a cartesian product of two PIDs which is subsequently filtered use two iterators of PIDs first filtered and subsequently zipped. This is a change of O(n^2) to O(n) which makes a big difference if n is large enough. This is the case for dijet grids, for example. --- pineappl/src/evolution.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pineappl/src/evolution.rs b/pineappl/src/evolution.rs index a9225678..a3dc0217 100644 --- a/pineappl/src/evolution.rs +++ b/pineappl/src/evolution.rs @@ -957,11 +957,14 @@ pub(crate) fn evolve_with_two( pids_a .iter() .zip(operators_a.iter()) - .cartesian_product(pids_b.iter().zip(operators_b.iter())) - .find_map(|((&(pa0, pa1), opa), (&(pb0, pb1), opb))| { - (pa0 == pida0 && pa1 == pida1 && pb0 == pidb0 && pb1 == pidb1) - .then_some((opa, opb)) + .find_map(|(&(pa0, pa1), opa)| { + (pa0 == pida0 && pa1 == pida1).then_some(opa) }) + .zip(pids_b.iter().zip(operators_b.iter()).find_map( + |(&(pb0, pb1), opb)| { + (pb0 == pidb0 && pb1 == pidb1).then_some(opb) + }, + )) .map(|(opa, opb)| (fk_table, opa, opb)) }) { @@ -1069,11 +1072,14 @@ pub(crate) fn evolve_slice_with_two( pids_a .iter() .zip(operators_a.iter()) - .cartesian_product(pids_b.iter().zip(operators_b.iter())) - .find_map(|((&(pa0, pa1), opa), (&(pb0, pb1), opb))| { - (pa0 == pida0 && pa1 == pida1 && pb0 == pidb0 && pb1 == pidb1) - .then_some((opa, opb)) + .find_map(|(&(pa0, pa1), opa)| { + (pa0 == pida0 && pa1 == pida1).then_some(opa) }) + .zip(pids_b.iter().zip(operators_b.iter()).find_map( + |(&(pb0, pb1), opb)| { + (pb0 == pidb0 && pb1 == pidb1).then_some(opb) + }, + )) .map(|(opa, opb)| (fk_table, opa, opb)) }) {