Skip to content

Commit 99d8a2f

Browse files
authored
Merge pull request #16 from andreasnoack/an/polynomial
Make Polynomials a dependency and stop using Requires
2 parents 82a4f42 + 49a25e6 commit 99d8a2f

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

Project.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ version = "1.0.0"
44

55
[deps]
66
LibAMVW_jll = "3420f54a-cca3-5752-a4b4-c8f5453f04ac"
7-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
7+
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
88

99
[compat]
10-
julia = "1.3"
1110
LibAMVW_jll = "1"
12-
Requires = "1"
11+
Polynomials = "0.7"
12+
julia = "1.3"
1313

1414
[extras]
15-
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
1615
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1716

1817
[targets]
19-
test = ["Polynomials", "Test"]
18+
test = ["Test"]

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ This package is a Julia wrapper of the Fortran programs accompanying [Fast and B
77
## Usage
88

99
The package provides the unexported function `FastPolynomialRoots.rootsFastPolynomialRoots(p::Vector{<:Union{Float64,Complex{Float64}}})`
10-
which computes the roots of the polynomial `p[1] + p[2]*x + p[3]*x^2 + ... + p[k]*x^(k-1)`. If the
11-
`Polynomials` packages is loaded, the `roots(::Poly)` methods for `Float64` and `Complex{Float64}` will
12-
be overwritten to that fast version provided by this package. See the examples below.
10+
which computes the roots of the polynomial `p[1] + p[2]*x + p[3]*x^2 + ... + p[k]*x^(k-1)`. The package also overwrites the `roots(::Polynomial)` methods in the `Polynomials` package for `Float64` and `Complex{Float64}` elements with the fast versions provided by this package. See the examples below.
1311

1412
## Example 1: Speed up `roots`
1513
```julia
1614
julia> using Polynomials, BenchmarkTools
1715

1816
julia> @btime roots(p) setup=(p = Polynomial(randn(500)));
19-
408.564 ms (54 allocations: 3.99 MiB)
17+
223.135 ms (23 allocations: 3.97 MiB)
2018

2119
julia> using FastPolynomialRoots
2220

2321
julia> @btime roots(p) setup=(p = Polynomial(randn(500)));
24-
46.507 ms (7 allocations: 26.41 KiB)
22+
30.786 ms (7 allocations: 26.41 KiB)
2523
```
2624

2725
## Example 2: Roots of a polynomial of degree 10,000
@@ -30,11 +28,10 @@ but can be handled by FastPolynomialRoots.
3028
```julia
3129
julia> using Polynomials, BenchmarkTools, FastPolynomialRoots
3230

33-
julia> n = 10000
34-
10000
31+
julia> n = 10000;
3532

3633
julia> r = @btime roots(p) setup=(p = Polynomial(randn(n + 1)));
37-
15.715 s (13 allocations: 508.38 KiB)
34+
10.290 s (13 allocations: 508.38 KiB)
3835

3936
julia> sum(isreal, r)
4037
7

src/FastPolynomialRoots.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
module FastPolynomialRoots
22

3-
using LibAMVW_jll, Requires
3+
using LibAMVW_jll, Polynomials
44

5-
function __init__()
6-
7-
@require Polynomials="f27b6e38-b328-58d1-80ce-0feddd5e7a45" begin
8-
Polynomials.roots(p::Union{Polynomials.Poly{Float64},Polynomials.Poly{Complex{Float64}}}) = rootsFastPolynomialRoots(p.a)
9-
Polynomials.roots(p::Polynomials.Poly{<:Integer}) = rootsFastPolynomialRoots(convert(Polynomials.Poly{Float64}, p))
10-
end
11-
end
5+
Polynomials.roots(p::Union{Polynomial{Float64},Polynomial{Complex{Float64}}}) = rootsFastPolynomialRoots(coeffs(p))
6+
Polynomials.roots(p::Polynomial{<:Integer}) = rootsFastPolynomialRoots(convert(Polynomial{Float64}, p))
127

138
function rootsFastPolynomialRoots(a::Vector{Float64})
149

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
using Test, FastPolynomialRoots, Polynomials
22

33
@testset "Standard normal coefficients" begin
4-
p = Poly(randn(50))
4+
p = Polynomial(randn(50))
55
@test sort(abs.(roots(p))) sort(abs.(roots(p)))
66
end
77
@testset "Standard normal complex coefficient" begin
8-
p = Poly(complex.(randn(50), randn(50)))
8+
p = Polynomial(complex.(randn(50), randn(50)))
99
@test sort(abs.(roots(p))) sort(abs.(roots(p)))
1010
end
1111

1212
@testset "Large polynomial" begin
13-
p = Poly(randn(5000))
13+
p = Polynomial(randn(5000))
1414
@time roots(p)
1515

1616
@info "Possible to calculate roots of large polynomial"
1717
@show rts = 1:100.0
18-
p = mapreduce(t -> Poly([1, -t]), *, rts, init=Poly(Float64[1]))
18+
p = mapreduce(t -> Polynomial([1, -t]), *, rts, init=Polynomial(Float64[1]))
1919
@info "But polynomial root finding is ill conditioned"
2020
@show sum(abs2, sort(abs.(roots(p))) - rts)
2121
end

0 commit comments

Comments
 (0)