From aa2b1ca91368c163910937443edf9d58aed39f17 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 15 Apr 2025 17:50:13 +0200 Subject: [PATCH 01/16] Mark v0 functions deprecated --- pineappl_capi/src/lib.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index c28ee961..0bfe06ec 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -368,7 +368,7 @@ pub unsafe extern "C" fn pineappl_grid_clone(grid: *const Grid) -> Box { /// See [`pineappl_grid_convolve_with_one`]. #[deprecated( since = "0.8.0", - note = "please use `pineappl_grid_convolve_with_one` instead" + note = "use `pineappl_grid_convolve_with_one` instead" )] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_convolute_with_one( @@ -406,7 +406,7 @@ pub unsafe extern "C" fn pineappl_grid_convolute_with_one( /// See [`pineappl_grid_convolve_with_two`]. #[deprecated( since = "0.8.0", - note = "please use `pineappl_grid_convolve_with_two` instead" + note = "use `pineappl_grid_convolve_with_two` instead" )] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_convolute_with_two( @@ -601,6 +601,7 @@ pub extern "C" fn pineappl_grid_delete(grid: Option>) {} /// /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_fill2` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_fill( grid: *mut Grid, @@ -625,6 +626,7 @@ pub unsafe extern "C" fn pineappl_grid_fill( /// /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_fill_all2` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_fill_all( grid: *mut Grid, @@ -650,6 +652,7 @@ pub unsafe extern "C" fn pineappl_grid_fill_all( /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. Additionally, all remaining pointer parameters must be /// arrays as long as specified by `size`. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_fill_array2` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_fill_array( grid: *mut Grid, @@ -684,6 +687,7 @@ pub unsafe extern "C" fn pineappl_grid_fill_array( /// /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_channels` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_lumi(grid: *const Grid) -> Box { let grid = unsafe { &*grid }; @@ -698,6 +702,7 @@ pub unsafe extern "C" fn pineappl_grid_lumi(grid: *const Grid) -> Box { /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. The pointer `order_params` must point to an array as large /// as four times the number of orders in `grid`. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_order_params2` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_order_params(grid: *const Grid, order_params: *mut u32) { let grid = unsafe { &*grid }; @@ -750,6 +755,7 @@ pub unsafe extern "C" fn pineappl_grid_order_count(grid: *const Grid) -> usize { /// # Panics /// /// TODO +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_new2` instead")] #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_grid_new( @@ -890,6 +896,7 @@ pub unsafe extern "C" fn pineappl_grid_scale(grid: *mut Grid, factor: f64) { /// /// If `grid` does not point to a valid `Grid` object, for example when `grid` is the null pointer, /// this function is not safe to call. +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_split_channels` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_split_lumi(grid: *mut Grid) { let grid = unsafe { &mut *grid }; @@ -1005,6 +1012,7 @@ pub unsafe extern "C" fn pineappl_grid_scale_by_order( /// # Panics /// /// TODO +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_metadata` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_key_value( grid: *const Grid, @@ -1043,6 +1051,7 @@ pub unsafe extern "C" fn pineappl_grid_key_value( /// # Panics /// /// TODO +#[deprecated(since = "1.0.0", note = "use `pineappl_grid_set_metadata` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_grid_set_key_value( grid: *mut Grid, @@ -1153,6 +1162,7 @@ pub unsafe extern "C" fn pineappl_grid_write(grid: *const Grid, filename: *const /// The parameter `lumi` must point to a valid `Lumi` object created by `pineappl_lumi_new`. /// `pdg_id_pairs` must be an array with length `2 * combinations`, and `factors` with length of /// `combinations`. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_add` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_lumi_add( lumi: *mut Lumi, @@ -1183,6 +1193,7 @@ pub unsafe extern "C" fn pineappl_lumi_add( /// /// The parameter `lumi` must point to a valid `Lumi` object created by `pineappl_lumi_new` or /// `pineappl_grid_lumi`. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_combinations` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_lumi_combinations(lumi: *const Lumi, entry: usize) -> usize { let lumi = unsafe { &*lumi }; @@ -1196,6 +1207,7 @@ pub unsafe extern "C" fn pineappl_lumi_combinations(lumi: *const Lumi, entry: us /// /// The parameter `lumi` must point to a valid `Lumi` object created by `pineappl_lumi_new` or /// `pineappl_grid_lumi`. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_count` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_lumi_count(lumi: *const Lumi) -> usize { let lumi = unsafe { &*lumi }; @@ -1204,6 +1216,7 @@ pub unsafe extern "C" fn pineappl_lumi_count(lumi: *const Lumi) -> usize { } /// Delete luminosity function previously created with `pineappl_lumi_new`. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_delete` instead")] #[no_mangle] #[allow(unused_variables)] pub extern "C" fn pineappl_lumi_delete(lumi: Option>) {} @@ -1217,6 +1230,7 @@ pub extern "C" fn pineappl_lumi_delete(lumi: Option>) {} /// `pineappl_grid_lumi`. The parameter `factors` must point to an array as long as the size /// returned by `pineappl_lumi_combinations` and `pdg_ids` must point to an array that is twice as /// long. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_entry` instead")] #[no_mangle] pub unsafe extern "C" fn pineappl_lumi_entry( lumi: *const Lumi, @@ -1243,6 +1257,7 @@ pub unsafe extern "C" fn pineappl_lumi_entry( /// Creates a new luminosity function and returns a pointer to it. If no longer needed, the object /// should be deleted using `pineappl_lumi_delete`. +#[deprecated(since = "1.0.0", note = "use `pineappl_channels_new` instead")] #[no_mangle] #[must_use] pub extern "C" fn pineappl_lumi_new() -> Box { @@ -1260,6 +1275,7 @@ pub struct KeyVal { } /// Delete the previously created object pointed to by `key_vals`. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[allow(unused_variables)] pub extern "C" fn pineappl_keyval_delete(key_vals: Option>) {} @@ -1270,6 +1286,7 @@ pub extern "C" fn pineappl_keyval_delete(key_vals: Option>) {} /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_keyval_bool(key_vals: *const KeyVal, key: *const c_char) -> bool { @@ -1285,6 +1302,7 @@ pub unsafe extern "C" fn pineappl_keyval_bool(key_vals: *const KeyVal, key: *con /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_keyval_double( @@ -1303,6 +1321,7 @@ pub unsafe extern "C" fn pineappl_keyval_double( /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_keyval_int(key_vals: *const KeyVal, key: *const c_char) -> i32 { @@ -1318,6 +1337,7 @@ pub unsafe extern "C" fn pineappl_keyval_int(key_vals: *const KeyVal, key: *cons /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_keyval_string( @@ -1331,6 +1351,7 @@ pub unsafe extern "C" fn pineappl_keyval_string( } /// Return a pointer to newly-created `pineappl_keyval` object. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] #[must_use] pub extern "C" fn pineappl_keyval_new() -> Box { @@ -1343,6 +1364,7 @@ pub extern "C" fn pineappl_keyval_new() -> Box { /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] pub unsafe extern "C" fn pineappl_keyval_set_bool( key_vals: *mut KeyVal, @@ -1363,6 +1385,7 @@ pub unsafe extern "C" fn pineappl_keyval_set_bool( /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] pub unsafe extern "C" fn pineappl_keyval_set_double( key_vals: *mut KeyVal, @@ -1383,6 +1406,7 @@ pub unsafe extern "C" fn pineappl_keyval_set_double( /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] pub unsafe extern "C" fn pineappl_keyval_set_int( key_vals: *mut KeyVal, @@ -1403,6 +1427,7 @@ pub unsafe extern "C" fn pineappl_keyval_set_int( /// /// The parameter `key_vals` must point to a valid `KeyVal` object created by /// `pineappl_keyval_new`. `key` must be a valid C string. +#[deprecated(since = "1.0.0", note = "")] #[no_mangle] pub unsafe extern "C" fn pineappl_keyval_set_string( key_vals: *mut KeyVal, From f4bdde0bbba070f2144837cc8fe6c7b23cf0e569 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 15 Apr 2025 18:08:40 +0200 Subject: [PATCH 02/16] 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 --- examples/cpp/advanced-filling.cpp | 6 +- examples/cpp/fill-grid.cpp | 6 +- pineappl_capi/cbindgen.toml | 2 +- pineappl_capi/src/lib.rs | 111 ++++++++++++++++-------------- 4 files changed, 68 insertions(+), 57 deletions(-) diff --git a/examples/cpp/advanced-filling.cpp b/examples/cpp/advanced-filling.cpp index 8c7a4a72..38382deb 100644 --- a/examples/cpp/advanced-filling.cpp +++ b/examples/cpp/advanced-filling.cpp @@ -56,7 +56,7 @@ int main() { pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2; pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE; - pineappl_interp_tuples interpolations[3] = { + pineappl_interp interpolations[3] = { { 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales` { 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1` { 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2` @@ -71,8 +71,8 @@ int main() { // create a new grid with the previously defined channels, 3 perturbative orders defined by the // exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra // parameters in `keyval`. - auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1, - bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales); + auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(), + channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales); // now we no longer need `channels` pineappl_channels_delete(channels); diff --git a/examples/cpp/fill-grid.cpp b/examples/cpp/fill-grid.cpp index b45c4939..2722594a 100644 --- a/examples/cpp/fill-grid.cpp +++ b/examples/cpp/fill-grid.cpp @@ -201,7 +201,7 @@ int main() { pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2; pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE; - pineappl_interp_tuples interpolations[3] = { + pineappl_interp interpolations[3] = { { 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales` { 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1` { 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2` @@ -216,8 +216,8 @@ int main() { // create a new grid with the previously defined channels, 3 perturbative orders defined by the // exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra // parameters in `keyval`. - auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1, - bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales); + auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(), + channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales); // now we no longer need `keyval` and `channels` pineappl_channels_delete(channels); diff --git a/pineappl_capi/cbindgen.toml b/pineappl_capi/cbindgen.toml index 8a07de99..8a79d97d 100644 --- a/pineappl_capi/cbindgen.toml +++ b/pineappl_capi/cbindgen.toml @@ -43,7 +43,7 @@ rename_variants = "ScreamingSnakeCase" "ReweightMeth" = "pineappl_reweight_meth" "Map" = "pineappl_map" "InterpMeth" = "pineappl_interp_meth" -"InterpTuples" = "pineappl_interp_tuples" +"Interp" = "pineappl_interp" "KeyVal" = "pineappl_keyval" "SubGrid" = "pineappl_subgrid" "GridOptFlags" = "pineappl_gof" diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index 0bfe06ec..863b6c59 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -59,7 +59,7 @@ use itertools::izip; use pineappl::boc::{Bin, BinsWithFillLimits, Channel, Kinematics, Order, ScaleFuncForm, Scales}; use pineappl::convolutions::{Conv, ConvType, ConvolutionCache}; use pineappl::grid::{Grid, GridOptFlags}; -use pineappl::interpolation::{Interp, InterpMeth, Map, ReweightMeth}; +use pineappl::interpolation::{Interp as InterpMain, InterpMeth, Map, ReweightMeth}; use pineappl::packed_array::ravel_multi_index; use pineappl::pids::PidBasis; use pineappl::subgrid::Subgrid; @@ -91,7 +91,7 @@ pub const PINEAPPL_GOF_STRIP_EMPTY_CHANNELS: GridOptFlags = GridOptFlags::STRIP_ // TODO: make sure no `panic` calls leave functions marked as `extern "C"` -fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec { +fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec { let mut q2_min = 1e2; let mut q2_max = 1e8; let mut q2_nodes = 40; @@ -213,7 +213,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec { } vec![ - Interp::new( + InterpMain::new( q2_min, q2_max, q2_nodes, @@ -222,7 +222,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec { Map::ApplGridH0, InterpMeth::Lagrange, ), - Interp::new( + InterpMain::new( x1_min, x1_max, x1_nodes, @@ -231,7 +231,7 @@ fn grid_interpolation_params(key_vals: Option<&KeyVal>) -> Vec { Map::ApplGridF2, InterpMeth::Lagrange, ), - Interp::new( + InterpMain::new( x2_min, x2_max, x2_nodes, @@ -1465,27 +1465,21 @@ pub struct Channels(Vec); /// Type for defining the interpolation object #[repr(C)] -pub struct InterpTuples { - node_min: f64, - node_max: f64, - nb_nodes: usize, - interp_degree: usize, - reweighting_method: ReweightMeth, - mapping: Map, - interpolation_method: InterpMeth, -} - -#[must_use] -fn construct_interpolation(interp: &InterpTuples) -> Interp { - Interp::new( - interp.node_min, - interp.node_max, - interp.nb_nodes, - interp.interp_degree, - interp.reweighting_method, - interp.mapping, - interp.interpolation_method, - ) +pub struct Interp { + /// TODO + pub min: f64, + /// TODO + pub max: f64, + /// TODO + pub nodes: usize, + /// TODO + pub order: usize, + /// TODO + pub reweight: ReweightMeth, + /// TODO + pub map: Map, + /// TODO + pub interp_meth: InterpMeth, } /// 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>) {} /// `0` -> `ScaleFuncForm::NoScale`, ..., `n` -> `ScaleFuncForm::Scale(n - 1)`. /// /// # Safety +/// /// TODO /// /// # Panics +/// /// TODO #[no_mangle] #[must_use] pub unsafe extern "C" fn pineappl_grid_new2( - pid_basis: PidBasis, - channels: *const Channels, - orders: usize, - order_params: *const u8, bins: usize, bin_limits: *const f64, - nb_convolutions: usize, + orders: usize, + order_params: *const u8, + channels: *const Channels, + pid_basis: PidBasis, convolution_types: *const ConvType, - pdg_ids: *const c_int, + convolution_pdg_ids: *const c_int, + interpolations: usize, + interp_info: *const Interp, kinematics: *const Kinematics, - interpolations: *const InterpTuples, mu_scales: *const usize, ) -> Box { - // Luminosity channels - let channels = unsafe { &*channels }; - - // Perturbative orders + let bins = BinsWithFillLimits::from_fill_limits( + unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(), + ) + .unwrap(); let order_params = unsafe { slice::from_raw_parts(order_params, 5 * orders) }; let orders: Vec<_> = order_params .chunks(5) @@ -1640,32 +1636,47 @@ pub unsafe extern "C" fn pineappl_grid_new2( logxia: s[4], }) .collect(); - - let bins = BinsWithFillLimits::from_fill_limits( - unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(), - ) - .unwrap(); + let channels = unsafe { &*channels }; // Construct the convolution objects + let convolutions = channels.0[0].entry()[0].0.len(); let convolution_types = - unsafe { slice::from_raw_parts(convolution_types, nb_convolutions).to_vec() }; - let pdg_ids = unsafe { slice::from_raw_parts(pdg_ids, nb_convolutions).to_vec() }; - let convolutions = izip!(convolution_types.iter(), pdg_ids.iter()) - .map(|(&conv, &pdg_value)| Conv::new(conv, pdg_value)) + unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() }; + let convolution_pdg_ids = + unsafe { slice::from_raw_parts(convolution_pdg_ids, convolutions).to_vec() }; + let convolutions = convolution_types + .iter() + .zip(convolution_pdg_ids) + .map(|(&convolution_type, pdg_id)| Conv::new(convolution_type, pdg_id)) .collect(); // Grid interpolations - let interp_slices = unsafe { std::slice::from_raw_parts(interpolations, nb_convolutions + 1) }; - let interp_vecs: Vec = interp_slices.iter().map(construct_interpolation).collect(); + let interp_slices = unsafe { std::slice::from_raw_parts(interp_info, interpolations) }; + let interp_vecs: Vec<_> = interp_slices + .iter() + .map(|interp| { + InterpMain::new( + interp.min, + interp.max, + interp.nodes, + interp.order, + interp.reweight, + interp.map, + interp.interp_meth, + ) + }) + .collect(); // Construct the kinematic variables - let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()).to_vec() }; + let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()) }.to_vec(); // Scales. An array containing the values of {ren, fac, frg} let mu_scales = unsafe { std::slice::from_raw_parts(mu_scales, 3) }; - let mu_scales_vec: Vec = mu_scales + let mu_scales_vec: Vec<_> = mu_scales .iter() .map(|&scale| { + // TODO: this doesn't allow all other `ScaleFuncForm`, for instance + // `ScaleFuncForm::QuadraticSum` if scale == 0 { ScaleFuncForm::NoScale } else { From 34ae3b80a5ff91dc0d14d65d04ddaa4e09e76594 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 15 Apr 2025 19:14:49 +0200 Subject: [PATCH 03/16] Specify the number of convolutions once in `pineappl_channels_new` --- examples/cpp/advanced-filling.cpp | 4 ++-- examples/cpp/fill-grid.cpp | 11 ++++------- pineappl_capi/src/lib.rs | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/cpp/advanced-filling.cpp b/examples/cpp/advanced-filling.cpp index 38382deb..ccc603cb 100644 --- a/examples/cpp/advanced-filling.cpp +++ b/examples/cpp/advanced-filling.cpp @@ -11,10 +11,10 @@ int main() { // Construct the channel object based on the nb of convolutions std::size_t nb_convolutions = 2; std::size_t nb_channels = 2; - auto* channels = pineappl_channels_new(); + auto* channels = pineappl_channels_new(nb_convolutions); int32_t pids[] = { 2, -2, 4, -4 }; double factors[] = { 1.0, 1.0 }; - pineappl_channels_add(channels, nb_channels, nb_convolutions, pids, factors); + pineappl_channels_add(channels, nb_channels, pids, factors); std::size_t channel_count = 1; diff --git a/examples/cpp/fill-grid.cpp b/examples/cpp/fill-grid.cpp index 2722594a..81a6413a 100644 --- a/examples/cpp/fill-grid.cpp +++ b/examples/cpp/fill-grid.cpp @@ -115,11 +115,8 @@ int main() { // --- // Create all channels - // this object will contain all channels (initial states) that we define - auto* channels = pineappl_channels_new(); - - // Specify the dimension of the channel, ie the number of convolutions required - std::size_t nb_convolutions = 2; + // this object will contain all channels (for two initial states) that we define + auto* channels = pineappl_channels_new(2); // photon-photon initial state, where `22` is the photon (PDG MC ids) int32_t pids1[] = { 22, 22 }; @@ -128,7 +125,7 @@ int main() { double factors1[] = { 1.0 }; // define the channel #0 - pineappl_channels_add(channels, 1, nb_convolutions, pids1, factors1); + pineappl_channels_add(channels, 1, pids1, factors1); // create another channel, which we won't fill, however @@ -143,7 +140,7 @@ int main() { // can also pass `nullptr` // define the channel #1 - pineappl_channels_add(channels, 3, nb_convolutions, pids2, nullptr); + pineappl_channels_add(channels, 3, pids2, nullptr); // --- // Specify the perturbative orders that will be filled into the grid diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index 863b6c59..0a704cee 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -1461,7 +1461,7 @@ pub unsafe extern "C" fn pineappl_string_delete(string: *mut c_char) { /// Type for defining a Channel function. #[derive(Default)] -pub struct Channels(Vec); +pub struct Channels(Vec, usize); /// Type for defining the interpolation object #[repr(C)] @@ -1486,8 +1486,8 @@ pub struct Interp { /// should be deleted using `pineappl_channels_delete`. #[no_mangle] #[must_use] -pub extern "C" fn pineappl_channels_new() -> Box { - Box::default() +pub extern "C" fn pineappl_channels_new(convolutions: usize) -> Box { + Box::new(Channels(Vec::new(), convolutions)) } /// Adds a generalized linear combination of initial states to the Luminosity. @@ -1503,13 +1503,12 @@ pub extern "C" fn pineappl_channels_new() -> Box { pub unsafe extern "C" fn pineappl_channels_add( channels: *mut Channels, combinations: usize, - nb_convolutions: usize, pdg_id_combinations: *const i32, factors: *const f64, ) { let channels = unsafe { &mut *channels }; let pdg_id_pairs = - unsafe { slice::from_raw_parts(pdg_id_combinations, nb_convolutions * combinations) }; + unsafe { slice::from_raw_parts(pdg_id_combinations, channels.1 * combinations) }; let factors = if factors.is_null() { vec![1.0; combinations] } else { @@ -1518,9 +1517,9 @@ pub unsafe extern "C" fn pineappl_channels_add( channels.0.push(Channel::new( pdg_id_pairs - .chunks(nb_convolutions) + .chunks(channels.1) .zip(factors) - .map(|x| ((0..nb_convolutions).map(|i| x.0[i]).collect(), x.1)) + .map(|x| ((0..channels.1).map(|i| x.0[i]).collect(), x.1)) .collect(), )); } @@ -1535,7 +1534,10 @@ pub unsafe extern "C" fn pineappl_channels_add( pub unsafe extern "C" fn pineappl_grid_channels(grid: *const Grid) -> Box { let grid = unsafe { &*grid }; - Box::new(Channels(grid.channels().to_vec())) + Box::new(Channels( + grid.channels().to_vec(), + grid.convolutions().len(), + )) } /// An exact duplicate of `pineappl_lumi_count` to make naming (lumi -> channel) consistent. @@ -1639,7 +1641,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( let channels = unsafe { &*channels }; // Construct the convolution objects - let convolutions = channels.0[0].entry()[0].0.len(); + let convolutions = channels.1; let convolution_types = unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() }; let convolution_pdg_ids = From 7748c54e27022fb46f9229a61f40f7daeba9230f Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 15 Apr 2025 19:26:46 +0200 Subject: [PATCH 04/16] Convert tuple into struct --- pineappl_capi/src/lib.rs | 59 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index 0a704cee..5032579f 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -1460,8 +1460,11 @@ pub unsafe extern "C" fn pineappl_string_delete(string: *mut c_char) { // Here starts the generalized C-API interface. /// Type for defining a Channel function. -#[derive(Default)] -pub struct Channels(Vec, usize); +#[derive(Clone)] +pub struct Channels { + channels: Vec, + convolutions: usize, +} /// Type for defining the interpolation object #[repr(C)] @@ -1487,7 +1490,10 @@ pub struct Interp { #[no_mangle] #[must_use] pub extern "C" fn pineappl_channels_new(convolutions: usize) -> Box { - Box::new(Channels(Vec::new(), convolutions)) + Box::new(Channels { + channels: Vec::new(), + convolutions, + }) } /// Adds a generalized linear combination of initial states to the Luminosity. @@ -1506,20 +1512,23 @@ pub unsafe extern "C" fn pineappl_channels_add( pdg_id_combinations: *const i32, factors: *const f64, ) { - let channels = unsafe { &mut *channels }; + let &mut Channels { + ref mut channels, + convolutions, + } = unsafe { &mut *channels }; let pdg_id_pairs = - unsafe { slice::from_raw_parts(pdg_id_combinations, channels.1 * combinations) }; + unsafe { slice::from_raw_parts(pdg_id_combinations, convolutions * combinations) }; let factors = if factors.is_null() { vec![1.0; combinations] } else { unsafe { slice::from_raw_parts(factors, combinations) }.to_vec() }; - channels.0.push(Channel::new( + channels.push(Channel::new( pdg_id_pairs - .chunks(channels.1) + .chunks(convolutions) .zip(factors) - .map(|x| ((0..channels.1).map(|i| x.0[i]).collect(), x.1)) + .map(|x| ((0..convolutions).map(|i| x.0[i]).collect(), x.1)) .collect(), )); } @@ -1534,10 +1543,10 @@ pub unsafe extern "C" fn pineappl_channels_add( pub unsafe extern "C" fn pineappl_grid_channels(grid: *const Grid) -> Box { let grid = unsafe { &*grid }; - Box::new(Channels( - grid.channels().to_vec(), - grid.convolutions().len(), - )) + Box::new(Channels { + channels: grid.channels().to_vec(), + convolutions: grid.convolutions().len(), + }) } /// An exact duplicate of `pineappl_lumi_count` to make naming (lumi -> channel) consistent. @@ -1548,9 +1557,9 @@ pub unsafe extern "C" fn pineappl_grid_channels(grid: *const Grid) -> Box usize { - let channels = unsafe { &*channels }; + let Channels { channels, .. } = unsafe { &*channels }; - channels.0.len() + channels.len() } /// An exact duplicate of `pineappl_lumi_combinations` to make naming (lumi -> channel) consistent. @@ -1564,9 +1573,9 @@ pub unsafe extern "C" fn pineappl_channels_combinations( channels: *const Channels, entry: usize, ) -> usize { - let channels = unsafe { &*channels }; + let Channels { channels, .. } = unsafe { &*channels }; - channels.0[entry].entry().len() + channels[entry].entry().len() } /// An exact duplicate of `pineappl_lumi_delete` to make naming (lumi -> channel) consistent. @@ -1638,10 +1647,12 @@ pub unsafe extern "C" fn pineappl_grid_new2( logxia: s[4], }) .collect(); - let channels = unsafe { &*channels }; + let Channels { + channels, + convolutions, + } = unsafe { &*channels }.clone(); // Construct the convolution objects - let convolutions = channels.1; let convolution_types = unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() }; let convolution_pdg_ids = @@ -1690,7 +1701,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( Box::new(Grid::new( bins, orders, - channels.0.clone(), + channels, pid_basis, convolutions, interp_vecs, @@ -1814,11 +1825,11 @@ pub unsafe extern "C" fn pineappl_channels_entry( pdg_ids: *mut i32, factors: *mut f64, ) { - let channels = unsafe { &*channels }; - let entry = channels.0[entry].entry(); - // if the channel has no entries we assume no convolutions, which is OK we don't copy anything - // in this case - let convolutions = entry.get(0).map_or(0, |x| x.0.len()); + let Channels { + channels, + convolutions, + } = unsafe { &*channels }; + let entry = channels[entry].entry(); let pdg_ids = unsafe { slice::from_raw_parts_mut(pdg_ids, convolutions * entry.len()) }; let factors = unsafe { slice::from_raw_parts_mut(factors, entry.len()) }; From d76fa8be13de9e74ed926c129f6f45a6de58b5c0 Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 00:05:13 +0200 Subject: [PATCH 05/16] Add some fixes to the Fortran API --- examples/fortran/lhapdf_example.f90 | 18 ++++---- examples/fortran/pineappl.f90 | 72 +++++++++++++++-------------- examples/fortran/test.f90 | 24 +++++----- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/examples/fortran/lhapdf_example.f90 b/examples/fortran/lhapdf_example.f90 index 8d187dd9..480accc3 100644 --- a/examples/fortran/lhapdf_example.f90 +++ b/examples/fortran/lhapdf_example.f90 @@ -9,7 +9,7 @@ program lhapdf_example type(pineappl_grid) :: grid type(pineappl_channels) :: channels type(pineappl_kinematics) :: kinematics(3) - type(pineappl_interp_tuples) :: interpolations(3) + type(pineappl_interp) :: interp_info(3) type(pineappl_xfx) :: xfx type(pineappl_alphas) :: alphas @@ -25,8 +25,8 @@ program lhapdf_example integer(c_int), target :: pdfs_array(2,2) character(len=30) :: pdfset1, pdfset2 - channels = pineappl_channels_new() - call pineappl_channels_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) + channels = pineappl_channels_new(int(2, kind=8)) + call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) kinematics = [& pineappl_kinematics(pineappl_scale, 0), & @@ -39,14 +39,14 @@ program lhapdf_example q2_mapping = pineappl_applgrid_h0 x_mapping = pineappl_applgrid_f2 interpolation_meth = pineappl_lagrange - interpolations = [ & - pineappl_interp_tuples(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), & - pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), & - pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & + interp_info = [ & + pineappl_interp(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), & + pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), & + pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] - grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 2, & - [0.0_dp, 1.0_dp, 2.0_dp], 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0]) + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) call pineappl_grid_fill_all2(grid, 0, 0.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [0.5_dp, 0.5_dp, 0.5_dp]) call pineappl_grid_fill_all2(grid, 0, 1.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [1.5_dp, 1.5_dp, 1.5_dp]) diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index e84c14f5..68aad6f9 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -74,11 +74,11 @@ module pineappl integer(c_size_t) :: index end type - type, bind(c) :: pineappl_interp_tuples - real(c_double) :: node_min - real(c_double) :: node_max - integer(c_size_t) :: nb_nodes - integer(c_size_t) :: interp_degree + type, bind(c) :: pineappl_interp + real(c_double) :: min + real(c_double) :: max + integer(c_size_t) :: nodes + integer(c_size_t) :: order integer(kind(pineappl_reweight_meth)) :: reweighting_method integer(kind(pineappl_map)) :: mapping integer(kind(pineappl_interp_meth)) :: interpolation_method @@ -125,18 +125,19 @@ function strlen(s) bind(c, name="strlen") integer (c_size_t) :: strlen end function strlen - subroutine channels_add(channels, combinations, nb_combinations, pdg_id_combinations, factors) & + subroutine channels_add(channels, combinations, pdg_id_combinations, factors) & bind(c, name = 'pineappl_channels_add') use iso_c_binding type (c_ptr), value :: channels - integer (c_size_t), value :: combinations, nb_combinations + integer (c_size_t), value :: combinations integer (c_int32_t) :: pdg_id_combinations(*) real (c_double) :: factors(*) end subroutine - type (c_ptr) function channels_new() bind(c, name = 'pineappl_channels_new') + type (c_ptr) function channels_new(convolutions) bind(c, name = 'pineappl_channels_new') use iso_c_binding + integer (c_size_t), value :: convolutions end function integer (c_size_t) function grid_bin_count(grid) bind(c, name = 'pineappl_grid_bin_count') @@ -312,20 +313,21 @@ type (c_ptr) function grid_new(lumi, orders, order_params, bins, bin_limits, key real (c_double) :: bin_limits(*) end function - type (c_ptr) function grid_new2(pid_basis, channels, orders, order_params, bins, bin_limits, nb_convolutions, & - convolution_types, pdg_ids, kinematics, interpolations, mu_scales) bind(c, name = 'pineappl_grid_new2') + type (c_ptr) function grid_new2(bins, bin_limits, orders, order_params, channels, & + pid_basis, convolution_types, convolution_pdg_ids, interpolations, interp_info, & + kinematics, mu_scales) bind(c, name = 'pineappl_grid_new2') use iso_c_binding - import ! so we can use pineappl_kinematics and pineappl_interp_tuples + import ! so we can use pineappl_kinematics and pineappl_interp integer (c_int32_t), value :: pid_basis type (c_ptr), value :: channels integer (c_int32_t) :: convolution_types(*) - integer (c_size_t), value :: orders, bins, nb_convolutions + integer (c_size_t), value :: orders, bins, interpolations integer (c_int8_t) :: order_params(*) real (c_double) :: bin_limits(*) - integer (c_int32_t) :: pdg_ids(*) + integer (c_int32_t) :: convolution_pdg_ids(*) type (pineappl_kinematics) :: kinematics(*) - type (pineappl_interp_tuples) :: interpolations(*) + type (pineappl_interp) :: interp_info(*) integer (c_size_t) :: mu_scales(*) end function @@ -557,10 +559,12 @@ function c_f_string(c_str) result(f_str) end do end function - type (pineappl_channels) function pineappl_channels_new() + type (pineappl_channels) function pineappl_channels_new(convolutions) implicit none - pineappl_channels_new = pineappl_channels(channels_new()) + integer (c_size_t), value :: convolutions + + pineappl_channels_new = pineappl_channels(channels_new(convolutions)) end function integer function pineappl_grid_bin_count(grid) @@ -896,36 +900,36 @@ type (pineappl_grid) function pineappl_grid_new(lumi, orders, order_params, bins order_params, int(bins, c_size_t), bin_limits, key_vals%ptr)) end function - type (pineappl_grid) function pineappl_grid_new2(pid_basis, channels, orders, order_params, & - bins, bin_limits, nb_convolutions, convolution_types, pdg_ids, kinematics, & - interpolations, mu_scales) + type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order_params, & + channels, pid_basis, convolution_types, convolution_pdg_ids, interpolations, interp_info, & + kinematics, mu_scales) implicit none integer(kind(pineappl_pid_basis)), intent(in) :: pid_basis type (pineappl_channels), intent(in) :: channels - integer, intent(in) :: orders, bins, nb_convolutions + integer, intent(in) :: orders, bins, interpolations integer(int8), dimension(5 * orders), intent(in) :: order_params real (dp), dimension(bins + 1), intent(in) :: bin_limits - integer(kind(pineappl_conv_type)), dimension(nb_convolutions), intent(in) :: convolution_types - integer, dimension(nb_convolutions), intent(in) :: pdg_ids - type (pineappl_kinematics), dimension(nb_convolutions + 1), intent(in), target :: kinematics - type (pineappl_interp_tuples), dimension(nb_convolutions + 1), intent(in) :: interpolations + integer(kind(pineappl_conv_type)), dimension(interpolations - 1), intent(in) :: convolution_types + integer, dimension(interpolations - 1), intent(in) :: convolution_pdg_ids + type (pineappl_kinematics), dimension(interpolations), intent(in), target :: kinematics + type (pineappl_interp), dimension(interpolations), intent(in) :: interp_info integer, dimension(3) :: mu_scales integer :: i pineappl_grid_new2 = pineappl_grid(grid_new2(& - pid_basis, & - channels%ptr, & - int(orders, c_size_t), & - order_params, & int(bins, c_size_t), & bin_limits, & - int(nb_convolutions, c_size_t), & + int(orders, c_size_t), & + order_params, & + channels%ptr, & + pid_basis, & convolution_types, & - pdg_ids, & + convolution_pdg_ids, & + int(interpolations, c_size_t), & + interp_info, & kinematics, & - interpolations, & [(int(mu_scales(i), c_size_t), i = 1, size(mu_scales))]) & ) end function @@ -1177,17 +1181,17 @@ subroutine pineappl_lumi_add(lumi, combinations, pdg_id_pairs, factors) call lumi_add(lumi%ptr, int(combinations, c_size_t), pdg_id_pairs, factors) end subroutine - subroutine pineappl_channels_add(channels, combinations, nb_combinations, pdg_id_combinations, factors) + subroutine pineappl_channels_add(channels, combinations, pdg_id_combinations, factors) use iso_c_binding implicit none type (pineappl_channels), intent(in) :: channels - integer, intent(in) :: combinations, nb_combinations + integer, intent(in) :: combinations integer, dimension(2 * combinations), intent(in) :: pdg_id_combinations real (dp), dimension(combinations), intent(in) :: factors - call channels_add(channels%ptr, int(combinations, c_size_t), int(nb_combinations, c_size_t), pdg_id_combinations, factors) + call channels_add(channels%ptr, int(combinations, c_size_t), pdg_id_combinations, factors) end subroutine integer function pineappl_lumi_combinations(lumi, entry) diff --git a/examples/fortran/test.f90 b/examples/fortran/test.f90 index b5b65d5e..c126cc16 100644 --- a/examples/fortran/test.f90 +++ b/examples/fortran/test.f90 @@ -9,7 +9,7 @@ program test_pineappl type(pineappl_channels) :: channels, channels2 type(pineappl_grid) :: grid, grid2 type(pineappl_kinematics) :: kinematics(3) - type(pineappl_interp_tuples) :: interpolations(3) + type(pineappl_interp) :: interp_info(3) real(dp), allocatable :: result(:), bin_limits_left(:), bin_limits_right(:), bin_normalizations(:) @@ -25,8 +25,8 @@ program test_pineappl type(c_ptr), target :: pdfs_state(2) integer(c_int), target :: pdfs_array(2,2) - channels = pineappl_channels_new() - call pineappl_channels_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) + channels = pineappl_channels_new(int(2, kind=8)) + call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) if (pineappl_channels_count(channels) /= 1) then write(*, *) "pineappl_channels_count(): ", pineappl_channels_count(channels) @@ -38,7 +38,7 @@ program test_pineappl error stop "error: pineappl_channels_combinations" end if - kinematics = [& + kinematics = [ & pineappl_kinematics(pineappl_scale, 0), & pineappl_kinematics(pineappl_x, 0), & pineappl_kinematics(pineappl_x, 1) & @@ -49,13 +49,13 @@ program test_pineappl q2_mapping = pineappl_applgrid_h0 x_mapping = pineappl_applgrid_f2 interpolation_meth = pineappl_lagrange - interpolations = [ & - pineappl_interp_tuples(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), & - pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), & - pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & + interp_info = [ & + pineappl_interp(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), & + pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), & + pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] - grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 2, [0.0_dp, 1.0_dp, 2.0_dp], & - 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0]) + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) if (pineappl_grid_order_count(grid) /= 1) then write(*, *) "pineappl_grid_order_count(): ", pineappl_grid_order_count(grid) @@ -121,8 +121,8 @@ program test_pineappl error stop "error: pineappl_channels_combinations" end if - grid2 = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 1, [2.0_dp, 3.0_dp], & - 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0]) + grid2 = pineappl_grid_new2(1, [2.0_dp, 3.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) call pineappl_grid_merge_and_delete(grid, grid2) From 23c4bf74e3cdf1ffb7af01140f7a4fabe6b958f7 Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 00:45:56 +0200 Subject: [PATCH 06/16] Fix C++ OOP interface and example --- examples/object-oriented-cpp/dyaa.cpp | 6 +++--- pineappl_capi/include/PineAPPL.hpp | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/object-oriented-cpp/dyaa.cpp b/examples/object-oriented-cpp/dyaa.cpp index 6fad292e..3044708a 100644 --- a/examples/object-oriented-cpp/dyaa.cpp +++ b/examples/object-oriented-cpp/dyaa.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -108,9 +107,10 @@ int main() { // Name of the PDF sets to be used for the convolutions std::string pdfset1 = "NNPDF31_nlo_as_0118_luxqed"; std::string pdfset2 = "MSHT20qed_nnlo"; + const std::size_t nb_convolutions = 2; // --- create a new `Channels` function for the $\gamma\gamma$ initial state - PineAPPL::Channels channels; + PineAPPL::Channels channels(nb_convolutions); PineAPPL::SubChannelEntry subchannels; subchannels.entry.push_back({{22, 22}, 1.0}); PineAPPL::ChannelsEntry channels_entry; @@ -150,7 +150,7 @@ int main() { pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2; pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE; - std::vector interpolations = { + std::vector interpolations = { {1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth}, // Interpolation fo `scales` {2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, diff --git a/pineappl_capi/include/PineAPPL.hpp b/pineappl_capi/include/PineAPPL.hpp index 20bf0e70..d44f1edd 100644 --- a/pineappl_capi/include/PineAPPL.hpp +++ b/pineappl_capi/include/PineAPPL.hpp @@ -41,7 +41,7 @@ struct Channels { pineappl_channels *raw; /** @brief Constructor. */ - Channels() : raw(pineappl_channels_new()) {} + Channels(const std::size_t convolutions) : raw(pineappl_channels_new(convolutions)) {} Channels(const Channels &) = delete; Channels(Channels &&) = delete; @@ -62,9 +62,6 @@ struct Channels { const std::size_t combinations = c.channels_entry.size(); if (combinations == 0) return; - const std::size_t nb_convolutions = - c.channels_entry[0].entry[0].first.size(); - std::vector pids; std::vector weights; for (const SubChannelEntry &s : c.channels_entry) { @@ -75,8 +72,7 @@ struct Channels { weights.push_back(m.second); } } - pineappl_channels_add(this->raw, combinations, nb_convolutions, pids.data(), - weights.data()); + pineappl_channels_add(this->raw, combinations, pids.data(), weights.data()); } /** @@ -154,12 +150,15 @@ struct Grid { * @param bin_limits bin_limits * @param mu_scales indexes representing the scales */ - Grid(std::vector &orders, const Channels &channels, - pineappl_pid_basis pid_basis, std::vector pids, + Grid(std::vector &orders, + const Channels &channels, + pineappl_pid_basis pid_basis, + std::vector pids, std::vector &convolution_types, std::vector &kinematics, - std::vector &interp, - std::vector &bin_limits, std::vector &mu_scales) + std::vector &interp, + std::vector &bin_limits, + std::vector &mu_scales) : Grid(nullptr) { const std::size_t n_orders = orders.size(); const std::size_t n_bins = bin_limits.size() - 1; @@ -186,9 +185,9 @@ struct Grid { } this->raw = pineappl_grid_new2( - pid_basis, channels.raw, n_orders, raw_orders.data(), n_bins, - bin_limits.data(), n_convs, convolution_types.data(), pids.data(), - kinematics.data(), interp.data(), mu_scales.data()); + n_bins, bin_limits.data(), n_orders, raw_orders.data(), channels.raw, + pid_basis, convolution_types.data(), pids.data(), interp.size(), + interp.data(), kinematics.data(), mu_scales.data()); } /** From d1a8854de20b4b5b02e8d7fc9abe0f45030fafff Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 10:51:34 +0200 Subject: [PATCH 07/16] Minor change of types in Fortran API --- examples/fortran/lhapdf_example.f90 | 2 +- examples/fortran/pineappl.f90 | 4 ++-- examples/fortran/test.f90 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/fortran/lhapdf_example.f90 b/examples/fortran/lhapdf_example.f90 index 480accc3..7657b75f 100644 --- a/examples/fortran/lhapdf_example.f90 +++ b/examples/fortran/lhapdf_example.f90 @@ -25,7 +25,7 @@ program lhapdf_example integer(c_int), target :: pdfs_array(2,2) character(len=30) :: pdfset1, pdfset2 - channels = pineappl_channels_new(int(2, kind=8)) + channels = pineappl_channels_new(2) call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) kinematics = [& diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index 68aad6f9..c7b04426 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -137,7 +137,7 @@ subroutine channels_add(channels, combinations, pdg_id_combinations, factors) & type (c_ptr) function channels_new(convolutions) bind(c, name = 'pineappl_channels_new') use iso_c_binding - integer (c_size_t), value :: convolutions + integer (c_int32_t), value :: convolutions end function integer (c_size_t) function grid_bin_count(grid) bind(c, name = 'pineappl_grid_bin_count') @@ -562,7 +562,7 @@ function c_f_string(c_str) result(f_str) type (pineappl_channels) function pineappl_channels_new(convolutions) implicit none - integer (c_size_t), value :: convolutions + integer (c_int32_t), value :: convolutions pineappl_channels_new = pineappl_channels(channels_new(convolutions)) end function diff --git a/examples/fortran/test.f90 b/examples/fortran/test.f90 index c126cc16..ae6cada2 100644 --- a/examples/fortran/test.f90 +++ b/examples/fortran/test.f90 @@ -25,7 +25,7 @@ program test_pineappl type(c_ptr), target :: pdfs_state(2) integer(c_int), target :: pdfs_array(2,2) - channels = pineappl_channels_new(int(2, kind=8)) + channels = pineappl_channels_new(2) call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) if (pineappl_channels_count(channels) /= 1) then From a4ce4a121749a69e9ebda0676de2fac2c1f8e23e Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 12:42:36 +0200 Subject: [PATCH 08/16] Allow for `ScaleFuncForm` in C-API and fix corresponding C++ examples --- examples/cpp/advanced-filling.cpp | 4 +++- examples/cpp/fill-grid.cpp | 4 +++- pineappl_capi/cbindgen.toml | 1 + pineappl_capi/src/lib.rs | 22 +++++----------------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/examples/cpp/advanced-filling.cpp b/examples/cpp/advanced-filling.cpp index ccc603cb..d6f94cf2 100644 --- a/examples/cpp/advanced-filling.cpp +++ b/examples/cpp/advanced-filling.cpp @@ -63,7 +63,9 @@ int main() { }; // Define the unphysical scale objecs - size_t mu_scales[] = { 1, 1, 0 }; + pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 }; + pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; + pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu }; // --- // Create the grid using the previously set information about orders, bins and channels diff --git a/examples/cpp/fill-grid.cpp b/examples/cpp/fill-grid.cpp index 81a6413a..1bb62136 100644 --- a/examples/cpp/fill-grid.cpp +++ b/examples/cpp/fill-grid.cpp @@ -205,7 +205,9 @@ int main() { }; // Define the unphysical scale objecs - size_t mu_scales[] = { 1, 1, 0 }; + pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 }; + pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; + pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu }; // --- // Create the grid using the previously set information about orders, bins and channels diff --git a/pineappl_capi/cbindgen.toml b/pineappl_capi/cbindgen.toml index 8a79d97d..94a24bc4 100644 --- a/pineappl_capi/cbindgen.toml +++ b/pineappl_capi/cbindgen.toml @@ -40,6 +40,7 @@ rename_variants = "ScreamingSnakeCase" "PidBasis" = "pineappl_pid_basis" "ConvType" = "pineappl_conv_type" "Kinematics" = "pineappl_kinematics" +"ScaleFuncForm" = "pineappl_scale_func_form" "ReweightMeth" = "pineappl_reweight_meth" "Map" = "pineappl_map" "InterpMeth" = "pineappl_interp_meth" diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index 5032579f..b6c5b9ba 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -1630,7 +1630,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( interpolations: usize, interp_info: *const Interp, kinematics: *const Kinematics, - mu_scales: *const usize, + mu_scales: *const ScaleFuncForm, ) -> Box { let bins = BinsWithFillLimits::from_fill_limits( unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(), @@ -1683,20 +1683,8 @@ pub unsafe extern "C" fn pineappl_grid_new2( // Construct the kinematic variables let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()) }.to_vec(); - // Scales. An array containing the values of {ren, fac, frg} + // Scales. An array containing the values of `ScaleFuncForm` objects let mu_scales = unsafe { std::slice::from_raw_parts(mu_scales, 3) }; - let mu_scales_vec: Vec<_> = mu_scales - .iter() - .map(|&scale| { - // TODO: this doesn't allow all other `ScaleFuncForm`, for instance - // `ScaleFuncForm::QuadraticSum` - if scale == 0 { - ScaleFuncForm::NoScale - } else { - ScaleFuncForm::Scale(scale - 1) - } - }) - .collect(); Box::new(Grid::new( bins, @@ -1707,9 +1695,9 @@ pub unsafe extern "C" fn pineappl_grid_new2( interp_vecs, kinematics, Scales { - ren: mu_scales_vec[0].clone(), - fac: mu_scales_vec[1].clone(), - frg: mu_scales_vec[2].clone(), + ren: mu_scales[0].clone(), + fac: mu_scales[1].clone(), + frg: mu_scales[2].clone(), }, )) } From aef594935eedfcfd1f0bc92d7424dade2a496937 Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 14:19:33 +0200 Subject: [PATCH 09/16] Propagate `ScaleFuncForm` into the Fortran API --- examples/fortran/lhapdf_example.f90 | 18 +++++++++---- examples/fortran/pineappl.f90 | 39 ++++++++++++++++++++++++++--- examples/fortran/test.f90 | 21 +++++++++++----- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/examples/fortran/lhapdf_example.f90 b/examples/fortran/lhapdf_example.f90 index 7657b75f..d819b49c 100644 --- a/examples/fortran/lhapdf_example.f90 +++ b/examples/fortran/lhapdf_example.f90 @@ -6,10 +6,11 @@ program lhapdf_example integer, parameter :: dp = kind(0.0d0) - type(pineappl_grid) :: grid - type(pineappl_channels) :: channels - type(pineappl_kinematics) :: kinematics(3) - type(pineappl_interp) :: interp_info(3) + type(pineappl_grid) :: grid + type(pineappl_channels) :: channels + type(pineappl_kinematics) :: kinematics(3) + type(pineappl_scale_func_form) :: mu_scales_form(3) + type(pineappl_interp) :: interp_info(3) type(pineappl_xfx) :: xfx type(pineappl_alphas) :: alphas @@ -45,8 +46,15 @@ program lhapdf_example pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] + ! All the `_body` have to defined with two fields - if not required, the value(s) will be ignored + mu_scales_form = [ & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) & + ] + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) call pineappl_grid_fill_all2(grid, 0, 0.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [0.5_dp, 0.5_dp, 0.5_dp]) call pineappl_grid_fill_all2(grid, 0, 1.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [1.5_dp, 1.5_dp, 1.5_dp]) diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index c7b04426..6f61f2d8 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -68,12 +68,43 @@ module pineappl enumerator :: pineappl_kinematics_tag end enum - ! The Kinematics struct is a tuple-like struct in the Pineappl Rust code, which is realized as a C union. Fortran does not support unions, but fortunately the union is only for storing ints, so we just use an integer variable for `index` + enum, bind(c) ! :: pineappl_scale_func_form_tag + enumerator :: pineappl_scale_func_form_no_scale + enumerator :: pineappl_scale_func_form_scale + enumerator :: pineappl_scale_func_form_quadratic_sum + enumerator :: pineappl_scale_func_form_quadratic_mean + enumerator :: pineappl_scale_func_form_quadratic_sum_over4 + enumerator :: pineappl_scale_func_form_linear_mean + enumerator :: pineappl_scale_func_form_linear_sum + enumerator :: pineappl_scale_func_form_scale_max + enumerator :: pineappl_scale_func_form_scale_min + enumerator :: pineappl_scale_func_form_prod + enumerator :: pineappl_scale_func_form_s2plus_s1half + enumerator :: pineappl_scale_func_form_pow4_sum + enumerator :: pineappl_scale_func_form_wgt_avg + enumerator :: pineappl_scale_func_form_s2plus_s1fourth + enumerator :: pineappl_scale_func_form_exp_prod2 + + enumerator :: pineappl_scale_func_form_tag + end enum + + ! The Kinematics struct is a tuple-like struct in the PineAPPL Rust code, which is realized as a C union. Fortran does not support unions, but fortunately the union is only for storing ints, so we just use an integer variable for `index` type, bind(c) :: pineappl_kinematics integer(kind(pineappl_kinematics_tag)) :: tag integer(c_size_t) :: index end type + ! Implement the ScaleFuncForm struct which is also a tuple-like struct ine PineAPPL Rust code. + type, bind(c) :: pineappl_scale_func_form_body + integer(c_size_t) :: index_0 ! index_0 maps to C union field _0 + integer(c_size_t) :: index_1 ! index_1 maps to C union field _1 + end type + + type, bind(c) :: pineappl_scale_func_form + integer(kind(pineappl_scale_func_form_tag)) :: tag + type(pineappl_scale_func_form_body) :: body + end type + type, bind(c) :: pineappl_interp real(c_double) :: min real(c_double) :: max @@ -328,7 +359,7 @@ type (c_ptr) function grid_new2(bins, bin_limits, orders, order_params, channels integer (c_int32_t) :: convolution_pdg_ids(*) type (pineappl_kinematics) :: kinematics(*) type (pineappl_interp) :: interp_info(*) - integer (c_size_t) :: mu_scales(*) + type (pineappl_scale_func_form) :: mu_scales(*) end function subroutine grid_optimize(grid) bind(c, name = 'pineappl_grid_optimize') @@ -914,7 +945,7 @@ type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order integer, dimension(interpolations - 1), intent(in) :: convolution_pdg_ids type (pineappl_kinematics), dimension(interpolations), intent(in), target :: kinematics type (pineappl_interp), dimension(interpolations), intent(in) :: interp_info - integer, dimension(3) :: mu_scales + type (pineappl_scale_func_form), dimension(interpolations) :: mu_scales integer :: i @@ -930,7 +961,7 @@ type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order int(interpolations, c_size_t), & interp_info, & kinematics, & - [(int(mu_scales(i), c_size_t), i = 1, size(mu_scales))]) & + mu_scales) & ) end function diff --git a/examples/fortran/test.f90 b/examples/fortran/test.f90 index ae6cada2..fb67fc6c 100644 --- a/examples/fortran/test.f90 +++ b/examples/fortran/test.f90 @@ -6,10 +6,11 @@ program test_pineappl integer, parameter :: dp = kind(0.0d0) - type(pineappl_channels) :: channels, channels2 - type(pineappl_grid) :: grid, grid2 - type(pineappl_kinematics) :: kinematics(3) - type(pineappl_interp) :: interp_info(3) + type(pineappl_channels) :: channels, channels2 + type(pineappl_grid) :: grid, grid2 + type(pineappl_kinematics) :: kinematics(3) + type(pineappl_scale_func_form) :: mu_scales_form(3) + type(pineappl_interp) :: interp_info(3) real(dp), allocatable :: result(:), bin_limits_left(:), bin_limits_right(:), bin_normalizations(:) @@ -54,8 +55,16 @@ program test_pineappl pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), & pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] + + ! All the `_body` have to defined with two fields - if not required, the value(s) will be ignored + mu_scales_form = [ & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & + pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) & + ] + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) if (pineappl_grid_order_count(grid) /= 1) then write(*, *) "pineappl_grid_order_count(): ", pineappl_grid_order_count(grid) @@ -122,7 +131,7 @@ program test_pineappl end if grid2 = pineappl_grid_new2(1, [2.0_dp, 3.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, [1, 1, 0]) + [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) call pineappl_grid_merge_and_delete(grid, grid2) From 35d7b4f366e74ddb038dbbf1f1686467eb613bea Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 21 May 2025 14:45:09 +0200 Subject: [PATCH 10/16] Propagate `ScaleFuncForm` into the C++ OOP --- examples/object-oriented-cpp/dyaa.cpp | 6 ++++-- pineappl_capi/include/PineAPPL.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/object-oriented-cpp/dyaa.cpp b/examples/object-oriented-cpp/dyaa.cpp index 3044708a..588bd1b7 100644 --- a/examples/object-oriented-cpp/dyaa.cpp +++ b/examples/object-oriented-cpp/dyaa.cpp @@ -159,8 +159,10 @@ int main() { interpolation_meth}, // Interpolation fo `x2` }; - // Define the μ scale - std::vector mu_scales = {1, 1, 1}; + // Define the μ ScaleFuncForm objects + pineappl_scale_func_form scale_form = {PINEAPPL_SCALE_FUNC_FORM_SCALE, 0}; + pineappl_scale_func_form no_scale_form = {PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0}; + std::vector mu_scales = {scale_form, scale_form, no_scale_form}; PineAPPL::Grid grid(orders, channels, pid_basis, pids, convolution_types, kinematics, interpolations, bins, mu_scales); diff --git a/pineappl_capi/include/PineAPPL.hpp b/pineappl_capi/include/PineAPPL.hpp index d44f1edd..1c9e5488 100644 --- a/pineappl_capi/include/PineAPPL.hpp +++ b/pineappl_capi/include/PineAPPL.hpp @@ -158,7 +158,7 @@ struct Grid { std::vector &kinematics, std::vector &interp, std::vector &bin_limits, - std::vector &mu_scales) + std::vector &mu_scales) : Grid(nullptr) { const std::size_t n_orders = orders.size(); const std::size_t n_bins = bin_limits.size() - 1; From 59ce3699f628eaeb23b8b251e3871203e53d8cde Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Thu, 22 May 2025 13:54:00 +0200 Subject: [PATCH 11/16] Minor cosmetic details --- examples/cpp/advanced-filling.cpp | 2 +- examples/cpp/fill-grid.cpp | 5 +++-- examples/fortran/lhapdf_example.f90 | 4 ++-- examples/fortran/pineappl.f90 | 2 +- examples/fortran/test.f90 | 4 ++-- examples/object-oriented-cpp/dyaa.cpp | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/cpp/advanced-filling.cpp b/examples/cpp/advanced-filling.cpp index d6f94cf2..83876771 100644 --- a/examples/cpp/advanced-filling.cpp +++ b/examples/cpp/advanced-filling.cpp @@ -64,7 +64,7 @@ int main() { // Define the unphysical scale objecs pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 }; - pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; + pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; // Here `.scale=0` is dummy value pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu }; // --- diff --git a/examples/cpp/fill-grid.cpp b/examples/cpp/fill-grid.cpp index 1bb62136..2cd21e10 100644 --- a/examples/cpp/fill-grid.cpp +++ b/examples/cpp/fill-grid.cpp @@ -116,7 +116,8 @@ int main() { // Create all channels // this object will contain all channels (for two initial states) that we define - auto* channels = pineappl_channels_new(2); + std::size_t nb_convolutions = 2; + auto* channels = pineappl_channels_new(nb_convolutions); // photon-photon initial state, where `22` is the photon (PDG MC ids) int32_t pids1[] = { 22, 22 }; @@ -206,7 +207,7 @@ int main() { // Define the unphysical scale objecs pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 }; - pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; + pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; // Here `.scale=0` is dummy value pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu }; // --- diff --git a/examples/fortran/lhapdf_example.f90 b/examples/fortran/lhapdf_example.f90 index d819b49c..974f55fe 100644 --- a/examples/fortran/lhapdf_example.f90 +++ b/examples/fortran/lhapdf_example.f90 @@ -26,7 +26,7 @@ program lhapdf_example integer(c_int), target :: pdfs_array(2,2) character(len=30) :: pdfset1, pdfset2 - channels = pineappl_channels_new(2) + channels = pineappl_channels_new(2) ! The argument is the number of convolutions call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) kinematics = [& @@ -46,7 +46,7 @@ program lhapdf_example pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] - ! All the `_body` have to defined with two fields - if not required, the value(s) will be ignored + ! The `pineappl_scale_func_form_body` objects have to defined with two fields - if not required, the value(s) will be ignored mu_scales_form = [ & pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index 6f61f2d8..6e59fc9f 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -94,7 +94,7 @@ module pineappl integer(c_size_t) :: index end type - ! Implement the ScaleFuncForm struct which is also a tuple-like struct ine PineAPPL Rust code. + ! Implement the ScaleFuncForm struct which is also a tuple-like struct ine PineAPPL Rust code. The `pineappl_scale_func_form_body` objects have to defined with two fields - if not required, the value(s) will be ignored. type, bind(c) :: pineappl_scale_func_form_body integer(c_size_t) :: index_0 ! index_0 maps to C union field _0 integer(c_size_t) :: index_1 ! index_1 maps to C union field _1 diff --git a/examples/fortran/test.f90 b/examples/fortran/test.f90 index fb67fc6c..7fbfc0c1 100644 --- a/examples/fortran/test.f90 +++ b/examples/fortran/test.f90 @@ -26,7 +26,7 @@ program test_pineappl type(c_ptr), target :: pdfs_state(2) integer(c_int), target :: pdfs_array(2,2) - channels = pineappl_channels_new(2) + channels = pineappl_channels_new(2) ! The argument is the number of convolutions call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp]) if (pineappl_channels_count(channels) /= 1) then @@ -56,7 +56,7 @@ program test_pineappl pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) & ] - ! All the `_body` have to defined with two fields - if not required, the value(s) will be ignored + ! The `pineappl_scale_func_form_body` objects have to defined with two fields - if not required, the value(s) will be ignored mu_scales_form = [ & pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), & diff --git a/examples/object-oriented-cpp/dyaa.cpp b/examples/object-oriented-cpp/dyaa.cpp index 588bd1b7..ad198259 100644 --- a/examples/object-oriented-cpp/dyaa.cpp +++ b/examples/object-oriented-cpp/dyaa.cpp @@ -159,7 +159,7 @@ int main() { interpolation_meth}, // Interpolation fo `x2` }; - // Define the μ ScaleFuncForm objects + // Define the μ `ScaleFuncForm` objects pineappl_scale_func_form scale_form = {PINEAPPL_SCALE_FUNC_FORM_SCALE, 0}; pineappl_scale_func_form no_scale_form = {PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0}; std::vector mu_scales = {scale_form, scale_form, no_scale_form}; From 276d6b5c41e408598178520d0c956ebbeba181bf Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 24 May 2025 10:35:11 +0200 Subject: [PATCH 12/16] Sort `[export.rename]` entries --- pineappl_capi/cbindgen.toml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pineappl_capi/cbindgen.toml b/pineappl_capi/cbindgen.toml index 94a24bc4..df8b90aa 100644 --- a/pineappl_capi/cbindgen.toml +++ b/pineappl_capi/cbindgen.toml @@ -34,20 +34,20 @@ prefix_with_name = true rename_variants = "ScreamingSnakeCase" [export.rename] -"Grid" = "pineappl_grid" -"Lumi" = "pineappl_lumi" "Channels" = "pineappl_channels" -"PidBasis" = "pineappl_pid_basis" "ConvType" = "pineappl_conv_type" -"Kinematics" = "pineappl_kinematics" -"ScaleFuncForm" = "pineappl_scale_func_form" -"ReweightMeth" = "pineappl_reweight_meth" -"Map" = "pineappl_map" -"InterpMeth" = "pineappl_interp_meth" +"Grid" = "pineappl_grid" +"GridOptFlags" = "pineappl_gof" "Interp" = "pineappl_interp" +"InterpMeth" = "pineappl_interp_meth" "KeyVal" = "pineappl_keyval" +"Kinematics" = "pineappl_kinematics" +"Lumi" = "pineappl_lumi" +"Map" = "pineappl_map" +"PidBasis" = "pineappl_pid_basis" +"ReweightMeth" = "pineappl_reweight_meth" +"ScaleFuncForm" = "pineappl_scale_func_form" "SubGrid" = "pineappl_subgrid" -"GridOptFlags" = "pineappl_gof" ############## Options for How Your Rust library Should Be Parsed ############## From 480a13fbfdb8adcf9b13145fefa9cc9386366e4d Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 24 May 2025 10:39:20 +0200 Subject: [PATCH 13/16] Rename parameters to match `Grid::new` --- pineappl_capi/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index b6c5b9ba..fb724867 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -1628,9 +1628,9 @@ pub unsafe extern "C" fn pineappl_grid_new2( convolution_types: *const ConvType, convolution_pdg_ids: *const c_int, interpolations: usize, - interp_info: *const Interp, + interps: *const Interp, kinematics: *const Kinematics, - mu_scales: *const ScaleFuncForm, + scales: *const ScaleFuncForm, ) -> Box { let bins = BinsWithFillLimits::from_fill_limits( unsafe { slice::from_raw_parts(bin_limits, bins + 1) }.to_vec(), @@ -1664,7 +1664,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( .collect(); // Grid interpolations - let interp_slices = unsafe { std::slice::from_raw_parts(interp_info, interpolations) }; + let interp_slices = unsafe { std::slice::from_raw_parts(interps, interpolations) }; let interp_vecs: Vec<_> = interp_slices .iter() .map(|interp| { @@ -1684,7 +1684,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( let kinematics = unsafe { slice::from_raw_parts(kinematics, interp_vecs.len()) }.to_vec(); // Scales. An array containing the values of `ScaleFuncForm` objects - let mu_scales = unsafe { std::slice::from_raw_parts(mu_scales, 3) }; + let mu_scales = unsafe { std::slice::from_raw_parts(scales, 3) }; Box::new(Grid::new( bins, From dcd6082f61d0ca0579f49d18d474a4a53586f59b Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 24 May 2025 11:02:49 +0200 Subject: [PATCH 14/16] Use `Conv` in the CAPI --- examples/cpp/advanced-filling.cpp | 10 +++++----- examples/cpp/fill-grid.cpp | 10 +++++----- examples/fortran/lhapdf_example.f90 | 8 +++++++- examples/fortran/pineappl.f90 | 19 ++++++++++--------- examples/fortran/test.f90 | 10 ++++++++-- examples/object-oriented-cpp/dyaa.cpp | 10 +++++----- pineappl_capi/cbindgen.toml | 1 + pineappl_capi/include/PineAPPL.hpp | 9 +++------ pineappl_capi/src/lib.rs | 18 ++++-------------- 9 files changed, 48 insertions(+), 47 deletions(-) diff --git a/examples/cpp/advanced-filling.cpp b/examples/cpp/advanced-filling.cpp index 83876771..7b8be66c 100644 --- a/examples/cpp/advanced-filling.cpp +++ b/examples/cpp/advanced-filling.cpp @@ -37,10 +37,10 @@ int main() { // hadrons. Then we add the corresponding PID of each of the hadrons, and finally define the // Basis onto which the partons are mapped. pineappl_pid_basis pid_basis = PINEAPPL_PID_BASIS_EVOL; - int32_t pdg_ids[2] = { 2212, 2212}; - pineappl_conv_type h1 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - pineappl_conv_type h2 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - pineappl_conv_type convolution_types[2] = { h1, h2 }; + pineappl_conv convs[] = { + { PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 }, + { PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 }, + }; // Define the kinematics required for this process. In the following example we have ONE // single scale and two momentum fractions (corresponding to the two initial-state hadrons). @@ -74,7 +74,7 @@ int main() { // exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra // parameters in `keyval`. auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(), - channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales); + channels, pid_basis, convs, 3, interpolations, kinematics, mu_scales); // now we no longer need `channels` pineappl_channels_delete(channels); diff --git a/examples/cpp/fill-grid.cpp b/examples/cpp/fill-grid.cpp index 2cd21e10..e56e8a4b 100644 --- a/examples/cpp/fill-grid.cpp +++ b/examples/cpp/fill-grid.cpp @@ -180,10 +180,10 @@ int main() { // hadrons. Then we add the corresponding PID of each of the hadrons, and finally define the // Basis onto which the partons are mapped. pineappl_pid_basis pid_basis = PINEAPPL_PID_BASIS_EVOL; - int32_t pdg_ids[2] = { 2212, 2212}; - pineappl_conv_type h1 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - pineappl_conv_type h2 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - pineappl_conv_type convolution_types[2] = { h1, h2 }; + pineappl_conv convs[] = { + { PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 }, + { PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 }, + }; // Define the kinematics required for this process. In the following example we have ONE // single scale and two momentum fractions (corresponding to the two initial-state hadrons). @@ -217,7 +217,7 @@ int main() { // exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra // parameters in `keyval`. auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(), - channels, pid_basis, convolution_types, pdg_ids, 3, interpolations, kinematics, mu_scales); + channels, pid_basis, convs, 3, interpolations, kinematics, mu_scales); // now we no longer need `keyval` and `channels` pineappl_channels_delete(channels); diff --git a/examples/fortran/lhapdf_example.f90 b/examples/fortran/lhapdf_example.f90 index 974f55fe..5f465e58 100644 --- a/examples/fortran/lhapdf_example.f90 +++ b/examples/fortran/lhapdf_example.f90 @@ -11,6 +11,7 @@ program lhapdf_example type(pineappl_kinematics) :: kinematics(3) type(pineappl_scale_func_form) :: mu_scales_form(3) type(pineappl_interp) :: interp_info(3) + type(pineappl_conv) :: convolutions(2) type(pineappl_xfx) :: xfx type(pineappl_alphas) :: alphas @@ -53,8 +54,13 @@ program lhapdf_example pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) & ] + convolutions = [ & + pineappl_conv(pineappl_unpol_pdf, 2212), & + pineappl_conv(pineappl_unpol_pdf, 2212) & + ] + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) + convolutions, 3, interp_info, kinematics, mu_scales_form) call pineappl_grid_fill_all2(grid, 0, 0.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [0.5_dp, 0.5_dp, 0.5_dp]) call pineappl_grid_fill_all2(grid, 0, 1.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [1.5_dp, 1.5_dp, 1.5_dp]) diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index 6e59fc9f..bab3c442 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -105,6 +105,11 @@ module pineappl type(pineappl_scale_func_form_body) :: body end type + type, bind(c) :: pineappl_conv + integer(kind(pineappl_conv_type)) :: conv_type + integer(c_int32_t) :: pid + end type + type, bind(c) :: pineappl_interp real(c_double) :: min real(c_double) :: max @@ -345,18 +350,17 @@ type (c_ptr) function grid_new(lumi, orders, order_params, bins, bin_limits, key end function type (c_ptr) function grid_new2(bins, bin_limits, orders, order_params, channels, & - pid_basis, convolution_types, convolution_pdg_ids, interpolations, interp_info, & + pid_basis, convolutions, interpolations, interp_info, & kinematics, mu_scales) bind(c, name = 'pineappl_grid_new2') use iso_c_binding import ! so we can use pineappl_kinematics and pineappl_interp integer (c_int32_t), value :: pid_basis type (c_ptr), value :: channels - integer (c_int32_t) :: convolution_types(*) integer (c_size_t), value :: orders, bins, interpolations integer (c_int8_t) :: order_params(*) real (c_double) :: bin_limits(*) - integer (c_int32_t) :: convolution_pdg_ids(*) + type (pineappl_conv) :: convolutions(*) type (pineappl_kinematics) :: kinematics(*) type (pineappl_interp) :: interp_info(*) type (pineappl_scale_func_form) :: mu_scales(*) @@ -932,8 +936,7 @@ type (pineappl_grid) function pineappl_grid_new(lumi, orders, order_params, bins end function type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order_params, & - channels, pid_basis, convolution_types, convolution_pdg_ids, interpolations, interp_info, & - kinematics, mu_scales) + channels, pid_basis, convolutions, interpolations, interp_info, kinematics, mu_scales) implicit none integer(kind(pineappl_pid_basis)), intent(in) :: pid_basis @@ -941,8 +944,7 @@ type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order integer, intent(in) :: orders, bins, interpolations integer(int8), dimension(5 * orders), intent(in) :: order_params real (dp), dimension(bins + 1), intent(in) :: bin_limits - integer(kind(pineappl_conv_type)), dimension(interpolations - 1), intent(in) :: convolution_types - integer, dimension(interpolations - 1), intent(in) :: convolution_pdg_ids + type (pineappl_conv), dimension(*), intent(in), target :: convolutions type (pineappl_kinematics), dimension(interpolations), intent(in), target :: kinematics type (pineappl_interp), dimension(interpolations), intent(in) :: interp_info type (pineappl_scale_func_form), dimension(interpolations) :: mu_scales @@ -956,8 +958,7 @@ type (pineappl_grid) function pineappl_grid_new2(bins, bin_limits, orders, order order_params, & channels%ptr, & pid_basis, & - convolution_types, & - convolution_pdg_ids, & + convolutions, & int(interpolations, c_size_t), & interp_info, & kinematics, & diff --git a/examples/fortran/test.f90 b/examples/fortran/test.f90 index 7fbfc0c1..ea3ac8d4 100644 --- a/examples/fortran/test.f90 +++ b/examples/fortran/test.f90 @@ -11,6 +11,7 @@ program test_pineappl type(pineappl_kinematics) :: kinematics(3) type(pineappl_scale_func_form) :: mu_scales_form(3) type(pineappl_interp) :: interp_info(3) + type(pineappl_conv) :: convolutions(2) real(dp), allocatable :: result(:), bin_limits_left(:), bin_limits_right(:), bin_normalizations(:) @@ -63,8 +64,13 @@ program test_pineappl pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) & ] + convolutions = [ & + pineappl_conv(pineappl_unpol_pdf, 2212), & + pineappl_conv(pineappl_unpol_pdf, 2212) & + ] + grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) + convolutions, 3, interp_info, kinematics, mu_scales_form) if (pineappl_grid_order_count(grid) /= 1) then write(*, *) "pineappl_grid_order_count(): ", pineappl_grid_order_count(grid) @@ -131,7 +137,7 @@ program test_pineappl end if grid2 = pineappl_grid_new2(1, [2.0_dp, 3.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, & - [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], 3, interp_info, kinematics, mu_scales_form) + convolutions, 3, interp_info, kinematics, mu_scales_form) call pineappl_grid_merge_and_delete(grid, grid2) diff --git a/examples/object-oriented-cpp/dyaa.cpp b/examples/object-oriented-cpp/dyaa.cpp index ad198259..bdffc142 100644 --- a/examples/object-oriented-cpp/dyaa.cpp +++ b/examples/object-oriented-cpp/dyaa.cpp @@ -130,12 +130,12 @@ int main() { // --- Construct the PineAPPL grid pineappl_pid_basis pid_basis = PINEAPPL_PID_BASIS_EVOL; - std::vector pids = {2212, 2212}; // Define the types of convolutions - pineappl_conv_type h1 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - pineappl_conv_type h2 = PINEAPPL_CONV_TYPE_UNPOL_PDF; - std::vector convolution_types = {h1, h2}; + std::vector convolutions = { + {PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212}, + {PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212} + }; // Define the Kinematics pineappl_kinematics scales = {PINEAPPL_KINEMATICS_SCALE, 0}; @@ -164,7 +164,7 @@ int main() { pineappl_scale_func_form no_scale_form = {PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0}; std::vector mu_scales = {scale_form, scale_form, no_scale_form}; - PineAPPL::Grid grid(orders, channels, pid_basis, pids, convolution_types, + PineAPPL::Grid grid(orders, channels, pid_basis, convolutions, kinematics, interpolations, bins, mu_scales); // fill the grid with phase-space points diff --git a/pineappl_capi/cbindgen.toml b/pineappl_capi/cbindgen.toml index df8b90aa..6eb11274 100644 --- a/pineappl_capi/cbindgen.toml +++ b/pineappl_capi/cbindgen.toml @@ -35,6 +35,7 @@ rename_variants = "ScreamingSnakeCase" [export.rename] "Channels" = "pineappl_channels" +"Conv" = "pineappl_conv" "ConvType" = "pineappl_conv_type" "Grid" = "pineappl_grid" "GridOptFlags" = "pineappl_gof" diff --git a/pineappl_capi/include/PineAPPL.hpp b/pineappl_capi/include/PineAPPL.hpp index 1c9e5488..d7fe1de4 100644 --- a/pineappl_capi/include/PineAPPL.hpp +++ b/pineappl_capi/include/PineAPPL.hpp @@ -153,8 +153,7 @@ struct Grid { Grid(std::vector &orders, const Channels &channels, pineappl_pid_basis pid_basis, - std::vector pids, - std::vector &convolution_types, + std::vector &convolutions, std::vector &kinematics, std::vector &interp, std::vector &bin_limits, @@ -162,12 +161,10 @@ struct Grid { : Grid(nullptr) { const std::size_t n_orders = orders.size(); const std::size_t n_bins = bin_limits.size() - 1; - const std::size_t n_convs = convolution_types.size(); + const std::size_t n_convs = convolutions.size(); // Various checks for the input arguments assert(n_orders >= 1 && "Orders cannot be empty."); - assert(n_convs == pids.size() && - "Number of convolutions and pids are different."); assert(n_convs == kinematics.size() - 1 && "Mismatch in the number of convolutions and the kinematics."); assert(kinematics.size() == interp.size() && @@ -186,7 +183,7 @@ struct Grid { this->raw = pineappl_grid_new2( n_bins, bin_limits.data(), n_orders, raw_orders.data(), channels.raw, - pid_basis, convolution_types.data(), pids.data(), interp.size(), + pid_basis, convolutions.data(), interp.size(), interp.data(), kinematics.data(), mu_scales.data()); } diff --git a/pineappl_capi/src/lib.rs b/pineappl_capi/src/lib.rs index fb724867..d36f9a88 100644 --- a/pineappl_capi/src/lib.rs +++ b/pineappl_capi/src/lib.rs @@ -67,7 +67,7 @@ use std::collections::HashMap; use std::ffi::{CStr, CString}; use std::fs::File; use std::mem; -use std::os::raw::{c_char, c_int, c_void}; +use std::os::raw::{c_char, c_void}; use std::path::Path; use std::slice; @@ -1625,8 +1625,7 @@ pub unsafe extern "C" fn pineappl_grid_new2( order_params: *const u8, channels: *const Channels, pid_basis: PidBasis, - convolution_types: *const ConvType, - convolution_pdg_ids: *const c_int, + convolutions: *const Conv, interpolations: usize, interps: *const Interp, kinematics: *const Kinematics, @@ -1649,19 +1648,10 @@ pub unsafe extern "C" fn pineappl_grid_new2( .collect(); let Channels { channels, - convolutions, + convolutions: nb_convolutions, } = unsafe { &*channels }.clone(); - // Construct the convolution objects - let convolution_types = - unsafe { slice::from_raw_parts(convolution_types, convolutions).to_vec() }; - let convolution_pdg_ids = - unsafe { slice::from_raw_parts(convolution_pdg_ids, convolutions).to_vec() }; - let convolutions = convolution_types - .iter() - .zip(convolution_pdg_ids) - .map(|(&convolution_type, pdg_id)| Conv::new(convolution_type, pdg_id)) - .collect(); + let convolutions = unsafe { slice::from_raw_parts(convolutions, nb_convolutions) }.to_vec(); // Grid interpolations let interp_slices = unsafe { std::slice::from_raw_parts(interps, interpolations) }; From c875087e1ff50d52a76c1008ffbf05909cac928f Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 24 May 2025 12:33:23 +0200 Subject: [PATCH 15/16] Update authors of the CAPI --- pineappl_capi/Cargo.toml | 5 ++++- pineappl_capi/cbindgen.toml | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pineappl_capi/Cargo.toml b/pineappl_capi/Cargo.toml index 3ef783b5..219fe9b5 100644 --- a/pineappl_capi/Cargo.toml +++ b/pineappl_capi/Cargo.toml @@ -1,5 +1,8 @@ [package] -authors = ["Christopher Schwan "] +authors = [ + "Christopher Schwan ", + "Tanjona R. Rabemananjara <>" +] description = "C language interface to PineAPPL" name = "pineappl_capi" readme = "README.md" diff --git a/pineappl_capi/cbindgen.toml b/pineappl_capi/cbindgen.toml index 6eb11274..7d3c6510 100644 --- a/pineappl_capi/cbindgen.toml +++ b/pineappl_capi/cbindgen.toml @@ -4,7 +4,8 @@ language = "C" header = """/* * PineAPPL - PDF-independent binning of phase space weights - * Copyright (C) 2020-2024 Christopher Schwan + * Copyright (C) 2020-2025 Christopher Schwan + * Copyright (C) 2024-2025 Tanjona R. Rabemananjara * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 49d99a2b42e41b0ff259593bdf73bb738cb719ec Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Sat, 24 May 2025 21:48:44 +0200 Subject: [PATCH 16/16] Add email address to C-API's `Cargo.toml` --- pineappl_capi/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pineappl_capi/Cargo.toml b/pineappl_capi/Cargo.toml index 219fe9b5..ad1bba58 100644 --- a/pineappl_capi/Cargo.toml +++ b/pineappl_capi/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = [ "Christopher Schwan ", - "Tanjona R. Rabemananjara <>" + "Tanjona R. Rabemananjara " ] description = "C language interface to PineAPPL" name = "pineappl_capi"