Skip to content

Commit

Permalink
Update arithmetic.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
crStiv authored Jan 16, 2025
1 parent 39ff2d3 commit ec627e2
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ pub fn eval_polynomial<F: Field>(poly: &[F], point: F) -> F {
/// This computes the inner product of two vectors `a` and `b`.
///
/// This function will panic if the two vectors are not the same size.
/// For vectors smaller than 32 elements, it uses sequential computation for better performance.
/// For larger vectors, it switches to parallel computation using multiple threads.
pub fn compute_inner_product<F: Field>(a: &[F], b: &[F]) -> F {
assert_eq!(a.len(), b.len());

Expand All @@ -124,20 +122,9 @@ pub fn compute_inner_product<F: Field>(a: &[F], b: &[F]) -> F {
return acc;
}

// Use parallel computation for large vectors
let mut products = vec![F::ZERO; a.len()];
parallelize(&mut products, |products, chunk_size| {
for (((a, b), product), i) in a
.chunks(chunk_size)
.zip(b.chunks(chunk_size))
.zip(products)
.zip(0..)
{
*product = a.iter().zip(b.iter()).fold(F::ZERO, |acc, (a, b)| acc + (*a) * (*b));
}
});

products.iter().fold(F::ZERO, |acc, product| acc + *product)
// Use parallel computation with rayon
use rayon::prelude::*;

Check failure on line 126 in halo2_proofs/src/arithmetic.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

failed to resolve: use of undeclared crate or module `rayon`
a.par_iter().zip(b.par_iter()).map(|(a, b)| (*a) * (*b)).sum()

Check failure on line 127 in halo2_proofs/src/arithmetic.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

no method named `par_iter` found for reference `&[F]` in the current scope

Check failure on line 127 in halo2_proofs/src/arithmetic.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

no method named `par_iter` found for reference `&[F]` in the current scope
}

/// Divides polynomial `a` in `X` by `X - b` with
Expand Down

0 comments on commit ec627e2

Please sign in to comment.