Skip to content

Commit

Permalink
Add asert to check input length is 2^n
Browse files Browse the repository at this point in the history
- Add a regression test to make sure non-power-of-two FFTs are not
  allowed for the time being
  • Loading branch information
smu160 committed Feb 7, 2024
1 parent dbe863d commit 719a5ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
Expand Down
7 changes: 7 additions & 0 deletions src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ pub struct Planner {
pub twiddles_im: Vec<f64>,
}

// 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`
///
Expand Down

0 comments on commit 719a5ba

Please sign in to comment.