From 705507246451a3c63b480c761bb702413fcb1a1a Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Fri, 4 Oct 2024 16:03:59 +0200 Subject: [PATCH] PolyComm: implement iterator to abstract access to field --- poly-commitment/src/commitment.rs | 9 +++++++++ poly-commitment/src/ipa.rs | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/poly-commitment/src/commitment.rs b/poly-commitment/src/commitment.rs index 941499d391..d2f2fda5dd 100644 --- a/poly-commitment/src/commitment.rs +++ b/poly-commitment/src/commitment.rs @@ -84,6 +84,15 @@ where } } +impl<'a, G> IntoIterator for &'a PolyComm { + type Item = &'a G; + type IntoIter = std::slice::Iter<'a, G>; + + fn into_iter(self) -> Self::IntoIter { + self.chunks.iter() + } +} + /// A commitment to a polynomial with some blinding factors. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct BlindedCommitment diff --git a/poly-commitment/src/ipa.rs b/poly-commitment/src/ipa.rs index e5695d7858..cf8274f3ae 100644 --- a/poly-commitment/src/ipa.rs +++ b/poly-commitment/src/ipa.rs @@ -162,8 +162,8 @@ pub fn combine_polys>( .for_each(|(i, x)| { *x += scale * evals[i * stride]; }); - for j in 0..omegas.len() { - omega += &(omegas.chunks[j] * scale); + for chunk in omegas.into_iter() { + omega += &(*chunk * scale); scale *= &polyscale; } } @@ -172,12 +172,12 @@ pub fn combine_polys>( DensePolynomialOrEvaluations::DensePolynomial(p_i) => { let mut offset = 0; // iterating over chunks of the polynomial - for j in 0..omegas.len() { + for chunk in omegas.into_iter() { let segment = &p_i.coeffs[std::cmp::min(offset, p_i.coeffs.len()) ..std::cmp::min(offset + srs_length, p_i.coeffs.len())]; plnm_coefficients.add_poly(scale, segment); - omega += &(omegas.chunks[j] * scale); + omega += &(*chunk * scale); scale *= &polyscale; offset += srs_length; }