From 195cc60e02cce1c273e4548a4c20686c17b0ad80 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 13 Nov 2024 12:52:49 +0100 Subject: [PATCH 1/2] poly: small refac for GeneralEvaluationDomain --- poly/src/domain/general.rs | 56 +++++++++++++++----------------------- poly/src/lib.rs | 2 +- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/poly/src/domain/general.rs b/poly/src/domain/general.rs index d09f05b25..156aa7e47 100644 --- a/poly/src/domain/general.rs +++ b/poly/src/domain/general.rs @@ -69,31 +69,27 @@ impl CanonicalSerialize for GeneralEvaluationDomain { compress: Compress, ) -> Result<(), SerializationError> { let variant = match self { - GeneralEvaluationDomain::Radix2(_) => 0u8, - GeneralEvaluationDomain::MixedRadix(_) => 1u8, + Self::Radix2(_) => 0u8, + Self::MixedRadix(_) => 1u8, }; variant.serialize_with_mode(&mut writer, compress)?; match self { - GeneralEvaluationDomain::Radix2(domain) => { - domain.serialize_with_mode(&mut writer, compress) - }, - GeneralEvaluationDomain::MixedRadix(domain) => { - domain.serialize_with_mode(&mut writer, compress) - }, + Self::Radix2(domain) => domain.serialize_with_mode(&mut writer, compress), + Self::MixedRadix(domain) => domain.serialize_with_mode(&mut writer, compress), } } fn serialized_size(&self, compress: Compress) -> usize { let type_id = match self { - GeneralEvaluationDomain::Radix2(_) => 0u8, - GeneralEvaluationDomain::MixedRadix(_) => 1u8, + Self::Radix2(_) => 0u8, + Self::MixedRadix(_) => 1u8, }; type_id.serialized_size(compress) + match self { - GeneralEvaluationDomain::Radix2(domain) => domain.serialized_size(compress), - GeneralEvaluationDomain::MixedRadix(domain) => domain.serialized_size(compress), + Self::Radix2(domain) => domain.serialized_size(compress), + Self::MixedRadix(domain) => domain.serialized_size(compress), } } } @@ -130,18 +126,14 @@ impl EvaluationDomain for GeneralEvaluationDomain { /// the radix-2 FFT cannot be constructed, this method tries /// constructing a mixed-radix FFT instead. fn new(num_coeffs: usize) -> Option { - let domain = Radix2EvaluationDomain::new(num_coeffs); - if let Some(domain) = domain { - return Some(GeneralEvaluationDomain::Radix2(domain)); - } - - if F::SMALL_SUBGROUP_BASE.is_some() { - return Some(GeneralEvaluationDomain::MixedRadix( - MixedRadixEvaluationDomain::new(num_coeffs)?, - )); - } - - None + Radix2EvaluationDomain::new(num_coeffs) + .map(Self::Radix2) + .or_else(|| { + F::SMALL_SUBGROUP_BASE + .is_some() + .then(|| MixedRadixEvaluationDomain::new(num_coeffs).map(Self::MixedRadix)) + .flatten() + }) } fn get_coset(&self, offset: F) -> Option { @@ -152,16 +144,12 @@ impl EvaluationDomain for GeneralEvaluationDomain { } fn compute_size_of_domain(num_coeffs: usize) -> Option { - let domain_size = Radix2EvaluationDomain::::compute_size_of_domain(num_coeffs); - if let Some(domain_size) = domain_size { - return Some(domain_size); - } - - if F::SMALL_SUBGROUP_BASE.is_some() { - return MixedRadixEvaluationDomain::::compute_size_of_domain(num_coeffs); - } - - None + Radix2EvaluationDomain::::compute_size_of_domain(num_coeffs).or_else(|| { + F::SMALL_SUBGROUP_BASE + .is_some() + .then(|| MixedRadixEvaluationDomain::::compute_size_of_domain(num_coeffs)) + .flatten() + }) } #[inline] diff --git a/poly/src/lib.rs b/poly/src/lib.rs index 327134689..236455ac1 100644 --- a/poly/src/lib.rs +++ b/poly/src/lib.rs @@ -1,6 +1,6 @@ //! This crate implements functions for manipulating polynomials over finite //! fields, including FFTs. -#![cfg_attr(not(feature = "std"), no_std)] +// #![cfg_attr(not(feature = "std"), no_std)] #![warn( unused, future_incompatible, From c593ab14b5840a3118f363a090fe18bd04c09937 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:53:43 +0100 Subject: [PATCH 2/2] Update poly/src/lib.rs --- poly/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poly/src/lib.rs b/poly/src/lib.rs index 236455ac1..327134689 100644 --- a/poly/src/lib.rs +++ b/poly/src/lib.rs @@ -1,6 +1,6 @@ //! This crate implements functions for manipulating polynomials over finite //! fields, including FFTs. -// #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), no_std)] #![warn( unused, future_incompatible,