Skip to content

Commit

Permalink
refactor: replace scalar_product function with an inline fold opera…
Browse files Browse the repository at this point in the history
…tion (#200)
  • Loading branch information
huitseeker authored and porcuquine committed Jun 28, 2023
1 parent 308cc53 commit e51b866
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/circuit2_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ where

// sparse mds
{
elements_buffer[0] = scalar_product(elements, &m.w_hat);
elements_buffer[0] = elements
.iter()
.zip(&m.w_hat)
.fold(Scalar::ZERO, |acc, (&x, &y)| acc + (x * y));

for j in 1..width {
elements_buffer[j] = elements[j] + elements[0] * m.v_rest[j - 1];
Expand Down Expand Up @@ -315,12 +318,6 @@ where
}
}

fn scalar_product<Scalar: PrimeField>(a: &[Scalar], b: &[Scalar]) -> Scalar {
a.iter()
.zip(b)
.fold(Scalar::ZERO, |acc, (&x, &y)| acc + (x * y))
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit e51b866

Please sign in to comment.