pub fn fft_inplace(
input: &mut [Complex64],
output: &mut [Complex64],
mode: FftMode,
normalize: bool,
) -> FFTResult<usize>
Expand description
Computes FFT in-place to minimize memory allocations
This function performs an in-place FFT using pre-allocated buffers to minimize memory allocations, which is beneficial for large arrays or when performing many FFT operations.
§Arguments
input
- Input buffer (will be modified in-place)output
- Pre-allocated output buffermode
- Whether to compute forward or inverse FFTnormalize
- Whether to normalize the result (required for IFFT)
§Returns
- Result with the number of elements processed
§Errors
Returns an error if the computation fails.
§Examples
use scirs2_fft::memory_efficient::{fft_inplace, FftMode};
use scirs2_core::numeric::Complex64;
// Create input and output buffers
let mut input_buffer = vec![Complex64::new(1.0, 0.0),
Complex64::new(2.0, 0.0),
Complex64::new(3.0, 0.0),
Complex64::new(4.0, 0.0)];
let mut output_buffer = vec![Complex64::new(0.0, 0.0); input_buffer.len()];
// Perform in-place FFT
fft_inplace(&mut input_buffer, &mut output_buffer, FftMode::Forward, false).unwrap();
// Input buffer now contains the result
let sum: f64 = (1.0 + 2.0 + 3.0 + 4.0);
assert!((input_buffer[0].re - sum).abs() < 1e-10);