Skip to content

Commit 2bbac76

Browse files
Clean up a bit pineappl_grid_evolve
1 parent 2f5dbef commit 2bbac76

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

pineappl_capi/src/lib.rs

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,53 +2143,46 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
21432143
.map(pineappl::convolutions::Conv::conv_type)
21442144
.collect();
21452145

2146-
let op_info =
2147-
unsafe { slice::from_raw_parts(op_info, conv_types.len() * evolve_info.fac1.len()) };
2148-
let opinfo_chunk = op_info.chunks_exact(conv_types.len());
2146+
let op_info = unsafe {
2147+
slice::from_raw_parts(op_info, conv_types.len() * evolve_info.fac1.len())
2148+
.chunks_exact(conv_types.len())
2149+
};
21492150

2150-
let flattened_shapes: usize = op_info
2151-
.iter()
2152-
.map(|_| eko_shape.iter().product::<usize>())
2153-
.sum();
2154-
let operators =
2155-
unsafe { slice::from_raw_parts(operators, conv_types.len() * flattened_shapes) };
2151+
let total_shape: usize = eko_shape.iter().product();
2152+
let operators = unsafe {
2153+
slice::from_raw_parts(
2154+
operators,
2155+
conv_types.len() * evolve_info.fac1.len() * total_shape,
2156+
)
2157+
.chunks_exact(total_shape)
2158+
};
21562159

2157-
let mut start_idx = 0;
2158-
let op_split: Vec<_> = op_info
2159-
.iter()
2160-
.map(|_| {
2161-
let end_idx = start_idx + eko_shape.iter().product::<usize>();
2162-
let op_range = operators[start_idx..end_idx].to_vec();
2163-
start_idx = end_idx;
2164-
op_range
2165-
})
2166-
.collect();
2167-
let ops_chunk = op_split.chunks_exact(conv_types.len());
2168-
2169-
let slices = opinfo_chunk
2170-
.into_iter()
2171-
.zip(ops_chunk)
2172-
.map(|(op_subinfo, op_range)| {
2173-
op_subinfo.iter().zip(op_range).map(|(opinfo, op_values)| {
2174-
let operator_slice_info = OperatorSliceInfo {
2175-
pid_basis: opinfo.pid_basis,
2176-
fac0: opinfo.fac0,
2177-
pids0: pids_fktable.to_vec(),
2178-
x0: x_fktable.to_vec(),
2179-
fac1: opinfo.fac1,
2180-
pids1: pids_grid.to_vec(),
2181-
x1: x_grid.to_vec(),
2182-
conv_type: opinfo.conv_type,
2183-
};
2184-
2185-
let array = Array4::from_shape_vec(
2186-
Ix4(eko_shape[0], eko_shape[1], eko_shape[2], eko_shape[3]),
2187-
op_values.clone(),
2188-
)
2189-
.expect("Shape mismatch or invalid input.");
2190-
2191-
Ok::<_, std::io::Error>((operator_slice_info, CowArray::from(array)))
2192-
})
2160+
let slices = op_info
2161+
.zip(operators)
2162+
.map(|(op_infos, op_vals)| {
2163+
op_infos
2164+
.iter()
2165+
.zip(std::iter::once(op_vals))
2166+
.map(|(op_info, values)| {
2167+
let operator_slice_info = OperatorSliceInfo {
2168+
pid_basis: op_info.pid_basis,
2169+
fac0: op_info.fac0,
2170+
pids0: pids_fktable.to_vec(),
2171+
x0: x_fktable.to_vec(),
2172+
fac1: op_info.fac1,
2173+
pids1: pids_grid.to_vec(),
2174+
x1: x_grid.to_vec(),
2175+
conv_type: op_info.conv_type,
2176+
};
2177+
2178+
let array = Array4::from_shape_vec(
2179+
Ix4(eko_shape[0], eko_shape[1], eko_shape[2], eko_shape[3]),
2180+
values.to_vec(),
2181+
)
2182+
.expect("Shape mismatch or invalid input.");
2183+
2184+
Ok::<_, std::io::Error>((operator_slice_info, CowArray::from(array)))
2185+
})
21932186
})
21942187
.collect();
21952188

@@ -2203,7 +2196,7 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22032196
},
22042197
);
22052198

2206-
Box::new(fk_table.unwrap())
2199+
Box::new(fk_table.expect("Evolving grid failed"))
22072200
}
22082201

22092202
/// Delete an FK table.

0 commit comments

Comments
 (0)