Closed johanbluecreek closed 2 years ago
This seems to do it
diff --git a/src/FastPolynomialRoots.jl b/src/FastPolynomialRoots.jl
index 87f7baf..2077096 100644
--- a/src/FastPolynomialRoots.jl
+++ b/src/FastPolynomialRoots.jl
@@ -3,7 +3,7 @@ module FastPolynomialRoots
using LibAMVW_jll, Polynomials
Polynomials.roots(p::Union{Polynomial{Float64},Polynomial{Complex{Float64}}}) = rootsFastPolynomialRoots(coeffs(p))
-Polynomials.roots(p::Polynomial{<:Integer}) = rootsFastPolynomialRoots(convert(Polynomial{Float64}, p))
+Polynomials.roots(p::Polynomial{<:Integer}) = rootsFastPolynomialRoots(convert(Vector{Float64}, coeffs(p)))
function rootsFastPolynomialRoots(a::Vector{Float64})
since then (continued session from above)
julia> Polynomials.roots(p::Polynomial{<:Integer}) = FastPolynomialRoots.rootsFastPolynomialRoots(convert(Vector{Float64}, coeffs(p)))
julia> Polynomial(Int64[1,10,100,1000]) |> roots
3-element Array{Complex{Float64},1}:
1.6219664500383146e-16 + 0.1000000000000001im
1.6219664500383146e-16 - 0.1000000000000001im
-0.09999999999999977 + 0.0im
julia> Polynomial(BigInt[1,10,100,1000]) |> roots
3-element Array{Complex{Float64},1}:
1.6219664500383146e-16 + 0.1000000000000001im
1.6219664500383146e-16 - 0.1000000000000001im
-0.09999999999999977 + 0.0im
or maybe BigInt
should be expected to be using the original Polynomials.roots
with GenericLinearAlgebra
's eigvals
?
Usually, we convert BigInt
s to BigFloat
s. I think we should only overwrite methods for which this package has implementations so I suspect that the Polynomials.roots(p::Polynomial{<:Integer})
method should be narrowed to just Int
.
Do you know how Roots solves the BigFloat case right now?
I think we should only overwrite methods for which this package has implementations so I suspect that the
Polynomials.roots(p::Polynomial{<:Integer})
method should be narrowed to justInt
.
I'd agree.
Do you know how Roots solves the BigFloat case right now?
I'm quite sure that the original Polynomials.roots
(if that is what you mean by "Roots") solves the problem by deriving the companion matrix and sending it to eigvals
. Since if I do not have GenericLinearAlgebra
loaded the call with a Polynomial{BigInt}
or BigFloat
just gives me e.g. ERROR: MethodError: no method matching eigvals!(::Array{BigFloat,2})
.
With the original
Polynomials.roots()
there are several working methods supporting polynomials with float and integer coefficients:when
roots
is overwritten byFastPolynomialRoots
, the methods for integers break:The expected behavior I would say is that the methods that were working before to still be working after
FastPolynomialRoots
has been used.