Skip to content

Commit f4bdde0

Browse files
committed
Change pineappl_grid_new2 function
- renamed `InterpTuples` to `InterpInfo` and named members like `Interp` - made members of `InterpInfo` public - reordered parameters of `pineappl_grid_new2` to have the same ordering as `Grid::new` - added new parameter `interpolations` that counts the number of interpolations, which in general is different from the number of convolutions plus one (previous assumption) - removed `nb_convolutions`, which can be inferred from the channels
1 parent aa2b1ca commit f4bdde0

4 files changed

Lines changed: 68 additions & 57 deletions

File tree

examples/cpp/advanced-filling.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int main() {
5656
pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method
5757
pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2;
5858
pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE;
59-
pineappl_interp_tuples interpolations[3] = {
59+
pineappl_interp interpolations[3] = {
6060
{ 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales`
6161
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1`
6262
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2`
@@ -71,8 +71,8 @@ int main() {
7171
// create a new grid with the previously defined channels, 3 perturbative orders defined by the
7272
// exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra
7373
// parameters in `keyval`.
74-
auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1,
75-
bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales);
74+
auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(),
75+
channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales);
7676

7777
// now we no longer need `channels`
7878
pineappl_channels_delete(channels);

examples/cpp/fill-grid.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int main() {
201201
pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method
202202
pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2;
203203
pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE;
204-
pineappl_interp_tuples interpolations[3] = {
204+
pineappl_interp interpolations[3] = {
205205
{ 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales`
206206
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1`
207207
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2`
@@ -216,8 +216,8 @@ int main() {
216216
// create a new grid with the previously defined channels, 3 perturbative orders defined by the
217217
// exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra
218218
// parameters in `keyval`.
219-
auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1,
220-
bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales);
219+
auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(),
220+
channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales);
221221

222222
// now we no longer need `keyval` and `channels`
223223
pineappl_channels_delete(channels);

pineappl_capi/cbindgen.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rename_variants = "ScreamingSnakeCase"
4343
"ReweightMeth" = "pineappl_reweight_meth"
4444
"Map" = "pineappl_map"
4545
"InterpMeth" = "pineappl_interp_meth"
46-
"InterpTuples" = "pineappl_interp_tuples"
46+
"Interp" = "pineappl_interp"
4747
"KeyVal" = "pineappl_keyval"
4848
"SubGrid" = "pineappl_subgrid"
4949
"GridOptFlags" = "pineappl_gof"

pineappl_capi/src/lib.rs

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use itertools::izip;
5959
use pineappl::boc::{Bin, BinsWithFillLimits, Channel, Kinematics, Order, ScaleFuncForm, Scales};
6060
use pineappl::convolutions::{Conv, ConvType, ConvolutionCache};
6161
use pineappl::grid::{Grid, GridOptFlags};
62-
use pineappl::interpolation::{Interp, InterpMeth, Map, ReweightMeth};
62+
use pineappl::interpolation::{Interp as InterpMain, InterpMeth, Map, ReweightMeth};
6363
use pineappl::packed_array::ravel_multi_index;
6464
use pineappl::pids::PidBasis;
6565
use pineappl::subgrid::Subgrid;
@@ -91,7 +91,7 @@ pub const PINEAPPL_GOF_STRIP_EMPTY_CHANNELS: GridOptFlags = GridOptFlags::STRIP_
9191

9292
// TODO: make sure no `panic` calls leave functions marked as `extern "C"`
9393

94-
fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec<Interp> {
94+
fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec<InterpMain> {
9595
let mut q2_min = 1e2;
9696
let mut q2_max = 1e8;
9797
let mut q2_nodes = 40;
@@ -213,7 +213,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec<Interp> {
213213
}
214214

215215
vec![
216-
Interp::new(
216+
InterpMain::new(
217217
q2_min,
218218
q2_max,
219219
q2_nodes,
@@ -222,7 +222,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec<Interp> {
222222
Map::ApplGridH0,
223223
InterpMeth::Lagrange,
224224
),
225-
Interp::new(
225+
InterpMain::new(
226226
x1_min,
227227
x1_max,
228228
x1_nodes,
@@ -231,7 +231,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec<Interp> {
231231
Map::ApplGridF2,
232232
InterpMeth::Lagrange,
233233
),
234-
Interp::new(
234+
InterpMain::new(
235235
x2_min,
236236
x2_max,
237237
x2_nodes,
@@ -1465,27 +1465,21 @@ pub struct Channels(Vec<Channel>);
14651465

14661466
/// Type for defining the interpolation object
14671467
#[repr(C)]
1468-
pub struct InterpTuples {
1469-
node_min: f64,
1470-
node_max: f64,
1471-
nb_nodes: usize,
1472-
interp_degree: usize,
1473-
reweighting_method: ReweightMeth,
1474-
mapping: Map,
1475-
interpolation_method: InterpMeth,
1476-
}
1477-
1478-
#[must_use]
1479-
fn construct_interpolation(interp: &InterpTuples) -> Interp {
1480-
Interp::new(
1481-
interp.node_min,
1482-
interp.node_max,
1483-
interp.nb_nodes,
1484-
interp.interp_degree,
1485-
interp.reweighting_method,
1486-
interp.mapping,
1487-
interp.interpolation_method,
1488-
)
1468+
pub struct Interp {
1469+
/// TODO
1470+
pub min: f64,
1471+
/// TODO
1472+
pub max: f64,
1473+
/// TODO
1474+
pub nodes: usize,
1475+
/// TODO
1476+
pub order: usize,
1477+
/// TODO
1478+
pub reweight: ReweightMeth,
1479+
/// TODO
1480+
pub map: Map,
1481+
/// TODO
1482+
pub interp_meth: InterpMeth,
14891483
}
14901484

14911485
/// An exact duplicate of `pineappl_lumi_new` to make naming (lumi -> channel) consistent.
@@ -1605,30 +1599,32 @@ pub extern "C" fn pineappl_channels_delete(channels: Option<Box<Channels>>) {}
16051599
/// `0` -> `ScaleFuncForm::NoScale`, ..., `n` -> `ScaleFuncForm::Scale(n - 1)`.
16061600
///
16071601
/// # Safety
1602+
///
16081603
/// TODO
16091604
///
16101605
/// # Panics
1606+
///
16111607
/// TODO
16121608
#[no_mangle]
16131609
#[must_use]
16141610
pub unsafe extern "C" fn pineappl_grid_new2(
1615-
pid_basis: PidBasis,
1616-
channels: *const Channels,
1617-
orders: usize,
1618-
order_params: *const u8,
16191611
bins: usize,
16201612
bin_limits: *const f64,
1621-
nb_convolutions: usize,
1613+
orders: usize,
1614+
order_params: *const u8,
1615+
channels: *const Channels,
1616+
pid_basis: PidBasis,
16221617
convolution_types: *const ConvType,
1623-
pdg_ids: *const c_int,
1618+
convolution_pdg_ids: *const c_int,
1619+
interpolations: usize,
1620+
interp_info: *const Interp,
16241621
kinematics: *const Kinematics,
1625-
interpolations: *const InterpTuples,
16261622
mu_scales: *const usize,
16271623
) -> Box<Grid> {
1628-
// Luminosity channels
1629-
let channels = unsafe { &*channels };
1630-
1631-
// Perturbative orders
1624+
let bins = BinsWithFillLimits::from_fill_limits(
1625+
unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(),
1626+
)
1627+
.unwrap();
16321628
let order_params = unsafe { slice::from_raw_parts(order_params, 5 * orders) };
16331629
let orders: Vec<_> = order_params
16341630
.chunks(5)
@@ -1640,32 +1636,47 @@ pub unsafe extern "C" fn pineappl_grid_new2(
16401636
logxia: s[4],
16411637
})
16421638
.collect();
1643-
1644-
let bins = BinsWithFillLimits::from_fill_limits(
1645-
unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(),
1646-
)
1647-
.unwrap();
1639+
let channels = unsafe { &*channels };
16481640

16491641
// Construct the convolution objects
1642+
let convolutions = channels.0[0].entry()[0].0.len();
16501643
let convolution_types =
1651-
unsafe { slice::from_raw_parts(convolution_types, nb_convolutions).to_vec() };
1652-
let pdg_ids = unsafe { slice::from_raw_parts(pdg_ids, nb_convolutions).to_vec() };
1653-
let convolutions = izip!(convolution_types.iter(), pdg_ids.iter())
1654-
.map(|(&conv, &pdg_value)| Conv::new(conv, pdg_value))
1644+
unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() };
1645+
let convolution_pdg_ids =
1646+
unsafe { slice::from_raw_parts(convolution_pdg_ids, convolutions).to_vec() };
1647+
let convolutions = convolution_types
1648+
.iter()
1649+
.zip(convolution_pdg_ids)
1650+
.map(|(&convolution_type, pdg_id)| Conv::new(convolution_type, pdg_id))
16551651
.collect();
16561652

16571653
// Grid interpolations
1658-
let interp_slices = unsafe { std::slice::from_raw_parts(interpolations, nb_convolutions + 1) };
1659-
let interp_vecs: Vec<Interp> = interp_slices.iter().map(construct_interpolation).collect();
1654+
let interp_slices = unsafe { std::slice::from_raw_parts(interp_info, interpolations) };
1655+
let interp_vecs: Vec<_> = interp_slices
1656+
.iter()
1657+
.map(|interp| {
1658+
InterpMain::new(
1659+
interp.min,
1660+
interp.max,
1661+
interp.nodes,
1662+
interp.order,
1663+
interp.reweight,
1664+
interp.map,
1665+
interp.interp_meth,
1666+
)
1667+
})
1668+
.collect();
16601669

16611670
// Construct the kinematic variables
1662-
let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()).to_vec() };
1671+
let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()) }.to_vec();
16631672

16641673
// Scales. An array containing the values of {ren, fac, frg}
16651674
let mu_scales = unsafe { std::slice::from_raw_parts(mu_scales, 3) };
1666-
let mu_scales_vec: Vec<ScaleFuncForm> = mu_scales
1675+
let mu_scales_vec: Vec<_> = mu_scales
16671676
.iter()
16681677
.map(|&scale| {
1678+
// TODO: this doesn't allow all other `ScaleFuncForm`, for instance
1679+
// `ScaleFuncForm::QuadraticSum`
16691680
if scale == 0 {
16701681
ScaleFuncForm::NoScale
16711682
} else {

0 commit comments

Comments
 (0)