Skip to content

Commit be40eb0

Browse files
Re-order and simplify the parameters of pineappl_grid_evolve and OperatorCallback
1 parent a57c48f commit be40eb0

3 files changed

Lines changed: 65 additions & 48 deletions

File tree

examples/cpp/evolve-grid-identity.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cstddef>
99
#include <string>
1010
#include <vector>
11+
#include <numeric>
1112

1213
// NOTE: Uses the scale of the Grid as the starting scale such that we can use an IDENTITY EKO.
1314
double FAC0 = 6456.44;
@@ -27,23 +28,22 @@ std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector
2728
extern "C" void generate_fake_ekos(
2829
pineappl_conv_type /*conv_type*/,
2930
double /*fac1*/,
30-
std::size_t pids_in_len,
3131
const int* /*pids_in*/,
32-
std::size_t x_in_len,
3332
const double* /*x_in*/,
34-
std::size_t pids_out_len,
3533
const int* /*pids_out*/,
36-
std::size_t x_out_len,
3734
const double* /*x_out*/,
35+
const std::size_t* eko_shape,
3836
double* eko_buffer,
3937
void* params_state
4038
) {
4139
// Check to get the μ0 of the PDF from the `params_state`
4240
const double _ = static_cast<LHAPDF::PDF*> (params_state)->q2Min();
4341

44-
std::size_t flat_len = pids_in_len * x_in_len * pids_out_len * x_out_len;
45-
// NOTE: The EKO has to have as shape: (pids_in, x_in, pids_out, x_out)
46-
std::vector<std::size_t> shape = {pids_in_len, x_in_len, pids_out_len, x_out_len};
42+
// NOTE: This has to work because the Evolution Operator is always 4D
43+
std::vector<std::size_t> shape(eko_shape, eko_shape + 4);
44+
// Compute the length of the flattened shape by multiplying the entries
45+
std::size_t flat_len = std::accumulate(shape.begin(),
46+
shape.end(), 1, std::multiplies<std::size_t>());
4747
for (std::size_t i = 0; i != flat_len; i++) {
4848
std::vector<std::size_t> coords = unravel_index(i, shape);
4949

@@ -185,21 +185,34 @@ int main() {
185185
// - `grid`: PineAPPL Grid
186186
// - `nb_slices`: the number of convolution(s)/Evolution Operator(s) required
187187
// - `slices`: callback that returns the evolution operator(s) in slices
188+
// - `operator_info`: operator info
189+
// - `pids_in`: PIDs basis representation of the Grid
190+
// - `x_in`: x-grid of the Grid
191+
// - `pids_out`: PIDs basis representation of the FK table
192+
// - `x_out`: x-grid of the FK table
188193
// - `state`: parameters that get passed to `operator`
189194
// - `order_mask`: array of booleans to mask the order(s) to apply the Evolution to,
190195
// `nullptr` selects all the orders
191196
// - `xi`: scale variation
192197
// - `ren1`: values of the renormalization scales
193198
// - `alphas_table`: values of alphas for each renormalization scales
194-
// - `operator_info`: operator info
195-
// - `x_in`: x-grid of the Grid
196-
// - `x_out`: x-grid of the FK table
197-
// - `pids_in`: PIDs basis representation of the Grid
198-
// - `pids_out`: PIDs basis representation of the FK table
199199
// - `eko_shape`: shape of the evolution operators
200-
pineappl_grid* fktable = pineappl_grid_evolve(grid, unique_convs.size(), generate_fake_ekos,
201-
opinfo_slices.data(), pdf.get(), nullptr, xi.data(), ren1.data(), alphas_table.data(),
202-
x_in.data(), x_in.data(), pids_in.data(), pids_out.data(), tensor_shape.data());
200+
pineappl_grid* fktable = pineappl_grid_evolve(
201+
grid, // `grid`
202+
unique_convs.size(), // `nb_slices`
203+
generate_fake_ekos, // `slices`
204+
opinfo_slices.data(), // `operator_info`
205+
pids_in.data(), // `pids_in`
206+
x_in.data(), // `x_in`
207+
pids_out.data(), // `pids_out`
208+
x_in.data(), // `x_out`
209+
tensor_shape.data(), // `eko_shape`
210+
pdf.get(), // `state`
211+
nullptr, // `order_mask`
212+
xi.data(), // `xi`
213+
ren1.data(), // `ren1`
214+
alphas_table.data() // `alphas_table`
215+
);
203216

204217
// ------------------ Compare Grid & FK after convolution ------------------
205218
// how many bins does this grid have?

examples/cpp/evolve-grid.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector
8585
extern "C" void generate_fake_ekos(
8686
pineappl_conv_type /*conv_type*/,
8787
double /*fac1*/,
88-
std::size_t /*pids_in_len*/,
8988
const int* /*pids_in*/,
90-
std::size_t /*x_in_len*/,
9189
const double* /*x_in*/,
92-
std::size_t /*pids_out_len*/,
9390
const int* /*pids_out*/,
94-
std::size_t /*x_out_len*/,
9591
const double* /*x_out*/,
92+
const std::size_t* /*eko_shape*/,
9693
double* eko_buffer,
9794
void* params_state
9895
) {
@@ -239,21 +236,34 @@ int main() {
239236
// - `grid`: PineAPPL Grid
240237
// - `nb_slices`: the number of convolution(s)/Evolution Operator(s) required
241238
// - `slices`: callback that returns the evolution operator(s) in slices
239+
// - `operator_info`: operator info
240+
// - `pids_in`: PIDs basis representation of the Grid
241+
// - `x_in`: x-grid of the Grid
242+
// - `pids_out`: PIDs basis representation of the FK table
243+
// - `x_out`: x-grid of the FK table
242244
// - `state`: parameters that get passed to `operator`
243245
// - `order_mask`: array of booleans to mask the order(s) to apply the Evolution to,
244246
// `nullptr` selects all the orders
245247
// - `xi`: scale variation
246248
// - `ren1`: values of the renormalization scales
247249
// - `alphas_table`: values of alphas for each renormalization scales
248-
// - `operator_info`: operator info
249-
// - `x_in`: x-grid of the Grid
250-
// - `x_out`: x-grid of the FK table
251-
// - `pids_in`: PIDs basis representation of the Grid
252-
// - `pids_out`: PIDs basis representation of the FK table
253250
// - `eko_shape`: shape of the evolution operators
254-
pineappl_grid* fktable = pineappl_grid_evolve(grid, unique_convs.size(), generate_fake_ekos,
255-
opinfo_slices.data(), pdf.get(), nullptr, xi.data(), ren1.data(), alphas_table.data(),
256-
XGRID.data(), XGRID.data(), pids_in.data(), pids_out.data(), tensor_shape.data());
251+
pineappl_grid* fktable = pineappl_grid_evolve(
252+
grid, // `grid`
253+
unique_convs.size(), // `nb_slices`
254+
generate_fake_ekos, // `slices`
255+
opinfo_slices.data(), // `operator_info`
256+
pids_in.data(), // `pids_in`
257+
XGRID.data(), // `x_in`
258+
pids_out.data(), // `pids_out`
259+
XGRID.data(), // `x_out`
260+
tensor_shape.data(), // `eko_shape`
261+
pdf.get(), // `state`
262+
nullptr, // `order_mask`
263+
xi.data(), // `xi`
264+
ren1.data(), // `ren1`
265+
alphas_table.data() // `alphas_table`
266+
);
257267

258268
// ------------------ Compare Grid & FK after convolution ------------------
259269
// how many bins does this grid have?

pineappl_capi/src/lib.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,18 +2139,15 @@ pub unsafe extern "C" fn pineappl_grid_evolve_info(
21392139

21402140
/// Type alias for the operator callback
21412141
pub type OperatorCallback = unsafe extern "C" fn(
2142-
ConvType, // Convolution type
2143-
f64, // fac1
2144-
usize, // size of `pids_in`
2145-
*const i32, // `pids_in`
2146-
usize, // size of `x_in`
2147-
*const f64, // `x_in`
2148-
usize, // size of `pids_out`
2149-
*const i32, // `pids_out`
2150-
usize, // size of `x_out`
2151-
*const f64, // `x_out`
2152-
*mut f64, // Evolution Operator data buffer
2153-
*mut c_void, // Callable state of parameters
2142+
ConvType, // Convolution type
2143+
f64, // fac1
2144+
*const i32, // `pids_in`
2145+
*const f64, // `x_in`
2146+
*const i32, // `pids_out`
2147+
*const f64, // `x_out`
2148+
*const usize, // shape of the EKO
2149+
*mut f64, // Evolution Operator data buffer
2150+
*mut c_void, // Callable state of parameters
21542151
);
21552152

21562153
/// Evolve a grid with an evolution operator and dump the resulting FK table.
@@ -2188,16 +2185,16 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
21882185
nb_slices: usize,
21892186
slices: OperatorCallback,
21902187
operator_info: *const OperatorInfo,
2188+
pids_in: *const i32,
2189+
x_in: *const f64,
2190+
pids_out: *const i32,
2191+
x_out: *const f64,
2192+
eko_shape: *const usize,
21912193
state: *mut c_void,
21922194
order_mask: *const bool,
21932195
xi: *const f64,
21942196
ren1: *const f64,
21952197
alphas: *const f64,
2196-
x_in: *const f64,
2197-
x_out: *const f64,
2198-
pids_in: *const i32,
2199-
pids_out: *const i32,
2200-
eko_shape: *const usize,
22012198
) -> Box<Grid> {
22022199
let grid = unsafe { &*grid };
22032200

@@ -2249,14 +2246,11 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22492246
slices(
22502247
op_info.conv_type,
22512248
op_info.fac1,
2252-
pids_in.len(),
22532249
pids_in.as_ptr(),
2254-
x_in.len(),
22552250
x_in.as_ptr(),
2256-
pids_out.len(),
22572251
pids_out.as_ptr(),
2258-
x_out.len(),
22592252
x_out.as_ptr(),
2253+
eko_shape.as_ptr(),
22602254
array
22612255
.as_slice_mut()
22622256
// UNWRAP: `array` is by construction contiguous and in standard order

0 commit comments

Comments
 (0)