ejmahler / RustFFT

RustFFT is a high-performance FFT library written in pure Rust.
Apache License 2.0
678 stars 47 forks source link

[Feature Request] Set stride #73

Closed tstsrt closed 3 years ago

tstsrt commented 3 years ago

I would like to be able to set the stride of the FFT. This is very useful for computing 2D and 3D FFTs.

Example usage:

let mut buffer2d = [1,0,0,0,
                    0,0,0,0];

// x direction
let mut fft = fft_planner.plan_fft(4, FftDirection::Forward);
fft.set_stride(1);
fft.process(&mut buffer2d);
assert_eq!(buffer2d, [1,1,1,1,
                      0,0,0,0]);

// y direction
fft = fft_planner.plan_fft(2, FftDirection::Inverse);
fft.set_stride(4);
fft.process(&mut buffer2d);
assert_eq!(buffer2d, [1,1,1,1,
                      1,1,1,1]);
HEnquist commented 3 years ago

This would complicate things a lot, and very likely give a significant performance drop. Why not just transpose the data between the fft steps? Check "transpose" on crates.io for nice fast 2D transposes.

tstsrt commented 3 years ago

I did end up manually transposing the data. I just thought that adding a stride parameter would have a minimal performance impact. However, if this is not the case, I think the library's speed is more valuable than the convenience of having a stride parameter.

ejmahler commented 3 years ago

I do think there is some room in rustFFT for stride, but it would work by copying the data to a contiguous scratch buffer, and then doing the FFT contiguously. This would have the potential for being faster than the standard width -> transpose -> height ->transpose process, since it would be much more cache friendly.

I don't think I'll be able to get to it in the near future, unfortunately.