From 60dd0ff35a1a242c575caf70b1f840ba9c541196 Mon Sep 17 00:00:00 2001 From: alindima Date: Thu, 25 Jan 2024 17:19:05 +0200 Subject: [PATCH] apply suggestion --- reed-solomon-novelpoly/src/field/inc_afft.rs | 60 ++++++++------------ 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/reed-solomon-novelpoly/src/field/inc_afft.rs b/reed-solomon-novelpoly/src/field/inc_afft.rs index 4719f86..f0d9ffd 100644 --- a/reed-solomon-novelpoly/src/field/inc_afft.rs +++ b/reed-solomon-novelpoly/src/field/inc_afft.rs @@ -475,44 +475,38 @@ impl AdditiveFFT { #[cfg(test)] mod afft_tests { - use rand::{SeedableRng, Rng}; - use crate::f2e16::{Additive, Elt}; - use reed_solomon_tester::SMALL_RNG_SEED; - - pub fn gen_plain>(size: usize) -> Vec { - let rng = ::from_seed(SMALL_RNG_SEED); - let dist = rand::distributions::Uniform::new_inclusive(Elt::MIN, Elt::MAX); - - Vec::from_iter(rng.sample_iter::(dist).take(size).map(Additive)) - } - #[cfg(all(target_feature = "avx", feature = "avx"))] - pub fn gen_faster8_from_plain(data: impl AsRef<[Additive]>) -> Vec { - let data = data.as_ref(); - data.to_vec() - } + mod simd { + use super::super::*; + use reed_solomon_tester::SMALL_RNG_SEED; + use rand::{SeedableRng, Rng, rngs::SmallRng}; - #[cfg(all(target_feature = "avx", feature = "avx"))] - pub fn gen_faster8>(size: usize) -> Vec { - let data = gen_plain::(size); - gen_faster8_from_plain(data) - } + pub fn gen_plain>(size: usize) -> Vec { + let rng = ::from_seed(SMALL_RNG_SEED); + let dist = rand::distributions::Uniform::new_inclusive(Elt::MIN, Elt::MAX); - #[cfg(all(target_feature = "avx", feature = "avx"))] - pub fn assert_plain_eq_faster8(plain: impl AsRef<[Additive]>, faster8: impl AsRef<[Additive]>) { - let plain = plain.as_ref(); - let faster8 = faster8.as_ref(); + Vec::from_iter(rng.sample_iter::(dist).take(size).map(Additive)) + } - assert!(plain.eq(faster8)); - } + pub fn gen_faster8_from_plain(data: impl AsRef<[Additive]>) -> Vec { + let data = data.as_ref(); + data.to_vec() + } - #[cfg(all(target_feature = "avx", feature = "avx"))] - mod simd { - use super::*; - use super::super::*; - use rand::rngs::SmallRng; + #[cfg(all(target_feature = "avx", feature = "avx"))] + pub fn gen_faster8>(size: usize) -> Vec { + let data = gen_plain::(size); + gen_faster8_from_plain(data) + } #[cfg(all(target_feature = "avx", feature = "avx"))] + pub fn assert_plain_eq_faster8(plain: impl AsRef<[Additive]>, faster8: impl AsRef<[Additive]>) { + let plain = plain.as_ref(); + let faster8 = faster8.as_ref(); + + assert!(plain.eq(faster8)); + } + #[test] fn afft_output_plain_eq_faster8_size_16() { let index = 0; @@ -533,7 +527,6 @@ mod afft_tests { assert_plain_eq_faster8(data_plain, data_faster8); } - #[cfg(all(target_feature = "avx", feature = "avx"))] #[test] fn afft_output_plain_eq_faster8_size_32() { let index = 0; @@ -554,7 +547,6 @@ mod afft_tests { assert_plain_eq_faster8(data_plain, data_faster8); } - #[cfg(all(target_feature = "avx", feature = "avx"))] #[test] fn afft_output_plain_eq_faster8_impulse_data() { let index = 0; @@ -580,7 +572,6 @@ mod afft_tests { assert_plain_eq_faster8(data_plain, data_faster8); } - #[cfg(all(target_feature = "avx", feature = "avx"))] #[test] fn inverse_afft_output_plain_eq_faster8_size_8() { let index = 0; @@ -603,7 +594,6 @@ mod afft_tests { assert_plain_eq_faster8(data_plain, data_faster8); } - #[cfg(all(target_feature = "avx", feature = "avx"))] #[test] fn inverse_afft_output_plain_eq_faster8_size_32() { let index = 0;