diff --git a/examples/benchmark.rs b/examples/benchmark.rs index a8f802d..d3c2408 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -1,11 +1,15 @@ use phastft::fft_dif; +use phastft::utils::gen_random_signal; fn bm_fft(num_qubits: usize) { for i in 4..num_qubits { println!("run PhastFT with {i} qubits"); let n = 1 << i; - let mut reals: Vec = (1..=n).map(f64::from).collect(); - let mut imags: Vec = (1..=n).map(f64::from).collect(); + + let mut reals = vec![0.0; n]; + let mut imags = vec![0.0; n]; + + gen_random_signal(&mut reals, &mut imags); let now = std::time::Instant::now(); fft_dif(&mut reals, &mut imags); diff --git a/src/twiddles.rs b/src/twiddles.rs index 58f33d5..de5f2a2 100644 --- a/src/twiddles.rs +++ b/src/twiddles.rs @@ -135,8 +135,8 @@ pub(crate) fn generate_twiddles_simd(dist: usize) -> (Vec, Vec) { // This avoids data dependencies of the regular calculation and gets vectorized. // We do it up front while the values we just calculated are still in the cache // so we don't have to re-load them from memory later, which would be slow. - apply_symmetry_re(&first_ch_re, second_ch_re); - apply_symmetry_im(&first_ch_im, second_ch_im); + apply_symmetry_re(first_ch_re, second_ch_re); + apply_symmetry_im(first_ch_im, second_ch_im); }, ); diff --git a/src/utils.rs b/src/utils.rs index 7264eae..d7a9d56 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,7 +6,7 @@ use std::f64::consts::PI; #[allow(dead_code)] #[track_caller] pub(crate) fn assert_f64_closeness(actual: f64, expected: f64, epsilon: f64) { - if !((actual - expected).abs() < epsilon) { + if (actual - expected).abs() >= epsilon { panic!( "Assertion failed: {} too far from expected value {} (with epsilon {})", actual, expected, epsilon @@ -18,7 +18,7 @@ pub(crate) fn assert_f64_closeness(actual: f64, expected: f64, epsilon: f64) { #[allow(dead_code)] #[track_caller] pub(crate) fn assert_f32_closeness(actual: f32, expected: f32, epsilon: f32) { - if !((actual - expected).abs() < epsilon) { + if (actual - expected).abs() >= epsilon { panic!( "Assertion failed: {} too far from expected value {} (with epsilon {})", actual, expected, epsilon @@ -27,7 +27,7 @@ pub(crate) fn assert_f32_closeness(actual: f32, expected: f32, epsilon: f32) { } pub fn gen_random_signal(reals: &mut [f64], imags: &mut [f64]) { - assert!(reals.len() == imags.len() && reals.len() > 0); + assert!(reals.len() == imags.len() && !reals.is_empty()); let mut rng = thread_rng(); let between = Uniform::from(0.0..1.0); let angle_dist = Uniform::from(0.0..2.0 * PI);