Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilinear extension evaluation speedup #603

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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