-
Notifications
You must be signed in to change notification settings - Fork 269
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
Fix evaluation of dense polynomials over domains smaller than the degree #521
Conversation
Evaluations::from_vec_and_domain(domain.fft(&d.coeffs), domain) | ||
let chunks = d.coeffs.chunks(domain.size()); | ||
let reduced = chunks.fold(vec![F::zero(); domain.size()], |x, y| { | ||
x.iter().zip(y).map(|(&x, y)| x + y).collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x.iter().zip(y).map(|(&x, y)| x + y).collect() | |
cfg_iter!(x).zip(y).map(|(&x, y)| x + y).collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can avoid extra allocations here by making this a for loop, like so:
let mut reduced = chunks.next().unwrap();
for chunk in chunks {
cfg_iter_mut!(reduced).zip(chunk).for_each(|(x, y)| {
*x += y;
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the notes, should be better now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. Just left a small comment.
Fixes the evaluation of dense polynomials over domains smaller than the polynomial degree.
Currently, the coefficients of dense polynomials are truncated to match the size of the evaluation domain. This causes unexpected / incorrect behavior when larger polynomials are used. This PR resolves the issue by reducing the polynomial mod
X^d
whered
is the size of the domain, before the FFT is performed.A new unit test is located in
src/polynomial/univariate/sparse.rs
It may also be a good idea to throw an error in the FFT routine when the coefficient vector is bigger than the FFT size, so that information is not accidentally discarded.
closes: #520
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer