Skip to content

Commit 2721757

Browse files
authored
Handle empty inputs in EvalUnivariate and EvalMultilinearMany (#1605)
1 parent 69fb6a1 commit 2721757

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

std/math/polynomial/polynomial.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func New[FR emulated.FieldParams](api frontend.API) (*Polynomial[FR], error) {
9393
// EvalUnivariate evaluates univariate polynomial at a point at. It returns the
9494
// evaluation. The method does not mutate the inputs.
9595
func (p *Polynomial[FR]) EvalUnivariate(P Univariate[FR], at *emulated.Element[FR]) *emulated.Element[FR] {
96+
if len(P) == 0 {
97+
return p.f.Zero()
98+
}
9699
res := p.f.Zero()
97100
for i := len(P) - 1; i > 0; i-- {
98101
res = p.f.Add(res, &P[i])
@@ -118,6 +121,9 @@ func (p *Polynomial[FR]) EvalMultilinear(at []*emulated.Element[FR], M Multiline
118121
// The method allows to share computations of computing the coefficients of the
119122
// multilinear polynomials at the given evaluation points.
120123
func (p *Polynomial[FR]) EvalMultilinearMany(at []*emulated.Element[FR], M ...Multilinear[FR]) ([]*emulated.Element[FR], error) {
124+
if len(M) == 0 {
125+
return nil, errors.New("no multilinear polynomials to evaluate")
126+
}
121127
lenM := len(M[0])
122128
for i := range M {
123129
if len(M[i]) != lenM {

0 commit comments

Comments
 (0)