Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Last active January 17, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvssvni/cf1f63daa861415a83ab3f9d1eef2991 to your computer and use it in GitHub Desktop.
Save bvssvni/cf1f63daa861415a83ab3f9d1eef2991 to your computer and use it in GitHub Desktop.
YEAH! It compiles!
pub fn par_trans2(
pos: V2<f32>,
f: Box<Fn(&[V2<f32>], &mut [bool]) + Sync>
) -> Box<Fn(&[V2<f32>], &mut [bool]) + Sync>{
const SIZE: usize = 1024;
Box::new(move |input, output| {
input.par_chunks(SIZE)
.zip(output.par_chunks_mut(SIZE))
.for_each(|(i, o): (&[V2<f32>], &mut [bool])| {
/// Use stack memory to avoid allocations.
let mut i2: [V2<f32>; SIZE] = [V2 {x: 0.0, y: 0.0}; SIZE];
for p in i2.iter_mut().take(i.len()) {
*p = *p - pos;
}
f(&i2[..i.len()], o)
})
})
}
@bvssvni
Copy link
Author

bvssvni commented Jan 17, 2017

This is a breakthrough because it might allow composing such functions together to perform parallel stream processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment