From edd468db870969a836dde41b2e80bc627cf68d33 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 13 Nov 2024 23:33:22 +0100 Subject: [PATCH] rm generics when useless --- ec/src/models/mnt4/g2.rs | 8 ++--- ec/src/models/mnt4/mod.rs | 2 +- ec/src/models/mnt6/g2.rs | 8 ++--- ec/src/models/mnt6/mod.rs | 2 +- ec/src/models/short_weierstrass/group.rs | 3 +- ec/src/models/short_weierstrass/mod.rs | 4 +-- ec/src/models/twisted_edwards/group.rs | 3 +- ec/src/models/twisted_edwards/mod.rs | 6 ++-- ec/src/scalar_mul/glv.rs | 4 +-- ec/src/scalar_mul/mod.rs | 4 +-- .../variable_base/stream_pippenger.rs | 2 +- ff-asm/src/lib.rs | 4 +-- ff-macros/src/lib.rs | 2 +- ff-macros/src/montgomery/sum_of_products.rs | 2 +- ff-macros/src/utils.rs | 2 +- ff/src/biginteger/mod.rs | 13 ++++--- ff/src/fields/field_hashers/mod.rs | 2 +- ff/src/fields/mod.rs | 4 +-- ff/src/fields/models/cubic_extension.rs | 4 +-- ff/src/fields/models/fp/mod.rs | 2 +- ff/src/fields/models/fp/montgomery_backend.rs | 9 +++-- ff/src/fields/models/quadratic_extension.rs | 4 +-- poly/benches/dense_multilinear.rs | 10 +++--- poly/benches/dense_uv_polynomial.rs | 14 ++++---- poly/benches/fft.rs | 32 ++++++----------- poly/benches/sparse_multilinear.rs | 35 ++++++------------- poly/src/domain/general.rs | 6 ++-- poly/src/domain/radix2/mod.rs | 30 ++++++++-------- 28 files changed, 96 insertions(+), 125 deletions(-) diff --git a/ec/src/models/mnt4/g2.rs b/ec/src/models/mnt4/g2.rs index 3d0835fff..22e93a2cc 100644 --- a/ec/src/models/mnt4/g2.rs +++ b/ec/src/models/mnt4/g2.rs @@ -54,13 +54,13 @@ impl From> for G2Prepared

{ let neg_g = g.neg(); for bit in P::ATE_LOOP_COUNT.iter().skip(1) { - let (r2, coeff) = MNT4::

::doubling_for_flipped_miller_loop(&r); + let (r2, coeff) = MNT4::doubling_for_flipped_miller_loop(&r); g_prep.double_coefficients.push(coeff); r = r2; let (r_temp, add_coeff) = match bit { - 1 => MNT4::

::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r), - -1 => MNT4::

::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r), + 1 => MNT4::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r), + -1 => MNT4::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r), 0 => continue, _ => unreachable!(), }; @@ -76,7 +76,7 @@ impl From> for G2Prepared

{ let minus_r_affine_x = r.x * &rz2_inv; let minus_r_affine_y = -r.y * &rz3_inv; - let add_result = MNT4::

::mixed_addition_for_flipped_miller_loop( + let add_result = MNT4::mixed_addition_for_flipped_miller_loop( &minus_r_affine_x, &minus_r_affine_y, &r, diff --git a/ec/src/models/mnt4/mod.rs b/ec/src/models/mnt4/mod.rs index 0b077286a..2ebf3085a 100644 --- a/ec/src/models/mnt4/mod.rs +++ b/ec/src/models/mnt4/mod.rs @@ -54,7 +54,7 @@ pub trait MNT4Config: 'static + Sized { .map(|(a, b)| (a.into(), b.into())) .collect::>(); let result = ark_std::cfg_into_iter!(pairs) - .map(|(a, b)| MNT4::::ate_miller_loop(&a, &b)) + .map(|(a, b)| MNT4::ate_miller_loop(&a, &b)) .product(); MillerLoopOutput(result) } diff --git a/ec/src/models/mnt6/g2.rs b/ec/src/models/mnt6/g2.rs index 7476aba4d..f3bad5990 100644 --- a/ec/src/models/mnt6/g2.rs +++ b/ec/src/models/mnt6/g2.rs @@ -52,13 +52,13 @@ impl From> for G2Prepared

{ let neg_g = g.neg(); for bit in P::ATE_LOOP_COUNT.iter().skip(1) { - let (r2, coeff) = MNT6::

::doubling_for_flipped_miller_loop(&r); + let (r2, coeff) = MNT6::doubling_for_flipped_miller_loop(&r); g_prep.double_coefficients.push(coeff); r = r2; let (r_temp, add_coeff) = match bit { - 1 => MNT6::

::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r), - -1 => MNT6::

::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r), + 1 => MNT6::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r), + -1 => MNT6::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r), 0 => continue, _ => unreachable!(), }; @@ -75,7 +75,7 @@ impl From> for G2Prepared

{ let minus_r_y = -r.y * &rz3_inv; let add_result = - MNT6::

::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r); + MNT6::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r); g_prep.addition_coefficients.push(add_result.1); } diff --git a/ec/src/models/mnt6/mod.rs b/ec/src/models/mnt6/mod.rs index 233c6d9de..14ce47999 100644 --- a/ec/src/models/mnt6/mod.rs +++ b/ec/src/models/mnt6/mod.rs @@ -55,7 +55,7 @@ pub trait MNT6Config: 'static + Sized { .map(|(a, b)| (a.into(), b.into())) .collect::>(); let result = ark_std::cfg_into_iter!(pairs) - .map(|(a, b)| MNT6::::ate_miller_loop(&a, &b)) + .map(|(a, b)| MNT6::ate_miller_loop(&a, &b)) .product(); MillerLoopOutput(result) } diff --git a/ec/src/models/short_weierstrass/group.rs b/ec/src/models/short_weierstrass/group.rs index 3e515abad..2835816ac 100644 --- a/ec/src/models/short_weierstrass/group.rs +++ b/ec/src/models/short_weierstrass/group.rs @@ -589,8 +589,7 @@ impl CanonicalSerialize for Projective

{ writer: W, compress: Compress, ) -> Result<(), SerializationError> { - let aff = Affine::

::from(*self); - P::serialize_with_mode(&aff, writer, compress) + P::serialize_with_mode(&(*self).into(), writer, compress) } #[inline] diff --git a/ec/src/models/short_weierstrass/mod.rs b/ec/src/models/short_weierstrass/mod.rs index 515c4721b..a7604c0cb 100644 --- a/ec/src/models/short_weierstrass/mod.rs +++ b/ec/src/models/short_weierstrass/mod.rs @@ -172,9 +172,9 @@ pub trait SWCurveConfig: super::CurveConfig { }, }; if flags.is_infinity() { - Ok(Affine::::identity()) + Ok(Affine::identity()) } else { - let point = Affine::::new_unchecked(x, y); + let point = Affine::new_unchecked(x, y); if let Validate::Yes = validate { point.check()?; } diff --git a/ec/src/models/twisted_edwards/group.rs b/ec/src/models/twisted_edwards/group.rs index 958985f98..c0d3693d3 100644 --- a/ec/src/models/twisted_edwards/group.rs +++ b/ec/src/models/twisted_edwards/group.rs @@ -430,8 +430,7 @@ impl CanonicalSerialize for Projective

{ writer: W, compress: Compress, ) -> Result<(), SerializationError> { - let aff = Affine::

::from(*self); - P::serialize_with_mode(&aff, writer, compress) + P::serialize_with_mode(&(*self).into(), writer, compress) } #[inline] diff --git a/ec/src/models/twisted_edwards/mod.rs b/ec/src/models/twisted_edwards/mod.rs index 6d326b3a2..9326e2255 100644 --- a/ec/src/models/twisted_edwards/mod.rs +++ b/ec/src/models/twisted_edwards/mod.rs @@ -60,7 +60,7 @@ pub trait TECurveConfig: super::CurveConfig { /// Default implementation of group multiplication for projective /// coordinates fn mul_projective(base: &Projective, scalar: &[u64]) -> Projective { - let mut res = Projective::::zero(); + let mut res = Projective::zero(); for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) { res.double_in_place(); if b { @@ -74,7 +74,7 @@ pub trait TECurveConfig: super::CurveConfig { /// Default implementation of group multiplication for affine /// coordinates fn mul_affine(base: &Affine, scalar: &[u64]) -> Projective { - let mut res = Projective::::zero(); + let mut res = Projective::zero(); for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) { res.double_in_place(); if b { @@ -141,7 +141,7 @@ pub trait TECurveConfig: super::CurveConfig { (x, y) }, }; - let point = Affine::::new_unchecked(x, y); + let point = Affine::new_unchecked(x, y); if let Validate::Yes = validate { point.check()?; } diff --git a/ec/src/scalar_mul/glv.rs b/ec/src/scalar_mul/glv.rs index b3acfb1a8..2270b4250 100644 --- a/ec/src/scalar_mul/glv.rs +++ b/ec/src/scalar_mul/glv.rs @@ -105,7 +105,7 @@ pub trait GLVConfig: Send + Sync + 'static + SWCurveConfig { let iter_k1 = ark_ff::BitIteratorBE::new(k1.into_bigint()); let iter_k2 = ark_ff::BitIteratorBE::new(k2.into_bigint()); - let mut res = Projective::::zero(); + let mut res = Projective::zero(); let mut skip_zeros = true; for pair in iter_k1.zip(iter_k2) { if skip_zeros && pair == (false, false) { @@ -141,7 +141,7 @@ pub trait GLVConfig: Send + Sync + 'static + SWCurveConfig { let iter_k1 = ark_ff::BitIteratorBE::new(k1.into_bigint()); let iter_k2 = ark_ff::BitIteratorBE::new(k2.into_bigint()); - let mut res = Projective::::zero(); + let mut res = Projective::zero(); let mut skip_zeros = true; for pair in iter_k1.zip(iter_k2) { if skip_zeros && pair == (false, false) { diff --git a/ec/src/scalar_mul/mod.rs b/ec/src/scalar_mul/mod.rs index 19762d6ed..26be64348 100644 --- a/ec/src/scalar_mul/mod.rs +++ b/ec/src/scalar_mul/mod.rs @@ -32,7 +32,7 @@ pub fn sw_double_and_add_affine( base: &Affine

