Skip to content

Commit e71569d

Browse files
authored
Fix 0.7 depwarns (#122)
1 parent 9dcb3ca commit e71569d

File tree

10 files changed

+41
-33
lines changed

10 files changed

+41
-33
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.6
2-
Compat 0.17.0
2+
Compat 0.62.0

src/Calculus.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__precompile__()
22
module Calculus
3-
import Compat
3+
using Compat
44
export check_derivative,
55
check_gradient,
66
check_hessian,
@@ -54,8 +54,8 @@ module Calculus
5454
include("finite_difference.jl")
5555
include("derivative.jl")
5656
include("check_derivative.jl")
57-
@Base.deprecate integrate(f,a,b) quadgk(f,a,b)[1]
58-
@Base.deprecate integrate(f,a,b,method) quadgk(f,a,b)[1]
57+
Base.@deprecate integrate(f,a,b) quadgk(f,a,b)[1]
58+
Base.@deprecate integrate(f,a,b,method) quadgk(f,a,b)[1]
5959
include("symbolic.jl")
6060
include("differentiate.jl")
6161
include("deparse.jl")

src/deparse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const op_precedence = Compat.@compat Dict(:+ => 1, :- => 1, :* => 2, :/ => 2, :^ => 3)
1+
const op_precedence = Dict(:+ => 1, :- => 1, :* => 2, :/ => 2, :^ => 3)
22

33
function deparse(ex::Expr, outer_precedence=0)
44
if ex.head != :call

src/derivative.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ derivative(f, dtype::Symbol = :central) = derivative(f, :scalar, dtype)
1313
gradient(f, x::Union{T, Vector{T}}, dtype::Symbol = :central) where {T <: Number} = finite_difference(f, float(x), dtype)
1414
gradient(f, dtype::Symbol = :central) = derivative(f, :vector, dtype)
1515

16-
function Base.gradient(f, x::Union{T, Vector{T}}, dtype::Symbol = :central) where T <: Number
17-
Base.warn_once("The finite difference methods from Calculus.jl no longer extend Base.gradient and should be called as Calculus.gradient instead. This usage is deprecated.")
16+
function Compat.LinearAlgebra.gradient(f, x::Union{T, Vector{T}}, dtype::Symbol = :central) where T <: Number
17+
Base.depwarn("The finite difference methods from Calculus.jl no longer extend " *
18+
"Base.gradient and should be called as Calculus.gradient instead. " *
19+
"This usage is deprecated.", :gradient)
1820
Calculus.gradient(f,x,dtype)
1921
end
2022

21-
function Base.gradient(f, dtype::Symbol = :central)
22-
Base.warn_once("The finite difference methods from Calculus.jl no longer extend Base.gradient and should be called as Calculus.gradient instead. This usage is deprecated.")
23+
function Compat.LinearAlgebra.gradient(f, dtype::Symbol = :central)
24+
Base.depwarn("The finite difference methods from Calculus.jl no longer extend " *
25+
"Base.gradient and should be called as Calculus.gradient instead. " *
26+
"This usage is deprecated.", :gradient)
2327
Calculus.gradient(f,dtype)
2428
end
2529

src/differentiate.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ end
7979
# d/dx (f * g * h) = (d/dx f) * g * h + f * (d/dx g) * h + ...
8080
function differentiate(::SymbolParameter{:*}, args, wrt)
8181
n = length(args)
82-
res_args = Vector{Any}(n)
82+
res_args = Vector{Any}(undef, n)
8383
for i in 1:n
84-
new_args = Vector{Any}(n)
84+
new_args = Vector{Any}(undef, n)
8585
for j in 1:n
8686
if j == i
8787
new_args[j] = differentiate(args[j], wrt)
@@ -196,7 +196,7 @@ export symbolic_derivatives_1arg
196196

197197
# deprecated: for backward compatibility with packages that used
198198
# this unexported interface.
199-
derivative_rules = Vector{Compat.@compat(Tuple{Symbol,Expr})}(0)
199+
derivative_rules = Vector{Tuple{Symbol,Expr}}()
200200
for (s,ex) in symbolic_derivative_1arg_list
201201
push!(derivative_rules, (s, :(xp*$ex)))
202202
end
@@ -263,14 +263,16 @@ end
263263

264264
function differentiate(ex::Expr, targets::Vector{Symbol})
265265
n = length(targets)
266-
exprs = Vector{Any}(n)
266+
exprs = Vector{Any}(undef, n)
267267
for i in 1:n
268268
exprs[i] = differentiate(ex, targets[i])
269269
end
270270
return exprs
271271
end
272272

273273
differentiate(ex::Expr) = differentiate(ex, :x)
274-
differentiate(s::Compat.AbstractString, target...) = differentiate(parse(s), target...)
275-
differentiate(s::Compat.AbstractString, target::Compat.AbstractString) = differentiate(parse(s), symbol(target))
276-
differentiate(s::Compat.AbstractString, targets::Vector{T}) where {T <: Compat.AbstractString} = differentiate(parse(s), map(symbol, targets))
274+
differentiate(s::AbstractString, target...) = differentiate(Compat.Meta.parse(s), target...)
275+
differentiate(s::AbstractString, target::AbstractString) =
276+
differentiate(Compat.Meta.parse(s), Symbol(target))
277+
differentiate(s::AbstractString, targets::Vector{T}) where {T <: AbstractString} =
278+
differentiate(Compat.Meta.parse(s), map(Symbol, targets))

src/finite_difference.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function finite_difference(f,
139139
x::AbstractVector{T},
140140
dtype::Symbol = :central) where T <: Number
141141
# Allocate memory for gradient
142-
g = Vector{Float64}(length(x))
142+
g = Vector{Float64}(undef, length(x))
143143

144144
# Mutate allocated gradient
145145
finite_difference!(f, float(x), g, dtype)
@@ -261,15 +261,15 @@ function finite_difference_hessian!(f,
261261
end
262262
xpp[i], xpm[i], xmp[i], xmm[i] = xi, xi, xi, xi
263263
end
264-
Base.LinAlg.copytri!(H,'U')
264+
Compat.LinearAlgebra.copytri!(H,'U')
265265
end
266266
function finite_difference_hessian(f,
267267
x::AbstractVector{T}) where T <: Number
268268
# What is the dimension of x?
269269
n = length(x)
270270

271271
# Allocate an empty Hessian
272-
H = Matrix{Float64}(n, n)
272+
H = Matrix{Float64}(undef, n, n)
273273

274274
# Mutate the allocated Hessian
275275
finite_difference_hessian!(f, x, H)

src/symbolic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Base.show, Base.(==)
1212
#
1313
#################################################################
1414

15-
Compat.@compat abstract type Symbolic end
16-
Compat.@compat abstract type AbstractVariable <: Symbolic end
15+
abstract type Symbolic end
16+
abstract type AbstractVariable <: Symbolic end
1717
const SymbolicVariable = Union{Symbol, AbstractVariable}
1818

1919

@@ -93,7 +93,7 @@ function simplify(ex::Expr)
9393
return ex
9494
end
9595
if all(isnumber, ex.args[2:end]) && length(ex.args) > 1
96-
return eval(current_module(), ex)
96+
return eval(@__MODULE__, ex)
9797
end
9898
new_ex = simplify(SymbolParameter(ex.args[1]), ex.args[2:end])
9999
while !(isequal(new_ex, ex))

test/deparse.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@test isequal(deparse(:(cos(x) + sin(x))), "cos(x) + sin(x)")
22
@test isequal(deparse(:(cos(x) + sin(x) + exp(-x))), "cos(x) + sin(x) + exp(-x)")
3-
@test isequal(deparse(parse("x+y*z")), "x + y * z")
4-
@test isequal(deparse(parse("(x+y)*z")), "(x + y) * z")
5-
@test isequal(deparse(parse("1/(x/y)")), "1 / (x / y)")
6-
@test isequal(deparse(parse("1/(x*y)")), "1 / (x * y)")
7-
@test isequal(deparse(parse("z^(x+y)")), "z ^ (x + y)")
8-
@test isequal(deparse(parse("z^(x*y)")), "z ^ (x * y)")
3+
@test isequal(deparse(Compat.Meta.parse("x+y*z")), "x + y * z")
4+
@test isequal(deparse(Compat.Meta.parse("(x+y)*z")), "(x + y) * z")
5+
@test isequal(deparse(Compat.Meta.parse("1/(x/y)")), "1 / (x / y)")
6+
@test isequal(deparse(Compat.Meta.parse("1/(x*y)")), "1 / (x * y)")
7+
@test isequal(deparse(Compat.Meta.parse("z^(x+y)")), "z ^ (x + y)")
8+
@test isequal(deparse(Compat.Meta.parse("z^(x*y)")), "z ^ (x * y)")

test/derivative.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ f2(x::Vector) = sin(x[1])
1818
#
1919

2020
f3(x::Real) = sin(x)
21-
for x in linspace(0.0, 0.1, 11) # seq()
22-
@test norm(f3'(x) - cos(x)) < 10e-4
21+
for x in Compat.range(0.0, stop=0.1, length=11) # seq()
22+
@test norm(f3'(x) - cos(x)) < 10e-4
2323
end
2424

2525
#
@@ -35,8 +35,8 @@ f4(x::Vector) = (100.0 - x[1])^2 + (50.0 - x[2])^2
3535
# jacobian()
3636
#
3737

38-
@test norm(Calculus.jacobian(identity, rand(3), :forward) - eye(3)) < 10e-4
39-
@test norm(Calculus.jacobian(identity, rand(3), :central) - eye(3)) < 10e-4
38+
@test norm(Calculus.jacobian(identity, rand(3), :forward) - Matrix(1.0I, 3, 3)) < 10e-4
39+
@test norm(Calculus.jacobian(identity, rand(3), :central) - Matrix(1.0I, 3, 3)) < 10e-4
4040

4141
#
4242
# second_derivative()

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#
44

55
using Calculus
6-
using Base.Test
6+
using Compat
7+
using Compat.Test
8+
using Compat.LinearAlgebra
79

810
tests = ["finite_difference",
911
"derivative",

0 commit comments

Comments
 (0)