Skip to content

Commit 14bb015

Browse files
authored
various fixes for v0.7/1.0 (#340)
* various fixes for v0.7/1.0 * remove old depwarns that have hung around for more than a release cycle * use ≈ instead of == for Dual auto-tests
1 parent 15ce2c7 commit 14bb015

13 files changed

+23
-115
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.7-beta2
1+
julia 0.7-rc3
22
StaticArrays 0.5.0
33
DiffResults 0.0.1
44
DiffRules 0.0.4

src/ForwardDiff.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
__precompile__()
2-
31
module ForwardDiff
42

53
using DiffRules, DiffResults
@@ -20,7 +18,6 @@ include("derivative.jl")
2018
include("gradient.jl")
2119
include("jacobian.jl")
2220
include("hessian.jl")
23-
include("deprecated.jl")
2421

2522
export DiffResults
2623

src/deprecated.jl

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/dual.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ end
254254
@inline Base.one(d::Dual) = one(typeof(d))
255255
@inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V}))
256256

257-
@inline Base.rand(d::Dual) = rand(typeof(d))
258-
@inline Base.rand(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(V), zero(Partials{N,V}))
259-
@inline Base.rand(rng::AbstractRNG, d::Dual) = rand(rng, typeof(d))
260-
@inline Base.rand(rng::AbstractRNG, ::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(rng, V), zero(Partials{N,V}))
257+
@inline Random.rand(d::Dual) = rand(typeof(d))
258+
@inline Random.rand(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(V), zero(Partials{N,V}))
259+
@inline Random.rand(rng::AbstractRNG, d::Dual) = rand(rng, typeof(d))
260+
@inline Random.rand(rng::AbstractRNG, ::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(rng, V), zero(Partials{N,V}))
261261

262262
# Predicates #
263263
#------------#

src/partials.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ end
2222

2323
@inline Base.@propagate_inbounds Base.getindex(partials::Partials, i::Int) = partials.values[i]
2424

25-
Base.start(partials::Partials) = start(partials.values)
26-
Base.next(partials::Partials, i) = next(partials.values, i)
27-
Base.done(partials::Partials, i) = done(partials.values, i)
25+
Base.iterate(partials::Partials) = iterate(partials.values)
26+
Base.iterate(partials::Partials, i) = iterate(partials.values, i)
2827

2928
Base.IndexStyle(::Type{<:Partials}) = IndexLinear()
3029

test/DeprecatedTest.jl

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/DerivativeTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using DiffTests
99

1010
include(joinpath(dirname(@__FILE__), "utils.jl"))
1111

12-
srand(1)
12+
Random.seed!(1)
1313

1414
########################
1515
# test vs. Calculus.jl #

test/DualTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,12 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
419419
if isnan(actualdx)
420420
@test isnan(partials(dx, 1))
421421
else
422-
@test partials(dx, 1) == actualdx
422+
@test partials(dx, 1) actualdx
423423
end
424424
if isnan(actualdy)
425425
@test isnan(partials(dy, 1))
426426
else
427-
@test partials(dy, 1) == actualdy
427+
@test partials(dy, 1) actualdy
428428
end
429429
end
430430
end

test/GradientTest.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,4 @@ sresult3 = ForwardDiff.gradient!(sresult3, prod, sx, scfg)
138138
@test DiffResults.gradient(sresult2) == DiffResults.gradient(result)
139139
@test DiffResults.gradient(sresult3) == DiffResults.gradient(result)
140140

141-
142141
end # module

test/MiscTest.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ a = fill(1.0, N)
115115
jac0 = reshape(vcat([[fill(0.0, N*(i-1)); a; fill(0.0, N^2-N*i)] for i = 1:N]...), N^2, N)
116116

117117
for op in (:.-, :.+, :./, :.*)
118-
f = @eval x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)]
119-
jac = @eval ForwardDiff.jacobian(f, a)
120-
@test isapprox(jac0, jac)
118+
@eval begin
119+
f = x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)]
120+
jac = ForwardDiff.jacobian(f, a)
121+
@test isapprox(jac0, jac)
122+
end
121123
end
122124

123125
# NaNs #
@@ -133,8 +135,10 @@ h = ForwardDiff.hessian(y -> sum(hypot.(x, y)), y)
133135
@test h[1, 1] (x[1]^2) / (x[1]^2 + y[1]^2)^(3/2)
134136
@test h[2, 2] (x[2]^2) / (x[2]^2 + y[2]^2)^(3/2)
135137
@test h[3, 3] (x[3]^2) / (x[3]^2 + y[3]^2)^(3/2)
136-
for i in 1:3, j in 1:3
137-
i != j && (@test h[i, j] 0.0)
138+
let i, j
139+
for i in 1:3, j in 1:3
140+
i != j && @test h[i, j] 0.0
141+
end
138142
end
139143

140144
########
@@ -144,8 +148,8 @@ end
144148
# issue 267
145149
@noinline f267(z, x) = x[1]
146150
z267 = ([(1, (2), [(3, (4, 5, [1, 2, (3, (4, 5), [5])]), (5))])])
147-
let z = z267
148-
g = x -> f267(z, x)
151+
let z = z267,
152+
g = x -> f267(z, x),
149153
h = x -> g(x)
150154
@test ForwardDiff.hessian(h, [1.]) == fill(0.0, 1, 1)
151155
end

test/PartialsTest.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ for N in (0, 3), T in (Int, Float32, Float64)
3636
@test PARTIALS[i] == VALUES[i]
3737
end
3838

39-
@test start(PARTIALS) == start(VALUES)
40-
@test N == 0 || (next(PARTIALS, start(PARTIALS)) == next(VALUES, start(VALUES)))
41-
@test done(PARTIALS, start(PARTIALS)) == done(VALUES, start(VALUES))
42-
4339
i = 1
4440
for p in PARTIALS
4541
@test p == VALUES[i]

test/runtests.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ t = @elapsed include("PartialsTest.jl")
55
println("done (took $t seconds).")
66

77
println("Testing Dual...")
8-
# t = @elapsed include("DualTest.jl")
8+
t = @elapsed include("DualTest.jl")
99
println("done (took $t seconds).")
1010

1111
println("Testing derivative functionality...")
@@ -37,7 +37,3 @@ if Base.JLOptions().opt_level >= 3
3737
t = @elapsed include("SIMDTest.jl")
3838
println("done (took $t seconds).")
3939
end
40-
41-
println("Testing deprecations...")
42-
t = @elapsed include("DeprecatedTest.jl")
43-
println("done (took $t seconds).")

test/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Random
55

66
# seed RNG, thus making result inaccuracies deterministic
77
# so we don't have to retune EPS for arbitrary inputs
8-
srand(1)
8+
Random.seed!(1)
99

1010
const XLEN = DEFAULT_CHUNK_THRESHOLD + 1
1111
const YLEN = div(DEFAULT_CHUNK_THRESHOLD, 2) + 1

0 commit comments

Comments
 (0)