pub(crate) fn fill_rows<T: Send>(
buffer: &mut [T],
stride: usize,
fill: impl Fn(usize, &mut [T]) + Send + Sync,
) {
if stride == 0 {
return;
}
#[cfg(feature = "rayon")]
{
use rayon::prelude::*;
buffer
.par_chunks_mut(stride)
.enumerate()
.for_each(|(y, row)| fill(y, row));
}
#[cfg(not(feature = "rayon"))]
buffer
.chunks_mut(stride)
.enumerate()
.for_each(|(y, row)| fill(y, row));
}
pub(crate) fn sum_rows(rows: usize, of: impl Fn(usize) -> u64 + Send + Sync) -> u64 {
#[cfg(feature = "rayon")]
{
use rayon::prelude::*;
(0..rows).into_par_iter().map(of).sum()
}
#[cfg(not(feature = "rayon"))]
(0..rows).map(of).sum()
}