Skip to content

Commit

Permalink
Fix bug in r2c fft using extra planner
Browse files Browse the repository at this point in the history
- This is a quick, but hacky and inefficient way to use the twiddle
  factors generated by the `Planner`, but it works.

- Add more details to assert statements for debugging
  • Loading branch information
smu160 committed Aug 15, 2024
1 parent e7dbd86 commit 0c10592
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::simd::prelude::f64x8;

use crate::planner::{Planner32, Planner64};
use crate::twiddles::filter_twiddles;
use crate::{
fft_32_with_opts_and_plan, fft_64, fft_64_with_opts_and_plan, twiddles::generate_twiddles,
Direction, Options,
Expand Down Expand Up @@ -64,11 +63,13 @@ macro_rules! impl_r2c_fft {
let mut planner = <$planner>::new(big_n, Direction::Forward);

// save these for the untanngling step
let twiddle_re = planner.twiddles_re.clone();
let twiddle_im = planner.twiddles_im.clone();
let twiddle_re = planner.twiddles_re;
let twiddle_im = planner.twiddles_im;

planner = <$planner>::new(big_n / 2, Direction::Forward);

// We only need (N / 2) / 2 twiddle factors for the actual FFT call, so we filter
filter_twiddles(&mut planner.twiddles_re, &mut planner.twiddles_im);
// filter_twiddles(&mut planner.twiddles_re, &mut planner.twiddles_im);

let opts = Options::guess_options(z_even.len());
$fft_w_opts_and_plan(&mut z_even, &mut z_odd, &opts, &mut planner);
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ macro_rules! impl_fft_interleaved_for {
};
}

#[doc(cfg(feature = "complex-nums"))]
// #[doc(cfg(feature = "complex-nums"))]
#[cfg(feature = "complex-nums")]
impl_fft_interleaved_for!(fft_32_interleaved, f32, fft_32, deinterleave_complex32);
#[doc(cfg(feature = "complex-nums"))]
// #[doc(cfg(feature = "complex-nums"))]
#[cfg(feature = "complex-nums")]
impl_fft_interleaved_for!(fft_64_interleaved, f64, fft_64, deinterleave_complex64);

Expand Down Expand Up @@ -129,7 +129,7 @@ macro_rules! impl_fft_with_opts_and_plan_for {
opts: &Options,
planner: &$planner,
) {
assert!(reals.len() == imags.len() && reals.len().is_power_of_two());
assert!(reals.len() == imags.len() && reals.len().is_power_of_two(), "reals.len() and imags.len() must be equal, and both should be a power of 2. Actual lengths - reals: {} imags: {}", reals.len(), imags.len());
let n: usize = reals.len().ilog2() as usize;

// Use references to avoid unnecessary clones
Expand All @@ -138,7 +138,7 @@ macro_rules! impl_fft_with_opts_and_plan_for {

// We shouldn't be able to execute FFT if the # of twiddles isn't equal to the distance
// between pairs
assert!(twiddles_re.len() == reals.len() / 2 && twiddles_im.len() == imags.len() / 2);
assert!(twiddles_re.len() == reals.len() / 2 && twiddles_im.len() == imags.len() / 2,"got: {} == {} and {} == {}", twiddles_re.len(), reals.len() / 2, twiddles_im.len(), imags.len() / 2);

match planner.direction {
Direction::Reverse => {
Expand Down

0 comments on commit 0c10592

Please sign in to comment.