Skip to content

Commit 8fe313d

Browse files
Merge pull request #1 from JeffreySarnoff/fbot/deps
Fix deprecations (from attobot)
2 parents 6f08334 + d91aa9d commit 8fe313d

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/Polynomials.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Poly type manipulations
22

3-
isdefined(Base, :__precompile__) && __precompile__()
3+
__precompile__()
4+
45

56
module Polynomials
67
#todo: sparse polynomials?
@@ -76,7 +77,7 @@ Poly(0.5 - 0.5⋅x^2)
7677
struct Poly{T}
7778
a::Vector{T}
7879
var::Symbol
79-
function (::Type{Poly})(a::AbstractVector{T}, var::SymbolLike = :x) where {T<:Number}
80+
function Poly(a::AbstractVector{T}, var::SymbolLike = :x) where {T<:Number}
8081
# if a == [] we replace it with a = [0]
8182
if length(a) == 0
8283
return new{T}(zeros(T,1),Symbol(var))
@@ -90,7 +91,7 @@ struct Poly{T}
9091
end
9192

9293
Poly(n::Number, var::SymbolLike = :x) = Poly([n], var)
93-
(::Type{Poly{T}})(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S} =
94+
Poly{T}(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S} =
9495
Poly(convert(Vector{T}, x), var)
9596

9697
# create a Poly object from its roots
@@ -403,21 +404,21 @@ given `norm` function. The tolerances `rtol` and `atol` are passed to both
403404
`truncate` and `isapprox`.
404405
"""
405406
function isapprox(p1::Poly{T}, p2::Poly{S};
406-
rtol::Real = (@compat Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = vecnorm) where {T,S}
407+
rtol::Real = (Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = vecnorm) where {T,S}
407408
p1.var == p2.var || error("Polynomials must have same variable")
408409
p1t = truncate(p1; rtol = rtol, atol = atol)
409410
p2t = truncate(p2; rtol = rtol, atol = atol)
410411
length(p1t) == length(p2t) && isapprox(coeffs(p1t), coeffs(p2t); rtol = rtol,
411412
atol = atol, norm = norm)
412413
end
413414

414-
function isapprox(p1::Poly{T}, n::S; rtol::Real = (@compat Base.rtoldefault(T,S, 0)),
415+
function isapprox(p1::Poly{T}, n::S; rtol::Real = (Base.rtoldefault(T,S, 0)),
415416
atol::Real = 0) where {T,S<:Number}
416417
p1t = truncate(p1; rtol = rtol, atol = atol)
417418
degree(p1t) == 0 && isapprox(coeffs(p1), [n]; rtol = rtol, atol = atol)
418419
end
419420

420-
isapprox(n::S, p1::Poly{T}; rtol::Real= (@compat Base.rtoldefault(T,S, 0)),
421+
isapprox(n::S, p1::Poly{T}; rtol::Real= (Base.rtoldefault(T,S, 0)),
421422
atol::Real = 0) where {T,S<:Number} = isapprox(p1, n; rtol = rtol, atol = atol)
422423

423424
hash(f::Poly, h::UInt) = hash(f.var, hash(f.a, h))
@@ -505,7 +506,7 @@ polyint(p::Poly{T}, k::S) where {T,S<:Number} = _polyint(p, k)
505506
function _polyint(p::Poly{T}, k::S) where {T,S<:Number}
506507
n = length(p)
507508
R = promote_type(typeof(one(T)/1), S)
508-
a2 = @compat Vector{R}(undef, n+1)
509+
a2 = Vector{R}(undef, n+1)
509510
a2[1] = k
510511
for i = 1:n
511512
a2[i+1] = p[i-1] / i
@@ -566,7 +567,7 @@ end
566567

567568
function _polyder(p::Poly{T}, order::Int=1) where {T}
568569
n = length(p)
569-
a2 = @compat Vector{T}(undef, n-order)
570+
a2 = Vector{T}(undef, n-order)
570571
for i = order:n-1
571572
a2[i-order+1] = p[i] * prod((i-order+1):i)
572573
end
@@ -634,7 +635,7 @@ function roots(p::Poly{T}) where {T}
634635
n = lastindex(p)-(num_leading_zeros + num_trailing_zeros)
635636
n < 1 && return zeros(R, length(p) - num_trailing_zeros - 1)
636637

637-
companion = @compat diagm(-1 => ones(R, n-1))
638+
companion = diagm(-1 => ones(R, n-1))
638639
an = p[end-num_trailing_zeros]
639640
companion[1,:] = -p[(end-num_trailing_zeros-1):-1:num_leading_zeros] / an
640641

src/pade.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ struct Pade{T<:Number,S<:Number}
22
p::Poly{T}
33
q::Poly{S}
44
var::Symbol
5-
function (::Type{Pade{T,S}})(p::Poly{T},q::Poly{S}) where {T,S}
5+
function Pade{T,S}(p::Poly{T},q::Poly{S}) where {T,S}
66
if p.var != q.var
77
error("Polynomials must have same variable")
88
end
99
new{T,S}(p, q, p.var)
1010
end
1111
end
12-
(::Type{Pade})(p::Poly{T}, q::Poly{S}) where {T<:Number,S<:Number}= Pade{T,S}(p,q)
12+
Pade(p::Poly{T}, q::Poly{S}) where {T<:Number,S<:Number}= Pade{T,S}(p,q)
1313

14-
function (::Type{Pade})(c::Poly{T},m::Int,n::Int) where {T}
14+
function Pade(c::Poly{T},m::Int,n::Int) where {T}
1515
@assert m+n < length(c)
1616
rold,rnew = Poly([zeros(T,m+n+1);one(T)],c.var),Poly(c.a[1:m+n+1],c.var)
1717
uold,vold = Poly([one(T)],c.var),Poly([zero(T)],c.var)

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ default, the terms are in order of ascending powers, matching the order in
7878
7979
# Examples
8080
```jldoctest
81-
julia> printpoly(STDOUT, Poly([1,2,3], :y))
81+
julia> printpoly(stdout, Poly([1,2,3], :y))
8282
1 + 2*y + 3*y^2
83-
julia> printpoly(STDOUT, Poly([1,2,3], :y), descending_powers=true)
83+
julia> printpoly(stdout, Poly([1,2,3], :y), descending_powers=true)
8484
3*y^2 + 2*y + 1
8585
```
8686
"""

test/runtests.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const _γ = 0.5772156649015
150150
println("Test for the summation of a factorially divergent series.")
151151
d = Poly(convert(Vector{BigInt},(-1).^(0:60).* map(gamma,BigFloat(1):BigFloat(61.0))).//1,"x")
152152
PQexpint = Pade(d,30,30)
153-
@compat println("The approximate sum of the divergent series is: ", Float64(padeval(PQexpint,1.0)))
153+
println("The approximate sum of the divergent series is: ", Float64(padeval(PQexpint,1.0)))
154154
println("The approximate sum of the convergent series is: ",exp(1)*(--sum([(-1).^k/k./gamma(k+1) for k=1:20])))
155155
@test isapprox(convert(Float64, padeval(PQexpint,1.0)),
156156
exp(1)*(--sum([(-1).^k/k./gamma(k+1) for k=1:20])))
@@ -290,15 +290,6 @@ end
290290
@test printpoly_to_string(Poly([1,2,3], "y"), descending_powers=true) == "3*y^2 + 2*y + 1"
291291

292292
## want to be able to copy and paste
293-
if VERSION < v"0.6.0-dev"
294-
string_eval_poly(p,x) = eval(Expr(:function, Expr(:call, :f, :x), parse(string(p)[6:end-1])))(x)
295-
p = Poly([1,2,3]) # copy and paste
296-
q = Poly([1//1, 2//1, 3//1])
297-
r = Poly([1.0, 2, 3])
298-
@test string_eval_poly(p, 5) == p(5)
299-
@test string_eval_poly(q, 5) == q(5)
300-
@test string_eval_poly(r, 5) == r(5)
301-
end
302293
## check hashing
303294
p = poly([1,2,3])
304295
q = poly([1,2,3])

0 commit comments

Comments
 (0)