Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python list arguments #308

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pineappl_py/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ impl PyGrid {
pdg_id: i32,
xfx: &Bound<'py, PyAny>,
alphas: &Bound<'py, PyAny>,
order_mask: Option<PyReadonlyArray1<bool>>,
bin_indices: Option<PyReadonlyArray1<usize>>,
channel_mask: Option<PyReadonlyArray1<bool>>,
order_mask: Option<Vec<bool>>,
bin_indices: Option<Vec<usize>>,
channel_mask: Option<Vec<bool>>,
xi: Option<Vec<(f64, f64)>>,
py: Python<'py>,
) -> Bound<'py, PyArray1<f64>> {
Expand All @@ -280,9 +280,9 @@ impl PyGrid {
self.grid
.convolve(
&mut lumi_cache,
&order_mask.map_or(vec![], |b| b.to_vec().unwrap()),
&bin_indices.map_or(vec![], |c| c.to_vec().unwrap()),
&channel_mask.map_or(vec![], |d| d.to_vec().unwrap()),
&order_mask.map_or(vec![], |b| b.to_vec()),
&bin_indices.map_or(vec![], |c| c.to_vec()),
&channel_mask.map_or(vec![], |d| d.to_vec()),
&xi.map_or(vec![(1.0, 1.0)], |m| m),
)
.into_pyarray_bound(py)
Expand Down Expand Up @@ -332,9 +332,9 @@ impl PyGrid {
pdg_id2: i32,
xfx2: &Bound<'py, PyAny>,
alphas: &Bound<'py, PyAny>,
order_mask: Option<PyReadonlyArray1<bool>>,
bin_indices: Option<PyReadonlyArray1<usize>>,
channel_mask: Option<PyReadonlyArray1<bool>>,
order_mask: Option<Vec<bool>>,
bin_indices: Option<Vec<usize>>,
channel_mask: Option<Vec<bool>>,
xi: Option<Vec<(f64, f64)>>,
py: Python<'py>,
) -> Bound<'py, PyArray1<f64>> {
Expand All @@ -347,9 +347,9 @@ impl PyGrid {
self.grid
.convolve(
&mut lumi_cache,
&order_mask.map_or(vec![], |b| b.to_vec().unwrap()),
&bin_indices.map_or(vec![], |c| c.to_vec().unwrap()),
&channel_mask.map_or(vec![], |d| d.to_vec().unwrap()),
&order_mask.map_or(vec![], |b| b.to_vec()),
&bin_indices.map_or(vec![], |c| c.to_vec()),
&channel_mask.map_or(vec![], |d| d.to_vec()),
&xi.map_or(vec![(1.0, 1.0)], |m| m),
)
.into_pyarray_bound(py)
Expand Down
39 changes: 37 additions & 2 deletions pineappl_py/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,48 @@ def test_convolve_with_one(self):
g.convolve_with_one(2212, lambda pid, x, q2: 0.0, lambda q2: 0.0),
[0.0] * 2,
)
v = 5e6 / 9999
np.testing.assert_allclose(
g.convolve_with_one(2212, lambda pid, x, q2: 1, lambda q2: 1.0),
[5e6 / 9999, 0.0],
[v, 0.0],
)
np.testing.assert_allclose(
g.convolve_with_one(
2212, lambda pid, x, q2: 1, lambda q2: 1.0, bin_indices=[0]
),
[v],
)
# block first bins with additional args
np.testing.assert_allclose(
g.convolve_with_one(
2212,
lambda pid, x, q2: 1,
lambda q2: 1.0,
bin_indices=[0],
order_mask=[False],
),
[0.0],
)
np.testing.assert_allclose(
g.convolve_with_one(
2212,
lambda pid, x, q2: 1,
lambda q2: 1.0,
bin_indices=[0],
channel_mask=[False],
),
[0.0],
)
# second bin is empty
np.testing.assert_allclose(
g.convolve_with_one(
2212, lambda pid, x, q2: 1, lambda q2: 1.0, bin_indices=[1]
),
[0.0],
)
np.testing.assert_allclose(
g.convolve_with_one(2212, lambda pid, x, q2: 1, lambda q2: 2.0),
[2**3 * 5e6 / 9999, 0.0],
[2**3 * v, 0.0],
)

def test_io(self, tmp_path):
Expand Down