From 3f2fbf98667af782d539d4b15da3e79149d05de9 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 16 Apr 2024 14:04:00 +0200 Subject: [PATCH] fix: Provide default values using options --- pineappl_py/src/fk_table.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pineappl_py/src/fk_table.rs b/pineappl_py/src/fk_table.rs index a74e26a6..8e386c62 100644 --- a/pineappl_py/src/fk_table.rs +++ b/pineappl_py/src/fk_table.rs @@ -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; @@ -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, - lumi_mask: PyReadonlyArray1, + bin_indices: Option>, + lumi_mask: Option>, py: Python<'py>, ) -> &'py PyArray1 { 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) }