Skip to content

Commit

Permalink
refactor: Inline used-once method
Browse files Browse the repository at this point in the history
changelog: ignore
  • Loading branch information
jan-ferdinand committed Oct 1, 2024
1 parent 7513004 commit 0251592
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ impl Stark {
let main_and_aux_codeword = short_domain.evaluate(&main_and_aux_combination_polynomial);

profiler!(start "quotient" ("CC"));
let quotient_segments_combination_polynomial =
Self::random_linear_sum(quotient_segment_polynomials.view(), weights.quot_segments);
let quotient_segments_combination_polynomial = quotient_segment_polynomials
.into_iter()
.zip_eq(weights.quot_segments)
.fold(Polynomial::zero(), |acc, (poly, w)| acc + poly * w);
let quotient_segments_combination_codeword =
short_domain.evaluate(&quotient_segments_combination_polynomial);
profiler!(stop "quotient");
Expand Down Expand Up @@ -480,39 +482,6 @@ impl Stark {
)
}

/// # Panics
///
/// Panics if the number of polynomials and weights are not equal.
fn random_linear_sum<FF>(
polynomials: ArrayView1<Polynomial<FF>>,
weights: Array1<XFieldElement>,
) -> Polynomial<XFieldElement>
where
FF: FiniteField + Mul<XFieldElement, Output = XFieldElement>,
{
assert_eq!(polynomials.len(), weights.len());

let random_linear_sum = (0..polynomials[0].coefficients.len())
.into_par_iter()
.map(|i| {
polynomials
.axis_iter(Axis(0))
.zip(&weights)
.map(|(poly, &w)| poly[()].coefficients[i] * w)
.sum()
})
.collect();
Polynomial::new(random_linear_sum)

// todo: replace by
// ```
// Zip::from(polynomials)
// .and(&weights)
// .fold(Polynomial::zero(), |acc, poly, &w| acc + poly.scalar_mul(w))
// ```
// (and maybe alter trait bounds) once `twenty-first` v0.42.0 is released.
}

/// Take a linear combination of the columns of the matrix with given weights.
/// The matrix can be defined over the base or extension fields.
///
Expand Down

0 comments on commit 0251592

Please sign in to comment.