Skip to content

Commit

Permalink
Multilinear extension evaluation speedup (arkworks-rs#603)
Browse files Browse the repository at this point in the history
* Reduce # multiplications in dense ml extension eval

* Reduce # multiplications in sparse ml extension eval

* Eliminate extra vector allocation in precompute_eq

* Add entry to changelog on mul reduction in eval functions
  • Loading branch information
Ben Hamlin authored and paberr committed Feb 22, 2023
1 parent 4eefba7 commit b65e251
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Pending

- (`ark-poly`) Reduce the number of field multiplications performed by `SparseMultilinearExtension::evaluate` and `DenseMultilinearExtension::evaluate`

### Breaking changes

### Features
Expand Down
4 changes: 3 additions & 1 deletion poly/src/evaluations/multivariate/multilinear/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ impl<F: Field> MultilinearExtension<F> for DenseMultilinearExtension<F> {
for i in 1..dim + 1 {
let r = partial_point[i - 1];
for b in 0..(1 << (nv - i)) {
poly[b] = poly[b << 1] * (F::one() - r) + poly[(b << 1) + 1] * r;
let left = poly[b << 1];
let right = poly[(b << 1) + 1];
poly[b] = left + r * (right - left);
}
}
Self::from_evaluations_slice(nv - dim, &poly[..(1 << (nv - dim))])
Expand Down
9 changes: 4 additions & 5 deletions poly/src/evaluations/multivariate/multilinear/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ impl<F: Field> SparseMultilinearExtension<F> {
/// utility: precompute f(x) = eq(g,x)
fn precompute_eq<F: Field>(g: &[F]) -> Vec<F> {
let dim = g.len();
let mut dp = Vec::with_capacity(1 << dim);
dp.resize(1 << dim, F::zero());
let mut dp = vec![F::zero(); 1 << dim];
dp[0] = F::one() - g[0];
dp[1] = g[0];
for i in 1..dim {
let dp_prev = dp[0..(1 << i)].to_vec();
for b in 0..(1 << i) {
dp[b] = dp_prev[b] * (F::one() - g[i]);
dp[b + (1 << i)] = dp_prev[b] * g[i];
let prev = dp[b];
dp[b + (1 << i)] = prev * g[i];
dp[b] = prev - dp[b + (1 << i)];
}
}
dp
Expand Down

0 comments on commit b65e251

Please sign in to comment.