mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Merge pull request #23 from mir-protocol/montgomery-barycentric
Montgomery inversion in computation of barycentric weights
This commit is contained in:
commit
1786f5e07d
@ -53,15 +53,16 @@ fn interpolate<F: Field>(points: &[(F, F)], x: F, barycentric_weights: &[F]) ->
|
|||||||
|
|
||||||
fn barycentric_weights<F: Field>(points: &[(F, F)]) -> Vec<F> {
|
fn barycentric_weights<F: Field>(points: &[(F, F)]) -> Vec<F> {
|
||||||
let n = points.len();
|
let n = points.len();
|
||||||
(0..n)
|
F::batch_multiplicative_inverse(
|
||||||
|
&(0..n)
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
(0..n)
|
(0..n)
|
||||||
.filter(|&j| j != i)
|
.filter(|&j| j != i)
|
||||||
.map(|j| points[i].0 - points[j].0)
|
.map(|j| points[i].0 - points[j].0)
|
||||||
.product::<F>()
|
.product::<F>()
|
||||||
.inverse()
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -117,16 +118,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn eval_naive<F: Field>(coeffs: &PolynomialCoeffs<F>, domain: &[F]) -> Vec<(F, F)> {
|
fn eval_naive<F: Field>(coeffs: &PolynomialCoeffs<F>, domain: &[F]) -> Vec<(F, F)> {
|
||||||
domain
|
domain.iter().map(|&x| (x, coeffs.eval(x))).collect()
|
||||||
.iter()
|
|
||||||
.map(|&x| {
|
|
||||||
let eval = x
|
|
||||||
.powers()
|
|
||||||
.zip(&coeffs.coeffs)
|
|
||||||
.map(|(x_power, &coeff)| coeff * x_power)
|
|
||||||
.sum();
|
|
||||||
(x, eval)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user