@@ -156,27 +156,35 @@ impl<'a, F: 'a + FftField> DenseOrSparsePolynomial<'a, F> {
156156 Evaluations :: from_vec_and_domain ( evals, domain)
157157 } ,
158158 DPolynomial ( Cow :: Borrowed ( d) ) => {
159- // Reduce the coefficients of the polynomial mod X^domain.size()
160- let mut chunks = d. coeffs . chunks ( domain. size ( ) ) ;
161- let mut reduced = chunks. next ( ) . unwrap ( ) . to_vec ( ) ;
162- for chunk in chunks {
163- cfg_iter_mut ! ( reduced) . zip ( chunk) . for_each ( |( x, y) | {
164- * x += y;
165- } ) ;
159+ if d. is_zero ( ) {
160+ Evaluations :: from_vec_and_domain ( vec ! [ F :: zero( ) ; domain. size( ) ] , domain)
161+ } else {
162+ // Reduce the coefficients of the polynomial mod X^domain.size()
163+ let mut chunks = d. coeffs . chunks ( domain. size ( ) ) ;
164+ let mut reduced = chunks. next ( ) . unwrap ( ) . to_vec ( ) ;
165+ for chunk in chunks {
166+ cfg_iter_mut ! ( reduced) . zip ( chunk) . for_each ( |( x, y) | {
167+ * x += y;
168+ } ) ;
169+ }
170+ Evaluations :: from_vec_and_domain ( domain. fft ( & reduced) , domain)
166171 }
167- Evaluations :: from_vec_and_domain ( domain. fft ( & reduced) , domain)
168172 } ,
169173 DPolynomial ( Cow :: Owned ( mut d) ) => {
170174 // Reduce the coefficients of the polynomial mod X^domain.size()
171- let mut chunks = d. coeffs . chunks_mut ( domain. size ( ) ) ;
172- let coeffs = chunks. next ( ) . unwrap ( ) ;
173- for chunk in chunks {
174- cfg_iter_mut ! ( coeffs) . zip ( chunk) . for_each ( |( x, y) | {
175- * x += y;
176- } ) ;
175+ if d. is_zero ( ) {
176+ Evaluations :: from_vec_and_domain ( vec ! [ F :: zero( ) ; domain. size( ) ] , domain)
177+ } else {
178+ let mut chunks = d. coeffs . chunks_mut ( domain. size ( ) ) ;
179+ let coeffs = chunks. next ( ) . unwrap ( ) ;
180+ for chunk in chunks {
181+ cfg_iter_mut ! ( coeffs) . zip ( chunk) . for_each ( |( x, y) | {
182+ * x += y;
183+ } ) ;
184+ }
185+ domain. fft_in_place ( & mut d. coeffs ) ;
186+ Evaluations :: from_vec_and_domain ( d. coeffs , domain)
177187 }
178- domain. fft_in_place ( & mut d. coeffs ) ;
179- Evaluations :: from_vec_and_domain ( d. coeffs , domain)
180188 } ,
181189 }
182190 }
0 commit comments