AdamNiederer / faster

SIMD for humans
Mozilla Public License 2.0
1.56k stars 51 forks source link

simd_for_each does nothing #14

Closed Osveron closed 6 years ago

Osveron commented 6 years ago

I have tried to do something using faster and noticed that you added simd_for_each, but it doesn't seems to do anything. Simple case:

extern crate faster;
use faster::*;

fn main() {
    let mut vector = vec![0f32, 1f32, 2f32, 3f32];
    vector
        .as_mut_slice()
        .simd_iter_mut()
        .simd_for_each(f32s(0f32), |mut x| x /= f32s(2f32));
    println!("{:?}", vector);
    vector.iter_mut().for_each(|x| *x /= 2f32);
    println!("{:?}", vector);
}

Outputs:

[0.0, 1.0, 2.0, 3.0]
[0.0, 0.5, 1.0, 1.5]

I have looked at the implementation of this function and it takes a owned simd vector and performs user provided function on it and then does nothing with the result. There should be store somewhere in there and the user provided function should take mutable reference to the simd vector. Or maybe I'm doing something wrong since there aren't any examples yet.

AdamNiederer commented 6 years ago

Hi there, Sorry for the lack of docs - I usually add them immediately before releases.

simd_for_each doesn't do anything by design at the moment, as I'm still implementing mutable/in-place iterators. I should have this finished by 0.5.0. You can get around this by either using simd_map, or manually storing in the closure for now.

AdamNiederer commented 6 years ago

Resolved in 595789262d653077529a6b7424adc35bfe18c871