@@ -1460,8 +1460,11 @@ pub unsafe extern "C" fn pineappl_string_delete(string: *mut c_char) {
14601460// Here starts the generalized C-API interface.
14611461
14621462/// Type for defining a Channel function.
1463- #[ derive( Default ) ]
1464- pub struct Channels ( Vec < Channel > , usize ) ;
1463+ #[ derive( Clone ) ]
1464+ pub struct Channels {
1465+ channels : Vec < Channel > ,
1466+ convolutions : usize ,
1467+ }
14651468
14661469/// Type for defining the interpolation object
14671470#[ repr( C ) ]
@@ -1487,7 +1490,10 @@ pub struct Interp {
14871490#[ no_mangle]
14881491#[ must_use]
14891492pub extern "C" fn pineappl_channels_new ( convolutions : usize ) -> Box < Channels > {
1490- Box :: new ( Channels ( Vec :: new ( ) , convolutions) )
1493+ Box :: new ( Channels {
1494+ channels : Vec :: new ( ) ,
1495+ convolutions,
1496+ } )
14911497}
14921498
14931499/// Adds a generalized linear combination of initial states to the Luminosity.
@@ -1506,20 +1512,23 @@ pub unsafe extern "C" fn pineappl_channels_add(
15061512 pdg_id_combinations : * const i32 ,
15071513 factors : * const f64 ,
15081514) {
1509- let channels = unsafe { & mut * channels } ;
1515+ let & mut Channels {
1516+ ref mut channels,
1517+ convolutions,
1518+ } = unsafe { & mut * channels } ;
15101519 let pdg_id_pairs =
1511- unsafe { slice:: from_raw_parts ( pdg_id_combinations, channels . 1 * combinations) } ;
1520+ unsafe { slice:: from_raw_parts ( pdg_id_combinations, convolutions * combinations) } ;
15121521 let factors = if factors. is_null ( ) {
15131522 vec ! [ 1.0 ; combinations]
15141523 } else {
15151524 unsafe { slice:: from_raw_parts ( factors, combinations) } . to_vec ( )
15161525 } ;
15171526
1518- channels. 0 . push ( Channel :: new (
1527+ channels. push ( Channel :: new (
15191528 pdg_id_pairs
1520- . chunks ( channels . 1 )
1529+ . chunks ( convolutions )
15211530 . zip ( factors)
1522- . map ( |x| ( ( 0 ..channels . 1 ) . map ( |i| x. 0 [ i] ) . collect ( ) , x. 1 ) )
1531+ . map ( |x| ( ( 0 ..convolutions ) . map ( |i| x. 0 [ i] ) . collect ( ) , x. 1 ) )
15231532 . collect ( ) ,
15241533 ) ) ;
15251534}
@@ -1534,10 +1543,10 @@ pub unsafe extern "C" fn pineappl_channels_add(
15341543pub unsafe extern "C" fn pineappl_grid_channels ( grid : * const Grid ) -> Box < Channels > {
15351544 let grid = unsafe { & * grid } ;
15361545
1537- Box :: new ( Channels (
1538- grid. channels ( ) . to_vec ( ) ,
1539- grid. convolutions ( ) . len ( ) ,
1540- ) )
1546+ Box :: new ( Channels {
1547+ channels : grid. channels ( ) . to_vec ( ) ,
1548+ convolutions : grid. convolutions ( ) . len ( ) ,
1549+ } )
15411550}
15421551
15431552/// 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<Channe
15481557/// `pineappl_grid_channels`.
15491558#[ no_mangle]
15501559pub unsafe extern "C" fn pineappl_channels_count ( channels : * const Channels ) -> usize {
1551- let channels = unsafe { & * channels } ;
1560+ let Channels { channels, .. } = unsafe { & * channels } ;
15521561
1553- channels. 0 . len ( )
1562+ channels. len ( )
15541563}
15551564
15561565/// 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(
15641573 channels : * const Channels ,
15651574 entry : usize ,
15661575) -> usize {
1567- let channels = unsafe { & * channels } ;
1576+ let Channels { channels, .. } = unsafe { & * channels } ;
15681577
1569- channels. 0 [ entry] . entry ( ) . len ( )
1578+ channels[ entry] . entry ( ) . len ( )
15701579}
15711580
15721581/// 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(
16381647 logxia : s[ 4 ] ,
16391648 } )
16401649 . collect ( ) ;
1641- let channels = unsafe { & * channels } ;
1650+ let Channels {
1651+ channels,
1652+ convolutions,
1653+ } = unsafe { & * channels } . clone ( ) ;
16421654
16431655 // Construct the convolution objects
1644- let convolutions = channels. 1 ;
16451656 let convolution_types =
16461657 unsafe { slice:: from_raw_parts ( convolution_types, convolutions) . to_vec ( ) } ;
16471658 let convolution_pdg_ids =
@@ -1690,7 +1701,7 @@ pub unsafe extern "C" fn pineappl_grid_new2(
16901701 Box :: new ( Grid :: new (
16911702 bins,
16921703 orders,
1693- channels. 0 . clone ( ) ,
1704+ channels,
16941705 pid_basis,
16951706 convolutions,
16961707 interp_vecs,
@@ -1814,11 +1825,11 @@ pub unsafe extern "C" fn pineappl_channels_entry(
18141825 pdg_ids : * mut i32 ,
18151826 factors : * mut f64 ,
18161827) {
1817- let channels = unsafe { & * channels } ;
1818- let entry = channels. 0 [ entry ] . entry ( ) ;
1819- // if the channel has no entries we assume no convolutions, which is OK we don't copy anything
1820- // in this case
1821- let convolutions = entry. get ( 0 ) . map_or ( 0 , |x| x . 0 . len ( ) ) ;
1828+ let Channels {
1829+ channels,
1830+ convolutions,
1831+ } = unsafe { & * channels } ;
1832+ let entry = channels [ entry] . entry ( ) ;
18221833 let pdg_ids = unsafe { slice:: from_raw_parts_mut ( pdg_ids, convolutions * entry. len ( ) ) } ;
18231834 let factors = unsafe { slice:: from_raw_parts_mut ( factors, entry. len ( ) ) } ;
18241835
0 commit comments