From f8722053f9dba0b12cd15945ee8758732e2c0c12 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Wed, 5 Feb 2025 13:36:16 +0100 Subject: [PATCH] Remove `Grid.convolve_subgrid` from Python API --- pineappl_py/src/grid.rs | 51 ---------------------------------- pineappl_py/tests/test_grid.py | 46 ------------------------------ 2 files changed, 97 deletions(-) diff --git a/pineappl_py/src/grid.rs b/pineappl_py/src/grid.rs index 0c3c0fee..b96efd04 100644 --- a/pineappl_py/src/grid.rs +++ b/pineappl_py/src/grid.rs @@ -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>, - xfxs: Vec, - alphas: PyObject, - ord: usize, - bin: usize, - channel: usize, - xi: Option<(f64, f64, f64)>, - py: Python<'py>, - ) -> Bound<'py, PyArrayDyn> { - 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 diff --git a/pineappl_py/tests/test_grid.py b/pineappl_py/tests/test_grid.py index 6a7a0a26..c868d29e 100644 --- a/pineappl_py/tests/test_grid.py +++ b/pineappl_py/tests/test_grid.py @@ -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 = [