Skip to content

Commit 2fa2a0f

Browse files
yuyichaojrevels
authored andcommitted
Fix most depwarn on 0.6 (#189)
1 parent 791cd93 commit 2fa2a0f

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed

src/config.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ abstract AbstractConfig
1010
# but feature different constructors and dispatch restrictions in downstream code.
1111
for Config in (:GradientConfig, :JacobianConfig)
1212
@eval begin
13-
immutable $Config{N,T,D} <: AbstractConfig
13+
@compat immutable $Config{N,T,D} <: AbstractConfig
1414
seeds::NTuple{N,Partials{N,T}}
1515
duals::D
1616
# disable default outer constructor
17-
$Config(seeds, duals) = new(seeds, duals)
17+
(::Type{$Config{N,T,D}}){N,T,D}(seeds, duals) = new{N,T,D}(seeds, duals)
1818
end
1919

2020
# This is type-unstable, which is why our docs advise users to manually enter a chunk size

src/deprecated.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Base.@deprecate JacobianResult(x) DiffBase.JacobianResult(x)
1414
Base.@deprecate HessianResult(x, y, z) DiffBase.DiffResult(x, y, z)
1515
Base.@deprecate HessianResult(x) DiffBase.HessianResult(x)
1616

17-
immutable Chunk{N}
18-
function Chunk()
17+
@compat immutable Chunk{N}
18+
function (::Type{Chunk{N}}){N}()
1919
Base.depwarn("Chunk{N}() is deprecated, use the ForwardDiff.AbstractConfig API instead.", :Chunk)
20-
return new()
20+
return new{N}()
2121
end
2222
end
2323

test/DerivativeTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for f in DiffBase.NUMBER_TO_NUMBER_FUNCS
1717
println(" ...testing $f")
1818
v = f(x)
1919
d = ForwardDiff.derivative(f, x)
20-
@test_approx_eq_eps d Calculus.derivative(f, x) FINITEDIFF_ERROR
20+
@test isapprox(d, Calculus.derivative(f, x), atol=FINITEDIFF_ERROR)
2121

2222
out = DiffBase.DiffResult(zero(v), zero(v))
2323
ForwardDiff.derivative!(out, f, x)
@@ -29,7 +29,7 @@ for f in DiffBase.NUMBER_TO_ARRAY_FUNCS
2929
println(" ...testing $f")
3030
v = f(x)
3131
d = ForwardDiff.derivative(f, x)
32-
@test_approx_eq_eps d Calculus.derivative(f, x) FINITEDIFF_ERROR
32+
@test isapprox(d, Calculus.derivative(f, x), atol=FINITEDIFF_ERROR)
3333

3434
out = similar(v)
3535
ForwardDiff.derivative!(out, f, x)

test/DualTest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ end
2323
if VERSION < v"0.5"
2424
# isapprox on v0.4 doesn't properly set the tolerance
2525
# for mixed-precision inputs, while @test_approx_eq does
26-
test_approx_diffnums(a::Real, b::Real) = @test_approx_eq a b
26+
# Use @eval to avoid expanding @test_approx_eq on 0.6 where it's deprecated
27+
@eval test_approx_diffnums(a::Real, b::Real) = @test_approx_eq a b
2728
else
2829
test_approx_diffnums(a::Real, b::Real) = @test isapprox(a, b)
2930
end

test/GradientTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
for f in DiffBase.VECTOR_TO_NUMBER_FUNCS
6969
v = f(X)
7070
g = ForwardDiff.gradient(f, X)
71-
@test_approx_eq_eps g Calculus.gradient(f, X) FINITEDIFF_ERROR
71+
@test isapprox(g, Calculus.gradient(f, X), atol=FINITEDIFF_ERROR)
7272
for c in CHUNK_SIZES
7373
println(" ...testing $f with chunk size = $c")
7474
cfg = ForwardDiff.GradientConfig{c}(X)

test/MiscTest.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ N = 4
113113
a = ones(N)
114114
jac0 = reshape(vcat([[zeros(N*(i-1)); a; zeros(N^2-N*i)] for i = 1:N]...), N^2, N)
115115

116-
for op in (-, +, .-, .+, ./, .*)
117-
f = x -> [op(x[1], a); op(x[2], a); op(x[3], a); op(x[4], a)]
118-
jac = ForwardDiff.jacobian(f, a)
116+
for op in (:-, :+, :.-, :.+, :./, :.*)
117+
f = @eval x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)]
118+
jac = @eval ForwardDiff.jacobian(f, a)
119119
@test isapprox(jac0, jac)
120120
end
121121

test/utils.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ const YLEN = div(CHUNK_THRESHOLD, 2) + 1
1111
const X, Y = rand(XLEN), rand(YLEN)
1212
const CHUNK_SIZES = (1, div(CHUNK_THRESHOLD, 3), div(CHUNK_THRESHOLD, 2), CHUNK_THRESHOLD, CHUNK_THRESHOLD + 1)
1313
const FINITEDIFF_ERROR = 1.5e-5
14-
15-
# used to test against results calculated via finite difference
16-
test_approx_eps(a::Array, b::Array) = @test_approx_eq_eps a b EPS

0 commit comments

Comments
 (0)