RustFFT icon indicating copy to clipboard operation
RustFFT copied to clipboard

Don't require process_outofplace_with_scratch input to be mutable

Open michaelciraci opened this issue 10 months ago • 5 comments

Right now, the Fft options are:

fn process(&self, buffer: &mut [Complex<T>]);
fn process_with_scratch(&self,
        buffer: &mut [Complex<T>],
        scratch: &mut [Complex<T>],
    );
fn process_outofplace_with_scratch(
        &self,
        input: &mut [Complex<T>],
        output: &mut [Complex<T>],
        scratch: &mut [Complex<T>],
    );

Can you provide an API where the input does not need to be mutable? Right now, if I have a non-mutable slice I need to clone the slice before I can take the FFT.

michaelciraci avatar Mar 08 '25 19:03 michaelciraci

ThIs would be quite convenient. Many of the algorithms (most of them IIRC) modify the input while performing the transform. So this new method would need to copy the input to a scratch buffer as the first step. It could be implemented quite easily as a provided method on the Fft trait.

HEnquist avatar Mar 08 '25 19:03 HEnquist

Do you think the past path to implement this would be to add a new function to the Fft trait? Maybe something like this:

fn process_outofplace_with_scratch_immut(
        &self,
        input: &[Complex<T>],
        output: &mut [Complex<T>],
        scratch1: &mut [Complex<T>],
        scratch2: &mut [Complex<T>],
    );

michaelciraci avatar Mar 08 '25 21:03 michaelciraci

Yes, but I would use a single scratch buffer and split it with split_at_mut(): https://doc.rust-lang.org/std/primitive.slice.html#method.split_at_mut

HEnquist avatar Mar 08 '25 21:03 HEnquist

Thanks for the info.

And it looks like there are several instances where perform_fft_out_of_place calls process_with_scratch (for example: https://github.com/ejmahler/RustFFT/blob/master/src/algorithm/good_thomas_algorithm.rs#L411). Any reason why this isn't self.height_size_fft.perform_fft_out_of_place?

michaelciraci avatar Mar 08 '25 22:03 michaelciraci

I didn't implement sse/neon/wasm yet, but I wanted to get your feedback first: https://github.com/ejmahler/RustFFT/pull/157

michaelciraci avatar Mar 09 '25 04:03 michaelciraci

Closed by #157

ejmahler avatar Jun 06 '25 04:06 ejmahler