Skip to content

Commit

Permalink
fix: Provide default values using options
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Apr 16, 2024
1 parent c42be03 commit 3f2fbf9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pineappl_py/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use pineappl::fk_table::{FkAssumptions, FkTable};
use pineappl::grid::Grid;
use pineappl::lumi::LumiCache;

use numpy::{IntoPyArray, PyArray1, PyArray4, PyReadonlyArray1};
use numpy::{pyarray, IntoPyArray, PyArray1, PyArray4, PyReadonlyArray1};
use pyo3::prelude::*;

use std::collections::HashMap;
Expand Down Expand Up @@ -214,24 +214,30 @@ impl PyFkTable {
/// -------
/// numpy.ndarray(float) :
/// cross sections for all bins
#[pyo3(signature = (pdf_id, xfx, bin_indices = pyarray![].readonly(), lumi_cache = pyarray![].readonly()))]
#[pyo3(signature = (pdg_id, xfx, bin_indices = None, lumi_mask= None))]
pub fn convolute_with_one<'py>(
&self,
pdg_id: i32,
xfx: &PyAny,
bin_indices: PyReadonlyArray1<usize>,
lumi_mask: PyReadonlyArray1<bool>,
bin_indices: Option<PyReadonlyArray1<usize>>,
lumi_mask: Option<PyReadonlyArray1<bool>>,
py: Python<'py>,
) -> &'py PyArray1<f64> {
let mut xfx = |id, x, q2| f64::extract(xfx.call1((id, x, q2)).unwrap()).unwrap();
let mut alphas = |_| 1.0;
let mut lumi_cache = LumiCache::with_one(pdg_id, &mut xfx, &mut alphas);
let bin_indices = if let Some(b) = bin_indices {
b.to_vec().unwrap()
} else {
vec![]
};
let lumi_mask = if let Some(l) = lumi_mask {
l.to_vec().unwrap()
} else {
vec![]
};
self.fk_table
.convolute(
&mut lumi_cache,
&bin_indices.to_vec().unwrap(),
&lumi_mask.to_vec().unwrap(),
)
.convolute(&mut lumi_cache, &bin_indices, &lumi_mask)
.into_pyarray(py)
}

Expand Down

0 comments on commit 3f2fbf9

Please sign in to comment.