AdamNiederer / faster

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

Support for Complex Numbers #27

Closed razorheadfx closed 6 years ago

razorheadfx commented 6 years ago

First of all thanks for making this library, the API looks really neat. I'm currently working on a project where I need to crunch a lot of complex numbers (esp. Complex) and would love to use faster instead of hooking into external C libraries like VOLK. Is support for complex types on your roadmap?

AdamNiederer commented 6 years ago

It looks like you could just cast an &[Complex32] to an &[f32] and process it with a strided iterator, because the struct is repr(C). Are there any things you are unable to do with that approach?

Something akin to this should work:

let (a, bi) = slice::from_raw_parts(&complexes as *const Complex32 as *const f32, complexes.len())
    .stride_two(/* default value here */);

a.simd_map(|| ...)
bi.simd_map(|| ...)
razorheadfx commented 6 years ago

Thanks, I'll give it a shot!

Update: Worked nicely!