, scalar: impl AsRef<[u64]>, ) -> Projective

{ - let mut res = Projective::

::zero(); + let mut res = Projective::zero(); for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) { res.double_in_place(); if b { @@ -49,7 +49,7 @@ pub fn sw_double_and_add_projective( base: &Projective

, scalar: impl AsRef<[u64]>, ) -> Projective

{ - let mut res = Projective::

::zero(); + let mut res = Projective::zero(); for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) { res.double_in_place(); if b { diff --git a/ec/src/scalar_mul/variable_base/stream_pippenger.rs b/ec/src/scalar_mul/variable_base/stream_pippenger.rs index cb5fe4269..79f121dba 100644 --- a/ec/src/scalar_mul/variable_base/stream_pippenger.rs +++ b/ec/src/scalar_mul/variable_base/stream_pippenger.rs @@ -78,7 +78,7 @@ impl HashMapPippenger { Self { buffer: HashMap::with_capacity_and_hasher( max_msm_buffer, - core::hash::BuildHasherDefault::::default(), + core::hash::BuildHasherDefault::default(), ), result: G::zero(), buf_size: max_msm_buffer, diff --git a/ff-asm/src/lib.rs b/ff-asm/src/lib.rs index 1833af026..05e5d8ed1 100644 --- a/ff-asm/src/lib.rs +++ b/ff-asm/src/lib.rs @@ -55,7 +55,7 @@ pub fn x86_64_asm_mul(input: TokenStream) -> TokenStream { .. }) = &*num_limbs { - lit_int.base10_parse::().unwrap() + lit_int.base10_parse().unwrap() } else { panic!("The number of limbs must be a literal"); }; @@ -106,7 +106,7 @@ pub fn x86_64_asm_square(input: TokenStream) -> TokenStream { .. }) = &*num_limbs { - lit_int.base10_parse::().unwrap() + lit_int.base10_parse().unwrap() } else { panic!("The number of limbs must be a literal"); }; diff --git a/ff-macros/src/lib.rs b/ff-macros/src/lib.rs index 724bd4e45..7a9e3d662 100644 --- a/ff-macros/src/lib.rs +++ b/ff-macros/src/lib.rs @@ -79,7 +79,7 @@ const ARG_MSG: &str = "Failed to parse unroll threshold; must be a positive inte /// Attribute used to unroll for loops found inside a function block. #[proc_macro_attribute] pub fn unroll_for_loops(args: TokenStream, input: TokenStream) -> TokenStream { - let unroll_by = match syn::parse2::(args.into()).expect(ARG_MSG) { + let unroll_by = match syn::parse2(args.into()).expect(ARG_MSG) { Lit::Int(int) => int.base10_parse().expect(ARG_MSG), _ => panic!("{}", ARG_MSG), }; diff --git a/ff-macros/src/montgomery/sum_of_products.rs b/ff-macros/src/montgomery/sum_of_products.rs index 57b992e7a..fbbd403e3 100644 --- a/ff-macros/src/montgomery/sum_of_products.rs +++ b/ff-macros/src/montgomery/sum_of_products.rs @@ -66,7 +66,7 @@ pub(super) fn sum_of_products_impl(num_limbs: usize, modulus: &[u64]) -> proc_ma let mut result = F::new_unchecked(result); __subtract_modulus(&mut result); debug_assert_eq!( - a.iter().zip(b).map(|(a, b)| *a * b).sum::(), + a.iter().zip(b).map(|(a, b)| *a * b).sum(), result ); result diff --git a/ff-macros/src/utils.rs b/ff-macros/src/utils.rs index 055fbf79f..ddb6f2c2b 100644 --- a/ff-macros/src/utils.rs +++ b/ff-macros/src/utils.rs @@ -55,7 +55,7 @@ pub fn str_to_limbs_u64(num: &str) -> (bool, Vec) { } this }) - .collect::>(); + .collect(); let sign_is_positive = sign != Sign::Minus; (sign_is_positive, limbs) diff --git a/ff/src/biginteger/mod.rs b/ff/src/biginteger/mod.rs index f131eaf37..6d6409ad5 100644 --- a/ff/src/biginteger/mod.rs +++ b/ff/src/biginteger/mod.rs @@ -64,7 +64,7 @@ impl CanonicalDeserialize for BigInt { compress: Compress, validate: Validate, ) -> Result { - Ok(BigInt::(<[u64; N]>::deserialize_with_mode( + Ok(BigInt(<[u64; N]>::deserialize_with_mode( reader, compress, validate, )?)) } @@ -278,15 +278,14 @@ impl BigInt { /// Computes the Montgomery R constant modulo `self`. #[doc(hidden)] pub const fn montgomery_r(&self) -> Self { - let two_pow_n_times_64 = crate::const_helpers::RBuffer::([0u64; N], 1); + let two_pow_n_times_64 = crate::const_helpers::RBuffer([0u64; N], 1); const_modulo!(two_pow_n_times_64, self) } /// Computes the Montgomery R2 constant modulo `self`. #[doc(hidden)] pub const fn montgomery_r2(&self) -> Self { - let two_pow_n_times_64_square = - crate::const_helpers::R2Buffer::([0u64; N], [0u64; N], 1); + let two_pow_n_times_64_square = crate::const_helpers::R2Buffer([0u64; N], [0u64; N], 1); const_modulo!(two_pow_n_times_64_square, self) } } @@ -385,7 +384,7 @@ impl BigInteger for BigInt { return (zero, zero); } - let mut r = crate::const_helpers::MulBuffer::::zeroed(); + let mut r = crate::const_helpers::MulBuffer::zeroed(); let mut carry = 0; @@ -595,7 +594,7 @@ impl Distribution> for Standard { for item in res.iter_mut() { *item = rng.gen(); } - BigInt::(res) + BigInt(res) } } @@ -1241,7 +1240,7 @@ pub trait BigInteger: /// assert_eq!(arr, vec); /// ``` fn to_bits_be(&self) -> Vec { - BitIteratorBE::new(self).collect::>() + BitIteratorBE::new(self).collect() } /// Returns the bit representation in a little endian boolean array, diff --git a/ff/src/fields/field_hashers/mod.rs b/ff/src/fields/field_hashers/mod.rs index f8bd0b26b..b4f7170e1 100644 --- a/ff/src/fields/field_hashers/mod.rs +++ b/ff/src/fields/field_hashers/mod.rs @@ -80,7 +80,7 @@ impl Ha }; F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap() }; - ark_std::array::from_fn::(cb) + ark_std::array::from_fn(cb) } } diff --git a/ff/src/fields/mod.rs b/ff/src/fields/mod.rs index c076c4335..33807bdcf 100644 --- a/ff/src/fields/mod.rs +++ b/ff/src/fields/mod.rs @@ -450,7 +450,7 @@ mod no_std_tests { #[test] fn test_batch_inversion() { - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); let vec_size = 1000; for _ in 0..=vec_size { @@ -458,7 +458,7 @@ mod no_std_tests { } let mut random_coeffs_inv = random_coeffs.clone(); - batch_inversion::(&mut random_coeffs_inv); + batch_inversion(&mut random_coeffs_inv); for i in 0..=vec_size { assert_eq!(random_coeffs_inv[i] * random_coeffs[i], Fr::one()); } diff --git a/ff/src/fields/models/cubic_extension.rs b/ff/src/fields/models/cubic_extension.rs index 1049908bf..0aa386061 100644 --- a/ff/src/fields/models/cubic_extension.rs +++ b/ff/src/fields/models/cubic_extension.rs @@ -729,7 +729,7 @@ mod cube_ext_tests { if d == ext_degree { continue; } - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..d { random_coeffs.push(Fq::rand(&mut test_rng())); } @@ -740,7 +740,7 @@ mod cube_ext_tests { // We test consistency against Fq2::new let number_of_tests = 10; for _ in 0..number_of_tests { - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..ext_degree { random_coeffs.push(Fq::rand(&mut test_rng())); } diff --git a/ff/src/fields/models/fp/mod.rs b/ff/src/fields/models/fp/mod.rs index 25fa86a9d..94f2f19a5 100644 --- a/ff/src/fields/models/fp/mod.rs +++ b/ff/src/fields/models/fp/mod.rs @@ -992,7 +992,7 @@ impl, const N: usize> zeroize::Zeroize for Fp { impl, const N: usize> From for Fp { #[inline] fn from(val: num_bigint::BigUint) -> Fp { - Fp::::from_le_bytes_mod_order(&val.to_bytes_le()) + Fp::from_le_bytes_mod_order(&val.to_bytes_le()) } } diff --git a/ff/src/fields/models/fp/montgomery_backend.rs b/ff/src/fields/models/fp/montgomery_backend.rs index 04114f482..7289997a8 100644 --- a/ff/src/fields/models/fp/montgomery_backend.rs +++ b/ff/src/fields/models/fp/montgomery_backend.rs @@ -75,15 +75,14 @@ pub trait MontConfig: 'static + Sync + Send + Sized { /// Precomputed material for use when computing square roots. /// The default is to use the standard Tonelli-Shanks algorithm. const SQRT_PRECOMP: Option, N>>> = - sqrt_precomputation::(); + sqrt_precomputation(); /// (MODULUS + 1) / 4 when MODULUS % 4 == 3. Used for square root precomputations. #[doc(hidden)] const MODULUS_PLUS_ONE_DIV_FOUR: Option> = { match Self::MODULUS.mod_4() == 3 { true => { - let (modulus_plus_one, carry) = - Self::MODULUS.const_add_with_carry(&BigInt::::one()); + let (modulus_plus_one, carry) = Self::MODULUS.const_add_with_carry(&BigInt::one()); let mut result = modulus_plus_one.divide_by_2_round_down(); // Since modulus_plus_one is even, dividing by 2 results in a MSB of 0. // Thus we can set MSB to `carry` to get the correct result of (MODULUS + 1) // 2: @@ -727,7 +726,7 @@ impl, const N: usize> Fp, N> { /// of this method #[doc(hidden)] pub const fn from_sign_and_limbs(is_positive: bool, limbs: &[u64]) -> Self { - let mut repr = BigInt::([0; N]); + let mut repr = BigInt([0; N]); assert!(limbs.len() <= N); crate::const_for!((i in 0..(limbs.len())) { repr.0[i] = limbs[i]; @@ -853,7 +852,7 @@ mod test { } this }) - .collect::>(); + .collect(); let sign_is_positive = sign != Sign::Minus; (sign_is_positive, limbs) diff --git a/ff/src/fields/models/quadratic_extension.rs b/ff/src/fields/models/quadratic_extension.rs index 4ebbb5a62..033cfd57b 100644 --- a/ff/src/fields/models/quadratic_extension.rs +++ b/ff/src/fields/models/quadratic_extension.rs @@ -788,7 +788,7 @@ mod quad_ext_tests { if d == ext_degree { continue; } - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..d { random_coeffs.push(Fq::rand(&mut test_rng())); } @@ -799,7 +799,7 @@ mod quad_ext_tests { // We test consistency against Fq2::new let number_of_tests = 10; for _ in 0..number_of_tests { - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..ext_degree { random_coeffs.push(Fq::rand(&mut test_rng())); } diff --git a/poly/benches/dense_multilinear.rs b/poly/benches/dense_multilinear.rs index fbc0f6c4b..62c8d01f8 100644 --- a/poly/benches/dense_multilinear.rs +++ b/poly/benches/dense_multilinear.rs @@ -15,8 +15,8 @@ fn arithmetic_op_bench(c: &mut Criterion) { let mut group = c.benchmark_group("DenseMultilinear::Add"); for nv in NUM_VARIABLES_RANGE { group.bench_with_input(BenchmarkId::from_parameter(nv), &nv, |b, &nv| { - let poly1 = DenseMultilinearExtension::::rand(nv, &mut rng); - let poly2 = DenseMultilinearExtension::::rand(nv, &mut rng); + let poly1 = DenseMultilinearExtension::rand(nv, &mut rng); + let poly2 = DenseMultilinearExtension::rand(nv, &mut rng); b.iter(|| black_box(&poly1 + &poly2)) }); } @@ -25,8 +25,8 @@ fn arithmetic_op_bench(c: &mut Criterion) { let mut group = c.benchmark_group("DenseMultilinear::Sub"); for nv in NUM_VARIABLES_RANGE { group.bench_with_input(BenchmarkId::from_parameter(nv), &nv, |b, &nv| { - let poly1 = DenseMultilinearExtension::::rand(nv, &mut rng); - let poly2 = DenseMultilinearExtension::::rand(nv, &mut rng); + let poly1 = DenseMultilinearExtension::rand(nv, &mut rng); + let poly2 = DenseMultilinearExtension::rand(nv, &mut rng); b.iter(|| black_box(&poly1 - &poly2)) }); } @@ -38,7 +38,7 @@ fn evaluation_op_bench(c: &mut Criterion) { let mut group = c.benchmark_group("DenseMultilinear::Evaluate"); for nv in NUM_VARIABLES_RANGE { group.bench_with_input(BenchmarkId::from_parameter(nv), &nv, |b, &nv| { - let poly = DenseMultilinearExtension::::rand(nv, &mut rng); + let poly = DenseMultilinearExtension::rand(nv, &mut rng); let point: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect(); b.iter(|| black_box(poly.evaluate(&point))) }); diff --git a/poly/benches/dense_uv_polynomial.rs b/poly/benches/dense_uv_polynomial.rs index c825bf8c8..2e283758d 100644 --- a/poly/benches/dense_uv_polynomial.rs +++ b/poly/benches/dense_uv_polynomial.rs @@ -48,7 +48,7 @@ fn bench_sparse_poly_evaluate(b: &mut Bencher, non_zero_entries: &usiz let mut inner: Vec<(usize, F)> = Vec::with_capacity(*non_zero_entries); (0..*non_zero_entries) .for_each(|_| inner.push((rng.gen_range(0..MAX_DEGREE), F::rand(&mut rng)))); - let poly = SparsePolynomial::::from_coefficients_vec(inner); + let poly = SparsePolynomial::from_coefficients_vec(inner); b.iter(|| { // Per benchmark iteration let pt = F::rand(&mut rng); @@ -59,7 +59,7 @@ fn bench_sparse_poly_evaluate(b: &mut Bencher, non_zero_entries: &usiz fn bench_poly_evaluate(b: &mut Bencher, degree: &usize) { // Per benchmark setup let mut rng = &mut ark_std::test_rng(); - let poly = DensePolynomial::::rand(*degree, &mut rng); + let poly = DensePolynomial::rand(*degree, &mut rng); b.iter(|| { // Per benchmark iteration let pt = F::rand(&mut rng); @@ -70,8 +70,8 @@ fn bench_poly_evaluate(b: &mut Bencher, degree: &usize) { fn bench_poly_add(b: &mut Bencher, degree: &usize) { // Per benchmark setup let mut rng = &mut ark_std::test_rng(); - let poly_one = DensePolynomial::::rand(*degree, &mut rng); - let poly_two = DensePolynomial::::rand(*degree, &mut rng); + let poly_one = DensePolynomial::rand(*degree, &mut rng); + let poly_two = DensePolynomial::rand(*degree, &mut rng); b.iter(|| { // Per benchmark iteration let _poly_three = &poly_one + &poly_two; @@ -81,8 +81,8 @@ fn bench_poly_add(b: &mut Bencher, degree: &usize) { fn bench_poly_add_assign(b: &mut Bencher, degree: &usize) { // Per benchmark setup let mut rng = &mut ark_std::test_rng(); - let mut poly_one = DensePolynomial::::rand(*degree, &mut rng); - let poly_two = DensePolynomial::::rand(*degree, &mut rng); + let mut poly_one = DensePolynomial::rand(*degree, &mut rng); + let poly_two = DensePolynomial::rand(*degree, &mut rng); b.iter(|| { // Per benchmark iteration poly_one += &poly_two; @@ -92,7 +92,7 @@ fn bench_poly_add_assign(b: &mut Bencher, degree: &usize) { fn bench_div_by_vanishing_poly(b: &mut Bencher, degree: &usize) { // Per benchmark setup let mut rng = &mut ark_std::test_rng(); - let p = DensePolynomial::::rand(*degree, &mut rng); + let p = DensePolynomial::rand(*degree, &mut rng); let domain = GeneralEvaluationDomain::new(BENCHMARK_MIN_DEGREE).unwrap(); b.iter(|| p.divide_by_vanishing_poly(domain)); diff --git a/poly/benches/fft.rs b/poly/benches/fft.rs index 47ccb0dbc..324c3b5c0 100644 --- a/poly/benches/fft.rs +++ b/poly/benches/fft.rs @@ -63,7 +63,7 @@ fn fft_setup_with_domain_size>( ) -> (D, Vec) { let mut rng = &mut ark_std::test_rng(); let domain = D::new(domain_size).unwrap(); - let a = DensePolynomial::::rand(degree - 1, &mut rng) + let a = DensePolynomial::rand(degree - 1, &mut rng) .coeffs() .to_vec(); (domain, a) @@ -71,7 +71,7 @@ fn fft_setup_with_domain_size>( fn bench_fft_in_place>(b: &mut Bencher, degree: &usize) { // Per benchmark setup - let (domain, mut a) = fft_setup::(*degree); + let (domain, mut a) = fft_setup(*degree); b.iter(|| { // Per benchmark iteration domain.fft_in_place(&mut a); @@ -83,7 +83,7 @@ fn bench_large_domain_fft_in_place>( degree: &usize, ) { // Per benchmark setup - let (domain, mut a) = fft_setup_with_domain_size::(*degree, degree << 2); + let (domain, mut a) = fft_setup_with_domain_size(*degree, degree << 2); b.iter(|| { // Per benchmark iteration domain.fft_in_place(&mut a); @@ -92,7 +92,7 @@ fn bench_large_domain_fft_in_place>( fn bench_ifft_in_place>(b: &mut Bencher, degree: &usize) { // Per benchmark setup - let (domain, mut a) = fft_setup::(*degree); + let (domain, mut a) = fft_setup(*degree); b.iter(|| { // Per benchmark iteration domain.ifft_in_place(&mut a); @@ -101,7 +101,7 @@ fn bench_ifft_in_place>(b: &mut Bencher, deg fn bench_coset_fft_in_place>(b: &mut Bencher, degree: &usize) { // Per benchmark setup - let (domain, mut a) = fft_setup::(*degree); + let (domain, mut a) = fft_setup(*degree); let coset_domain = domain.get_coset(F::GENERATOR).unwrap(); b.iter(|| { // Per benchmark iteration @@ -111,7 +111,7 @@ fn bench_coset_fft_in_place>(b: &mut Bencher fn bench_coset_ifft_in_place>(b: &mut Bencher, degree: &usize) { // Per benchmark setup - let (domain, mut a) = fft_setup::(*degree); + let (domain, mut a) = fft_setup(*degree); let coset_domain = domain.get_coset(F::GENERATOR).unwrap(); b.iter(|| { // Per benchmark iteration @@ -125,25 +125,15 @@ fn fft_benches>( size_range: &[usize], ) { let bench_name = format!("{name} - Subgroup FFT"); - setup_bench(c, &bench_name, bench_fft_in_place::, size_range); + setup_bench(c, &bench_name, bench_fft_in_place, size_range); let bench_name = format!("{name} - Subgroup FFT on larger domain"); - setup_bench( - c, - &bench_name, - bench_large_domain_fft_in_place::, - size_range, - ); + setup_bench(c, &bench_name, bench_large_domain_fft_in_place, size_range); let bench_name = format!("{name} - Subgroup IFFT"); - setup_bench(c, &bench_name, bench_ifft_in_place::, size_range); + setup_bench(c, &bench_name, bench_ifft_in_place, size_range); let bench_name = format!("{name} - Coset FFT"); - setup_bench(c, &bench_name, bench_coset_fft_in_place::, size_range); + setup_bench(c, &bench_name, bench_coset_fft_in_place, size_range); let bench_name = format!("{name} - Coset IFFT"); - setup_bench( - c, - &bench_name, - bench_coset_ifft_in_place::, - size_range, - ); + setup_bench(c, &bench_name, bench_coset_ifft_in_place, size_range); } fn bench_bls12_381(c: &mut Criterion) { diff --git a/poly/benches/sparse_multilinear.rs b/poly/benches/sparse_multilinear.rs index 68c2d60a2..151f2055d 100644 --- a/poly/benches/sparse_multilinear.rs +++ b/poly/benches/sparse_multilinear.rs @@ -19,16 +19,10 @@ fn arithmetic_op_bench(c: &mut Criterion) { BenchmarkId::new(format!("Add with num_vars = {nv}"), num_nonzero_entries), &num_nonzero_entries, |b, &num_nonzero_entries| { - let poly1 = SparseMultilinearExtension::::rand_with_config( - nv, - num_nonzero_entries, - &mut rng, - ); - let poly2 = SparseMultilinearExtension::::rand_with_config( - nv, - num_nonzero_entries, - &mut rng, - ); + let poly1 = + SparseMultilinearExtension::rand_with_config(nv, num_nonzero_entries, &mut rng); + let poly2 = + SparseMultilinearExtension::rand_with_config(nv, num_nonzero_entries, &mut rng); b.iter(|| black_box(&poly1 + &poly2)) }, ); @@ -40,16 +34,10 @@ fn arithmetic_op_bench(c: &mut Criterion) { BenchmarkId::new(format!("Sub with num_vars = {nv}"), num_nonzero_entries), &num_nonzero_entries, |b, &num_nonzero_entries| { - let poly1 = SparseMultilinearExtension::::rand_with_config( - nv, - num_nonzero_entries, - &mut rng, - ); - let poly2 = SparseMultilinearExtension::::rand_with_config( - nv, - num_nonzero_entries, - &mut rng, - ); + let poly1 = + SparseMultilinearExtension::rand_with_config(nv, num_nonzero_entries, &mut rng); + let poly2 = + SparseMultilinearExtension::rand_with_config(nv, num_nonzero_entries, &mut rng); b.iter(|| black_box(&poly1 - &poly2)) }, ); @@ -66,11 +54,8 @@ fn evaluation_op_bench(c: &mut Criterion) { BenchmarkId::new(format!("Eval with num_vars = {nv}"), num_nonzero_entries), &num_nonzero_entries, |b, &num_nonzero_entries| { - let poly = SparseMultilinearExtension::::rand_with_config( - nv, - num_nonzero_entries, - &mut rng, - ); + let poly = + SparseMultilinearExtension::rand_with_config(nv, num_nonzero_entries, &mut rng); let point: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect(); b.iter(|| black_box(poly.evaluate(&point))) }, diff --git a/poly/src/domain/general.rs b/poly/src/domain/general.rs index d09f05b25..b2f083ae2 100644 --- a/poly/src/domain/general.rs +++ b/poly/src/domain/general.rs @@ -257,7 +257,7 @@ mod tests { fn vanishing_polynomial_evaluation() { let rng = &mut test_rng(); for coeffs in 0..10 { - let domain = GeneralEvaluationDomain::::new(coeffs).unwrap(); + let domain = GeneralEvaluationDomain::new(coeffs).unwrap(); let z = domain.vanishing_polynomial(); for _ in 0..100 { let point = rng.gen(); @@ -269,7 +269,7 @@ mod tests { } for coeffs in 15..17 { - let domain = GeneralEvaluationDomain::::new(coeffs).unwrap(); + let domain = GeneralEvaluationDomain::new(coeffs).unwrap(); let z = domain.vanishing_polynomial(); for _ in 0..100 { let point = rng.gen(); @@ -284,7 +284,7 @@ mod tests { #[test] fn vanishing_polynomial_vanishes_on_domain() { for coeffs in 0..1000 { - let domain = GeneralEvaluationDomain::::new(coeffs).unwrap(); + let domain = GeneralEvaluationDomain::new(coeffs).unwrap(); let z = domain.vanishing_polynomial(); for point in domain.elements() { assert!(z.evaluate(&point).is_zero()) diff --git a/poly/src/domain/radix2/mod.rs b/poly/src/domain/radix2/mod.rs index 9e03fcafc..cbc82418f 100644 --- a/poly/src/domain/radix2/mod.rs +++ b/poly/src/domain/radix2/mod.rs @@ -185,7 +185,7 @@ mod tests { fn vanishing_polynomial_evaluation() { let rng = &mut test_rng(); for coeffs in 0..10 { - let domain = Radix2EvaluationDomain::::new(coeffs).unwrap(); + let domain = Radix2EvaluationDomain::new(coeffs).unwrap(); let coset_domain = domain.get_coset(Fr::GENERATOR).unwrap(); let z = domain.vanishing_polynomial(); let z_coset = coset_domain.vanishing_polynomial(); @@ -206,7 +206,7 @@ mod tests { #[test] fn vanishing_polynomial_vanishes_on_domain() { for coeffs in 0..1000 { - let domain = Radix2EvaluationDomain::::new(coeffs).unwrap(); + let domain = Radix2EvaluationDomain::new(coeffs).unwrap(); let z = domain.vanishing_polynomial(); for point in domain.elements() { assert!(z.evaluate(&point).is_zero()) @@ -224,10 +224,10 @@ mod tests { fn filter_polynomial_test() { for log_domain_size in 1..=4 { let domain_size = 1 << log_domain_size; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); for log_subdomain_size in 1..=log_domain_size { let subdomain_size = 1 << log_subdomain_size; - let subdomain = Radix2EvaluationDomain::::new(subdomain_size).unwrap(); + let subdomain = Radix2EvaluationDomain::new(subdomain_size).unwrap(); // Obtain all possible offsets of `subdomain` within `domain`. let mut possible_offsets = vec![Fr::one()]; @@ -269,7 +269,7 @@ mod tests { fn size_of_elements() { for coeffs in 1..10 { let size = 1 << coeffs; - let domain = Radix2EvaluationDomain::::new(size).unwrap(); + let domain = Radix2EvaluationDomain::new(size).unwrap(); let domain_size = domain.size(); assert_eq!(domain_size, domain.elements().count()); } @@ -279,7 +279,7 @@ mod tests { fn elements_contents() { for coeffs in 1..10 { let size = 1 << coeffs; - let domain = Radix2EvaluationDomain::::new(size).unwrap(); + let domain = Radix2EvaluationDomain::new(size).unwrap(); let offset = Fr::GENERATOR; let coset_domain = domain.get_coset(offset).unwrap(); for (i, (x, coset_x)) in domain.elements().zip(coset_domain.elements()).enumerate() { @@ -297,7 +297,7 @@ mod tests { fn non_systematic_lagrange_coefficients_test() { for domain_dim in 1..10 { let domain_size = 1 << domain_dim; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); let coset_domain = domain.get_coset(Fr::GENERATOR).unwrap(); // Get random pt + lagrange coefficients let rand_pt = Fr::rand(&mut test_rng()); @@ -306,7 +306,7 @@ mod tests { // Sample the random polynomial, evaluate it over the domain and the random // point. - let rand_poly = DensePolynomial::::rand(domain_size - 1, &mut test_rng()); + let rand_poly = DensePolynomial::rand(domain_size - 1, &mut test_rng()); let poly_evals = domain.fft(rand_poly.coeffs()); let coset_poly_evals = coset_domain.fft(rand_poly.coeffs()); let actual_eval = rand_poly.evaluate(&rand_pt); @@ -330,7 +330,7 @@ mod tests { // low. We generate lagrange coefficients for each element in the domain. for domain_dim in 1..5 { let domain_size = 1 << domain_dim; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); let coset_domain = domain.get_coset(Fr::GENERATOR).unwrap(); for (i, (x, coset_x)) in domain.elements().zip(coset_domain.elements()).enumerate() { let lagrange_coeffs = domain.evaluate_all_lagrange_coefficients(x); @@ -364,13 +364,13 @@ mod tests { // Runs in time O(degree^2) let log_degree = 5; let degree = 1 << log_degree; - let rand_poly = DensePolynomial::::rand(degree - 1, &mut test_rng()); + let rand_poly = DensePolynomial::rand(degree - 1, &mut test_rng()); for log_domain_size in log_degree..(log_degree + 2) { let domain_size = 1 << log_domain_size; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); let coset_domain = - Radix2EvaluationDomain::::new_coset(domain_size, Fr::GENERATOR).unwrap(); + Radix2EvaluationDomain::new_coset(domain_size, Fr::GENERATOR).unwrap(); let poly_evals = domain.fft(&rand_poly.coeffs); let poly_coset_evals = coset_domain.fft(&rand_poly.coeffs); @@ -401,9 +401,9 @@ mod tests { fn degree_aware_fft_correctness() { // Test that the degree aware FFT (O(n log d)) matches the regular FFT (O(n log n)). let num_coeffs = 1 << 5; - let rand_poly = DensePolynomial::::rand(num_coeffs - 1, &mut test_rng()); + let rand_poly = DensePolynomial::rand(num_coeffs - 1, &mut test_rng()); let domain_size = num_coeffs * DEGREE_AWARE_FFT_THRESHOLD_FACTOR; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); let coset_domain = domain.get_coset(Fr::GENERATOR).unwrap(); let deg_aware_fft_evals = domain.fft(&rand_poly); @@ -421,7 +421,7 @@ mod tests { let max_degree = 10; for log_domain_size in 0..max_degree { let domain_size = 1 << log_domain_size; - let domain = Radix2EvaluationDomain::::new(domain_size).unwrap(); + let domain = Radix2EvaluationDomain::new(domain_size).unwrap(); let actual_roots = domain.roots_of_unity(domain.group_gen); for &value in &actual_roots { assert!(domain.evaluate_vanishing_polynomial(value).is_zero());