mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 06:43:07 +00:00
trim_to_len helper function (#472)
* trim_to_len helper function Seems a little nicer IMO to only remove a certain number of zeros, vs removing all trailing zeros then re-adding some. * PR feedback
This commit is contained in:
parent
a43e138f57
commit
b40827e655
@ -197,12 +197,21 @@ impl<F: Field> PolynomialCoeffs<F> {
|
||||
poly
|
||||
}
|
||||
|
||||
/// Removes leading zero coefficients.
|
||||
/// Removes any leading zero coefficients.
|
||||
pub fn trim(&mut self) {
|
||||
self.coeffs.truncate(self.degree_plus_one());
|
||||
}
|
||||
|
||||
/// Removes leading zero coefficients.
|
||||
/// Removes some leading zero coefficients, such that a desired length is reached. Fails if a
|
||||
/// nonzero coefficient is encountered before then.
|
||||
pub fn trim_to_len(&mut self, len: usize) -> Result<()> {
|
||||
ensure!(self.len() >= len);
|
||||
ensure!(self.coeffs[len..].iter().all(F::is_zero));
|
||||
self.coeffs.truncate(len);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes any leading zero coefficients.
|
||||
pub fn trimmed(&self) -> Self {
|
||||
let coeffs = self.coeffs[..self.degree_plus_one()].to_vec();
|
||||
Self { coeffs }
|
||||
|
||||
@ -148,11 +148,10 @@ pub(crate) fn prove<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, co
|
||||
quotient_polys
|
||||
.into_par_iter()
|
||||
.flat_map(|mut quotient_poly| {
|
||||
quotient_poly.trim();
|
||||
quotient_poly.pad(quotient_degree).expect(
|
||||
"Quotient has failed, the vanishing polynomial is not divisible by `Z_H",
|
||||
quotient_poly.trim_to_len(quotient_degree).expect(
|
||||
"Quotient has failed, the vanishing polynomial is not divisible by Z_H",
|
||||
);
|
||||
// Split t into degree-n chunks.
|
||||
// Split quotient into degree-n chunks.
|
||||
quotient_poly.chunks(degree)
|
||||
})
|
||||
.collect()
|
||||
|
||||
@ -80,10 +80,9 @@ where
|
||||
let all_quotient_chunks = quotient_polys
|
||||
.into_par_iter()
|
||||
.flat_map(|mut quotient_poly| {
|
||||
quotient_poly.trim();
|
||||
quotient_poly
|
||||
.pad(degree * stark.quotient_degree_factor())
|
||||
.expect("Quotient has failed, the vanishing polynomial is not divisible by `Z_H");
|
||||
.trim_to_len(degree * stark.quotient_degree_factor())
|
||||
.expect("Quotient has failed, the vanishing polynomial is not divisible by Z_H");
|
||||
// Split quotient into degree-n chunks.
|
||||
quotient_poly.chunks(degree)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user