Skip to content

Commit a94fed9

Browse files
authored
Fix more deprecations; drop Compat dep (#149)
* Fix deprecations * Fix more deprecations; drop Compat dep * Update travis
1 parent ef129b7 commit a94fed9

File tree

4 files changed

+18
-43
lines changed

4 files changed

+18
-43
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.6
6+
- 0.7
77
- nightly
88
matrix:
99
fast_finish: true

REQUIRE

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.59.0
1+
julia 0.7

src/Polynomials.jl

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
# Poly type manipulations
22

3-
VERSION < v"0.7.0-beta2.199" && __precompile__()
4-
53
module Polynomials
64
#todo: sparse polynomials?
75

8-
using Compat
9-
106
export Poly, poly
117
export degree, coeffs, variable, printpoly
128
export polyval, polyint, polyder, roots, polyfit
139
export Pade, padeval
1410

15-
import Compat.lastindex
16-
17-
import Base: length, size, eltype, collect, eachindex
11+
import Base: length, size, eltype, collect, eachindex, lastindex
1812
import Base: getindex, setindex!, copy, zero, one, convert, gcd
1913
import Base: show, print, *, /, //, -, +, ==, isapprox, divrem, div, rem, eltype
2014
import Base: promote_rule, truncate, chop, conj, transpose, hash
2115
import Base: isequal
22-
import Compat.LinearAlgebra: norm, dot, eigvals, diagm, vecnorm, qrfact
16+
import LinearAlgebra: norm, dot, eigvals, diagm
2317

2418
const SymbolLike = Union{AbstractString,Char,Symbol}
2519

@@ -145,16 +139,9 @@ eltype(::Type{Poly{T}}) where {T} = Poly{T}
145139
length(p::Poly) = length(coeffs(p))
146140
lastindex(p::Poly) = length(p) - 1
147141

148-
if VERSION < v"0.7.0-DEV.5126"
149-
import Base: start, next, done
150-
start(p::Poly) = start(coeffs(p)) - 1
151-
next(p::Poly, state) = (temp = fill!(similar(coeffs(p)), 0); temp[state+1] = p[state]; (Poly(temp), state+1))
152-
done(p::Poly, state) = state > degree(p)
153-
else
154-
import Base: iterate
155-
Base.iterate(p::Poly) = (p[0] * one(p), 1)
156-
Base.iterate(p::Poly, state) = state <= degree(p) ? (p[state]*variable(p)^(state), state+1) : nothing
157-
end
142+
import Base: iterate
143+
Base.iterate(p::Poly) = (p[0] * one(p), 1)
144+
Base.iterate(p::Poly, state) = state <= degree(p) ? (p[state]*variable(p)^(state), state+1) : nothing
158145

159146
# shortcut for collect(eltype, collection)
160147
collect(p::Poly{T}) where {T} = collect(Poly{T}, p)
@@ -405,14 +392,14 @@ rem(num::Poly, den::Poly) = divrem(num, den)[2]
405392
==(n::Number, p1::Poly) = (p1 == n)
406393

407394
"""
408-
isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; rtol::Real = Base.rtoldefault(T,S, 0), atol::Real = 0, norm::Function = vecnorm)
395+
isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; rtol::Real = Base.rtoldefault(T,S, 0), atol::Real = 0, norm::Function = norm)
409396
410397
Truncate polynomials `p1` and `p2`, and compare the coefficient vectors using the
411398
given `norm` function. The tolerances `rtol` and `atol` are passed to both
412399
`truncate` and `isapprox`.
413400
"""
414401
function isapprox(p1::Poly{T}, p2::Poly{S};
415-
rtol::Real = (Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = vecnorm) where {T,S}
402+
rtol::Real = (Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = norm) where {T,S}
416403
p1.var == p2.var || error("Polynomials must have same variable")
417404
p1t = truncate(p1; rtol = rtol, atol = atol)
418405
p2t = truncate(p2; rtol = rtol, atol = atol)
@@ -697,7 +684,7 @@ argument can be used to specify the symbol for the returned polynomial.
697684
# Examples
698685
699686
```julia
700-
julia> xs = linspace(0, pi, 5);
687+
julia> xs = range(0, stop=pi, length=5);
701688
702689
julia> ys = map(sin, xs);
703690

test/runtests.jl

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# assert file to test polynomial implementation
2-
using Compat
3-
using Compat.Test
4-
using Compat.LinearAlgebra
2+
using Test
3+
using LinearAlgebra
54
using Polynomials
65
using SpecialFunctions
76

8-
import Compat.SparseArrays: sparse, speye, nnz
7+
import SparseArrays: sparse, nnz
98

109
pNULL = Poly(Float32[])
1110
p0 = Poly([0])
@@ -158,11 +157,7 @@ println("The approximate sum of the convergent series is: ",exp(1)*(-_γ-sum([(-
158157

159158

160159
## polyfit
161-
if VERSION < v"0.7-"
162-
xs = linspace(0, pi, 10)
163-
else
164-
xs = range(0, stop=pi, length=10)
165-
end
160+
xs = range(0, stop=pi, length=10)
166161

167162
ys = map(sin,xs)
168163
p = polyfit(xs, ys)
@@ -273,21 +268,15 @@ p = Poly([1.0, 0 + NaN*im, NaN, Inf, 0 - Inf*im]) # handle NaN or Inf appropriat
273268

274269
p = Poly([1,2,3])
275270

276-
if VERSION < v"0.7-"
277-
@test reprmime("text/latex", p) == "\$1 + 2\\cdot x + 3\\cdot x^{2}\$"
278-
p = Poly([1//2, 2//3, 1])
279-
@test reprmime("text/latex", p) == "\$\\frac{1}{2} + \\frac{2}{3}\\cdot x + x^{2}\$"
280-
else
281-
@test repr("text/latex", p) == "\$1 + 2\\cdot x + 3\\cdot x^{2}\$"
282-
p = Poly([1//2, 2//3, 1])
283-
@test repr("text/latex", p) == "\$\\frac{1}{2} + \\frac{2}{3}\\cdot x + x^{2}\$"
284-
end
271+
@test repr("text/latex", p) == "\$1 + 2\\cdot x + 3\\cdot x^{2}\$"
272+
p = Poly([1//2, 2//3, 1])
273+
@test repr("text/latex", p) == "\$\\frac{1}{2} + \\frac{2}{3}\\cdot x + x^{2}\$"
285274

286275
# customized printing with printpoly
287276
function printpoly_to_string(args...; kwargs...)
288277
buf = IOBuffer()
289278
printpoly(buf, args...; kwargs...)
290-
return Compat.String(take!(buf))
279+
return String(take!(buf))
291280
end
292281
@test printpoly_to_string(Poly([1,2,3], "y")) == "1 + 2*y + 3*y^2"
293282
@test printpoly_to_string(Poly([1,2,3], "y"), descending_powers=true) == "3*y^2 + 2*y + 1"

0 commit comments

Comments
 (0)