Skip to content

Commit

Permalink
Make Generalized convolution works
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Oct 18, 2024
1 parent a884201 commit f1574a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
31 changes: 28 additions & 3 deletions pineappl_py/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,38 @@ impl PyGrid {
xi: Option<Vec<(f64, f64, f64)>>,
py: Python<'py>,
) -> Bound<'py, PyArray1<f64>> {
// Closure for alphas function
let mut alphas = |q2: f64| {
let result: f64 = alphas.call1(py, (q2,)).unwrap().extract(py).unwrap();
result
};

todo!()
let mut xfx_funcs: Vec<_> = xfxs
.iter()
.map(|xfx| {
move |id: i32, x: f64, q2: f64| {
xfx.call1(py, (id, x, q2)).unwrap().extract(py).unwrap()
}
})
.collect();

let mut lumi_cache = ConvolutionCache::new(
pdg_convs.into_iter().map(|pdg| pdg.conv.clone()).collect(),
xfx_funcs
.iter_mut()
.map(|fx| fx as &mut dyn FnMut(i32, f64, f64) -> f64)
.collect(),
&mut alphas,
);

self.grid
.convolve(
&mut lumi_cache,
&order_mask.unwrap_or_default(),
&bin_indices.unwrap_or_default(),
&channel_mask.unwrap_or_default(),
&xi.unwrap_or_else(|| vec![(1.0, 1.0, 0.0)]),
)
.into_pyarray_bound(py)
}

/// Collect information for convolution with an evolution operator.
Expand Down Expand Up @@ -684,7 +709,7 @@ impl PyGrid {
/// bin_indices : numpy.ndarray[int]
/// list of indices of bins to removed
pub fn delete_bins(&mut self, bin_indices: Vec<usize>) {
self.grid.delete_bins(&bin_indices)
self.grid.delete_bins(&bin_indices);
}
}

Expand Down
8 changes: 8 additions & 0 deletions pineappl_py/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def test_convolve_with_two(self):
),
[2**3 * v, 0.0],
)
np.testing.assert_allclose(
g.convolve(
pdg_convs=[CONVOBJECT, CONVOBJECT],
xfxs=[lambda pid, x, q2: 1.0, lambda pid, x, q2: 1.0],
alphas=lambda q2: 2.0,
),
[2**3 * v, 0.0],
) # Test using the generalized convolution
np.testing.assert_allclose(
g.convolve_with_two(
pdg_conv1=CONVOBJECT,
Expand Down

0 comments on commit f1574a3

Please sign in to comment.