-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 evalpoly for no coefficients case #56706
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -91,7 +91,7 @@ julia> evalpoly(2, (1, 2, 3)) | |||||
17 | ||||||
``` | ||||||
""" | ||||||
function evalpoly(x, p::Tuple) | ||||||
function evalpoly(x, p::Tuple{Any, Vararg}) | ||||||
if @generated | ||||||
N = length(p.parameters::Core.SimpleVector) | ||||||
ex = :(p[end]) | ||||||
|
@@ -104,19 +104,22 @@ function evalpoly(x, p::Tuple) | |||||
end | ||||||
end | ||||||
|
||||||
evalpoly(x, p::Tuple{}) = zero(x) | ||||||
|
||||||
evalpoly(x, p::AbstractVector) = _evalpoly(x, p) | ||||||
|
||||||
function _evalpoly(x, p) | ||||||
Base.require_one_based_indexing(p) | ||||||
N = length(p) | ||||||
N == 0 && return zero(x) | ||||||
ex = p[end] | ||||||
for i in N-1:-1:1 | ||||||
ex = muladd(x, ex, p[i]) | ||||||
end | ||||||
ex | ||||||
end | ||||||
|
||||||
function evalpoly(z::Complex, p::Tuple) | ||||||
function evalpoly(z::Complex, p::Tuple{Any, Any, Vararg}) | ||||||
if @generated | ||||||
N = length(p.parameters) | ||||||
a = :(p[end]) | ||||||
|
@@ -141,15 +144,18 @@ function evalpoly(z::Complex, p::Tuple) | |||||
_evalpoly(z, p) | ||||||
end | ||||||
end | ||||||
|
||||||
evalpoly(z::Complex, p::Tuple{<:Any}) = p[1] | ||||||
|
||||||
evalpoly(z::Complex, p::Tuple{}) = zero(z) | ||||||
|
||||||
evalpoly(z::Complex, p::AbstractVector) = _evalpoly(z, p) | ||||||
|
||||||
function _evalpoly(z::Complex, p) | ||||||
Base.require_one_based_indexing(p) | ||||||
length(p) == 1 && return p[1] | ||||||
N = length(p) | ||||||
N == 0 && return zero(z) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
for improved type-stability? Although that will throw if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your suggestion, but I personally think this change should not be made due to the possible undefined error in |
||||||
N == 1 && return p[1] | ||||||
a = p[end] | ||||||
b = p[end-1] | ||||||
|
||||||
|
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.
Don't unnecessarily increase diff size. Leave this line as it is.
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.
Sorry for that. I have fixed it in the latest commit.