Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to accomplish zip_mut_with in faster? #37

Open
jonathanstrong opened this issue May 9, 2018 · 2 comments
Open

how to accomplish zip_mut_with in faster? #37

jonathanstrong opened this issue May 9, 2018 · 2 comments

Comments

@jonathanstrong
Copy link

hey,

I have spent a few minutes trying unsuccessfully to write a simd version of code that uses ndarray's zip_mut_with - is there currently a way of combining a simd_iter_mut and simd_iter with zip?

Essentially, I'd like to modify the elements of an array in place with an operation that uses the values in another array of the same shape.

I tried this:

let mut xs = ndarray::Array::from_elem((64,), 0.0f32);
let ys = ndarray::Array::from_elem((64,), 1.0f32);
(xs.as_slice_mut().unwrap().simd_iter_mut(f32s(0.0)),
 ys.as_slice().unwrap().simd_iter(f32s(0.0)))
    .zip()
    .simd_for_each(|(x, y)| {
        *x += *y; // or whatever, not sure if this is correct for the closure
    });

and got this error:

error[E0599]: no method named `simd_for_each` found for type `faster::Zip<(faster::SIMDIter<&mut [f32]>, faster::SIMDIter<&[f32]>)>` in the current scope
   --> src/mlp/m3r.rs:298:26
    |
298 |                         .simd_for_each(|(z, b)| {
    |                          ^^^^^^^^^^^^^
...

Any recommendations for how to proceed? First time using the library, apologies if this is an obvious question.

@jesskfullwood
Copy link

I couldn't work this out either, FWIW. Wasted a lot of time thinking that for_each would do the job, before discovering that it creates a copy that is discarded, rather than mutating the vector in-place.

@AdamNiederer
Copy link
Owner

Mutable iterators are still a work in progress. For now, try using simd_do_each or the immutable/functional iterators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants