Skip to content

Commit

Permalink
Remove Grid.convolve_subgrid from Python API
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Feb 5, 2025
1 parent e39af43 commit f872205
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 97 deletions.
51 changes: 0 additions & 51 deletions pineappl_py/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,57 +427,6 @@ impl PyGrid {
.into_pyarray_bound(py)
}

/// Convolve a single subgrid `(order, bin, channel)` with the distributions.
///
/// # Panics
/// TODO
#[must_use]
#[pyo3(signature = (pdg_convs, xfxs, alphas, ord, bin, channel, xi = None))]
pub fn convolve_subgrid<'py>(
&self,
pdg_convs: Vec<PyRef<PyConv>>,
xfxs: Vec<PyObject>,
alphas: PyObject,
ord: usize,
bin: usize,
channel: usize,
xi: Option<(f64, f64, f64)>,
py: Python<'py>,
) -> Bound<'py, PyArrayDyn<f64>> {
let mut alphas = |q2: f64| {
let result: f64 = alphas.call1(py, (q2,)).unwrap().extract(py).unwrap();
result
};

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 convolution_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_subgrid(
&mut convolution_cache,
ord,
bin,
channel,
xi.unwrap_or((1.0, 1.0, 0.0)),
)
.into_pyarray_bound(py)
}

/// Collect information for convolution with an evolution operator.
///
/// # Panics
Expand Down
46 changes: 0 additions & 46 deletions pineappl_py/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,52 +433,6 @@ def test_polarized_convolution(
expected_results,
)

def test_convolve_subgrid(self, fake_grids):
binning = [1e-2, 1e-1, 0.5, 1]
g = fake_grids.grid_with_generic_convolution(
nb_convolutions=2,
channels=CHANNELS,
orders=ORDERS,
convolutions=[CONVOBJECT, CONVOBJECT],
bins=binning,
)

# Fill the grid with `fill_array`
rndgen = Generator(PCG64(seed=1234))
ntuples = [
np.array([q2, x1, x2])
for q2, x1, x2 in itertools.product(Q2GRID, XGRID, XGRID)
]
obs = [rndgen.uniform(binning[0], binning[-1]) for _ in ntuples]
for pto in range(len(ORDERS)):
for channel_id in range(len(CHANNELS)):
g.fill_array(
order=pto,
observables=obs,
channel=channel_id,
ntuples=ntuples,
weights=np.repeat(10, len(obs)),
)

ptos_res = []
for pto in range(len(g.orders())):
res_by_bin = []
for bin in range(g.bins()):
res_by_channel = 0
for channel in range(len(g.channels())):
res_by_channel += g.convolve_subgrid(
pdg_convs=[CONVOBJECT, CONVOBJECT],
xfxs=[lambda pid, x, q2: x, lambda pid, x, q2: x],
alphas=lambda q2: 1.0,
ord=pto,
bin=bin,
channel=channel,
).sum()
res_by_bin.append(res_by_channel)
ptos_res.append(res_by_bin)

np.testing.assert_allclose(ptos_res, [FILL_CONV_RESUTLS])

def test_many_convolutions(self, fake_grids, pdf, nb_convolutions: int = 3):
"""Test for fun many convolutions."""
expected_results = [
Expand Down

0 comments on commit f872205

Please sign in to comment.