Skip to content

Commit a7e6113

Browse files
committed
ENH: speedup evaluation of numpy.polynomial.legendre.legval
Moving the parentheses combines two broadcasted scalar multiplies into one. This improves runtime by about 30% when evaluating on large grids.
1 parent 4873f93 commit a7e6113

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

numpy/polynomial/legendre.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ def legval(x, c, tensor=True):
905905
for i in range(3, len(c) + 1):
906906
tmp = c0
907907
nd = nd - 1
908-
c0 = c[-i] - (c1*(nd - 1))/nd
909-
c1 = tmp + (c1*x*(2*nd - 1))/nd
908+
c0 = c[-i] - c1*((nd - 1)/nd)
909+
c1 = tmp + c1*x*((2*nd - 1)/nd)
910910
return c0 + c1*x
911911

912912

0 commit comments

Comments
 (0)