diff --git a/src/lib.rs b/src/lib.rs index 441ea1d..9d809e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ pub fn fft_with_opts( opts: &Options, planner: &mut Planner, ) { - assert_eq!(reals.len(), imags.len()); + assert!(reals.len() == imags.len() && reals.len().is_power_of_two()); let n: usize = reals.len().ilog2() as usize; let twiddles_re = &mut planner.twiddles_re; @@ -89,6 +89,19 @@ mod tests { use super::*; + #[should_panic] + #[test] + fn non_power_of_two_fft() { + let num_points = 5; + + // this test will actually always fail at this stage + let mut planner = Planner::new(num_points); + + let mut reals = vec![0.0; num_points]; + let mut imags = vec![0.0; num_points]; + fft(&mut reals, &mut imags, &mut planner); + } + #[test] fn fft_correctness() { let range = Range { start: 4, end: 17 }; diff --git a/src/planner.rs b/src/planner.rs index e5d5a47..1fd7ca0 100644 --- a/src/planner.rs +++ b/src/planner.rs @@ -5,6 +5,13 @@ pub struct Planner { pub twiddles_im: Vec, } +// TODO(saveliy yusufov): Add a parameter to `new` that will take into consideration whether we do inverse FFT (IFFT) +// In this case, the twiddle factors should be pre-computed as follows: +// +// FFT Twiddle Factor: e^{i2π*k/N} +// IFFT Twiddle Factor: e^{-i2π*k/N} +// +// source: https://dsp.stackexchange.com/q/73367 impl Planner { /// Create a `Planner` for an FFT of size `num_points` ///