Skip to content

Instantly share code, notes, and snippets.

@bvssvni bvssvni/test.rs
Last active Jan 17, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.