Skip to content

Commit

Permalink
Improve evaluation of LaurentPolynomial (#292)
Browse files Browse the repository at this point in the history
Use `ntuple` instead of `NTuple` for constructing the coefficient tuples
passed to `evalpoly`. This compiles much faster on Julia 1.0 (especially
for high-degree polynomials) and is also faster to evaluate even on
current Julia.
  • Loading branch information
martinholters authored Nov 3, 2020
1 parent f2c4a0e commit d72dd38
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/polynomials/LaurentPolynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ function (p::LaurentPolynomial{T})(x::S) where {T,S}
m,n = (extrema degreerange)(p)
m == n == 0 && return p[0] * _one(S)
if m >= 0
evalpoly(x, NTuple{n+1,T}(p[i] for i in 0:n))
evalpoly(x, ntuple(i -> p[i-1], n+1)) # NTuple{n+1}(p[i] for i in 0:n)
elseif n <= 0
evalpoly(inv(x), NTuple{-m+1,T}(p[i] for i in 0:-1:m))
evalpoly(inv(x), ntuple(i -> p[-i+1], -m+1)) # NTuple{-m+1}(p[i] for i in 0:-1:m)
else
# eval pl(x) = a_mx^m + ...+ a_0 at 1/x; pr(x) = a_0 + a_1x + ... + a_nx^n at x; subtract a_0
l = evalpoly(inv(x), NTuple{-m+1,T}(p[i] for i in 0:-1:m))
r = evalpoly(x, NTuple{n+1,T}(p[i] for i in 0:n))
l = evalpoly(inv(x), ntuple(i -> p[-i+1], -m+1)) # NTuple{-m+1}(p[i] for i in 0:-1:m)
r = evalpoly(x, ntuple(i -> p[i-1], n+1)) # NTuple{n+1}(p[i] for i in 0:n)
mid = p[0]
l + r - mid
end
Expand Down

2 comments on commit d72dd38

@jverzani
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/24108

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.11 -m "<description of version>" d72dd38caf176ba0d5c919c73c444e7b6f78c6be
git push origin v1.1.11

Please sign in to comment.