Skip to content

Commit 901bff7

Browse files
committed
Add regression test for planner/fft mismatch
1 parent c8898d5 commit 901bff7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub fn fft_with_opts_and_plan(
6363
let twiddles_re = &mut planner.twiddles_re;
6464
let twiddles_im = &mut planner.twiddles_im;
6565

66+
// We shouldn't be able to execute FFT if the # of twiddles isn't equal to the distance between pairs
67+
assert!(twiddles_re.len() / 2 == reals.len() && twiddles_im.len() / 2 == imags.len());
68+
6669
for t in (0..n).rev() {
6770
let dist = 1 << t;
6871
let chunk_size = dist << 1;
@@ -123,6 +126,24 @@ mod tests {
123126
fft_with_opts_and_plan(&mut reals, &mut imags, &opts, &mut planner);
124127
}
125128

129+
// a regression test to make sure planner is always compatible with fft execution
130+
#[should_panic]
131+
#[test]
132+
fn wrong_num_points_in_planner() {
133+
let n = 16;
134+
let num_points = 1 << n;
135+
136+
// this test will actually always fail at this stage
137+
138+
let mut planner = Planner::new(n, Direction::Forward);
139+
let mut reals = vec![0.0; num_points];
140+
let mut imags = vec![0.0; num_points];
141+
let opts = Options::guess_options(reals.len());
142+
143+
// but this call should panic as well
144+
fft_with_opts_and_plan(&mut reals, &mut imags, &opts, &mut planner);
145+
}
146+
126147
#[test]
127148
fn fft_correctness() {
128149
let range = Range { start: 4, end: 17 };

0 commit comments

Comments
 (0)