diff --git a/REQUIRE b/REQUIRE index 387d5ce3..84cac9fa 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.7-beta2 +julia 0.7-rc3 StaticArrays 0.5.0 DiffResults 0.0.1 DiffRules 0.0.4 diff --git a/src/ForwardDiff.jl b/src/ForwardDiff.jl index f41a361a..cfafe6a5 100644 --- a/src/ForwardDiff.jl +++ b/src/ForwardDiff.jl @@ -1,5 +1,3 @@ -__precompile__() - module ForwardDiff using DiffRules, DiffResults @@ -20,7 +18,6 @@ include("derivative.jl") include("gradient.jl") include("jacobian.jl") include("hessian.jl") -include("deprecated.jl") export DiffResults diff --git a/src/deprecated.jl b/src/deprecated.jl deleted file mode 100644 index e2d72568..00000000 --- a/src/deprecated.jl +++ /dev/null @@ -1,39 +0,0 @@ -######################################################### -# Config{N}(args...) --> Config(f, args..., Chunk{N}()) # -######################################################### - -function GradientConfig{N}(x) where N - msg = "GradientConfig{N}(x) is deprecated; use GradientConfig(nothing, x, Chunk{N}()) instead." - Base.depwarn(msg, :GradientConfig) - return GradientConfig(nothing, x, Chunk{N}()) -end - -function JacobianConfig{N}(x) where N - msg = "JacobianConfig{N}(x) is deprecated; use JacobianConfig(nothing, x, Chunk{N}()) instead." - Base.depwarn(msg, :JacobianConfig) - return JacobianConfig(nothing, x, Chunk{N}()) -end - -function JacobianConfig{N}(y, x) where N - msg = "JacobianConfig{N}(y, x) is deprecated; use JacobianConfig(nothing, y, x, Chunk{N}()) instead." - Base.depwarn(msg, :JacobianConfig) - return JacobianConfig(nothing, y, x, Chunk{N}()) -end - -function HessianConfig{N}(x) where N - msg = "HessianConfig{N}(x) is deprecated; use HessianConfig(nothing, x, Chunk{N}()) instead." - Base.depwarn(msg, :HessianConfig) - return HessianConfig(nothing, x, Chunk{N}()) -end - -function HessianConfig{N}(out, x) where N - msg = "HessianConfig{N}(out, x) is deprecated; use HessianConfig(nothing, out, x, Chunk{N}()) instead." - Base.depwarn(msg, :HessianConfig) - return HessianConfig(nothing, out, x, Chunk{N}()) -end - -function MultithreadConfig(cfg::AbstractConfig) - msg = "MultithreadConfig(cfg) is deprecated; use cfg instead (ForwardDiff no longer implements experimental multithreading)." - Base.depwarn(msg, :MultithreadConfig) - return cfg -end diff --git a/src/dual.jl b/src/dual.jl index e21b2b71..4beed70e 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -254,10 +254,10 @@ end @inline Base.one(d::Dual) = one(typeof(d)) @inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V})) -@inline Base.rand(d::Dual) = rand(typeof(d)) -@inline Base.rand(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(V), zero(Partials{N,V})) -@inline Base.rand(rng::AbstractRNG, d::Dual) = rand(rng, typeof(d)) -@inline Base.rand(rng::AbstractRNG, ::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(rng, V), zero(Partials{N,V})) +@inline Random.rand(d::Dual) = rand(typeof(d)) +@inline Random.rand(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(V), zero(Partials{N,V})) +@inline Random.rand(rng::AbstractRNG, d::Dual) = rand(rng, typeof(d)) +@inline Random.rand(rng::AbstractRNG, ::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(rng, V), zero(Partials{N,V})) # Predicates # #------------# diff --git a/src/partials.jl b/src/partials.jl index dfb0d577..5734a434 100644 --- a/src/partials.jl +++ b/src/partials.jl @@ -22,9 +22,8 @@ end @inline Base.@propagate_inbounds Base.getindex(partials::Partials, i::Int) = partials.values[i] -Base.start(partials::Partials) = start(partials.values) -Base.next(partials::Partials, i) = next(partials.values, i) -Base.done(partials::Partials, i) = done(partials.values, i) +Base.iterate(partials::Partials) = iterate(partials.values) +Base.iterate(partials::Partials, i) = iterate(partials.values, i) Base.IndexStyle(::Type{<:Partials}) = IndexLinear() diff --git a/test/DeprecatedTest.jl b/test/DeprecatedTest.jl deleted file mode 100644 index 561d19fc..00000000 --- a/test/DeprecatedTest.jl +++ /dev/null @@ -1,44 +0,0 @@ -module DeprecatedTest - -using Test -using ForwardDiff, DiffResults - -using ForwardDiff: AbstractConfig, GradientConfig, - JacobianConfig, HessianConfig, - MultithreadConfig - -include(joinpath(dirname(@__FILE__), "utils.jl")) - -function similar_duals(a::AbstractArray, b::AbstractArray) - return typeof(a) == typeof(b) && size(a) == size(b) -end - -similar_duals(a::Tuple, b::Tuple) = all(similar_duals.(a, b)) - -function similar_config(a::AbstractConfig, b::AbstractConfig) - return a.seeds == b.seeds && similar_duals(a.duals, b.duals) -end - -function similar_config(a::HessianConfig, b::HessianConfig) - return (similar_config(a.gradient_config, b.gradient_config) && - similar_config(a.jacobian_config, b.jacobian_config)) -end - -x = rand(3) -y = rand(3) -out = DiffResults.HessianResult(x) -N = 1 -chunk = ForwardDiff.Chunk{N}() - -@info("The following tests print lots of deprecation warnings on purpose.") - -@test similar_config(GradientConfig{N}(x), GradientConfig(nothing, x, chunk)) -@test similar_config(JacobianConfig{N}(x), JacobianConfig(nothing, x, chunk)) -@test similar_config(JacobianConfig{N}(y, x), JacobianConfig(nothing, y, x, chunk)) -@test similar_config(HessianConfig{N}(x), HessianConfig(nothing, x, chunk)) -@test similar_config(HessianConfig{N}(out, x), HessianConfig(nothing, out, x, chunk)) -@test similar_config(MultithreadConfig(GradientConfig(nothing, x, chunk)), GradientConfig(nothing, x, chunk)) - -@info("Deprecation testing is now complete, so any further deprecation warnings are real.") - -end # module diff --git a/test/DerivativeTest.jl b/test/DerivativeTest.jl index 463d74b7..513cf80e 100644 --- a/test/DerivativeTest.jl +++ b/test/DerivativeTest.jl @@ -9,7 +9,7 @@ using DiffTests include(joinpath(dirname(@__FILE__), "utils.jl")) -srand(1) +Random.seed!(1) ######################## # test vs. Calculus.jl # diff --git a/test/DualTest.jl b/test/DualTest.jl index d7941b9b..0312ce5e 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -419,12 +419,12 @@ for N in (0,3), M in (0,4), V in (Int, Float32) if isnan(actualdx) @test isnan(partials(dx, 1)) else - @test partials(dx, 1) == actualdx + @test partials(dx, 1) ≈ actualdx end if isnan(actualdy) @test isnan(partials(dy, 1)) else - @test partials(dy, 1) == actualdy + @test partials(dy, 1) ≈ actualdy end end end diff --git a/test/GradientTest.jl b/test/GradientTest.jl index d503da83..bba52429 100644 --- a/test/GradientTest.jl +++ b/test/GradientTest.jl @@ -138,5 +138,4 @@ sresult3 = ForwardDiff.gradient!(sresult3, prod, sx, scfg) @test DiffResults.gradient(sresult2) == DiffResults.gradient(result) @test DiffResults.gradient(sresult3) == DiffResults.gradient(result) - end # module diff --git a/test/MiscTest.jl b/test/MiscTest.jl index c27e4fa8..2a22cb2f 100644 --- a/test/MiscTest.jl +++ b/test/MiscTest.jl @@ -115,9 +115,11 @@ a = fill(1.0, N) jac0 = reshape(vcat([[fill(0.0, N*(i-1)); a; fill(0.0, N^2-N*i)] for i = 1:N]...), N^2, N) for op in (:.-, :.+, :./, :.*) - f = @eval x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)] - jac = @eval ForwardDiff.jacobian(f, a) - @test isapprox(jac0, jac) + @eval begin + f = x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)] + jac = ForwardDiff.jacobian(f, a) + @test isapprox(jac0, jac) + end end # NaNs # @@ -133,8 +135,10 @@ h = ForwardDiff.hessian(y -> sum(hypot.(x, y)), y) @test h[1, 1] ≈ (x[1]^2) / (x[1]^2 + y[1]^2)^(3/2) @test h[2, 2] ≈ (x[2]^2) / (x[2]^2 + y[2]^2)^(3/2) @test h[3, 3] ≈ (x[3]^2) / (x[3]^2 + y[3]^2)^(3/2) -for i in 1:3, j in 1:3 - i != j && (@test h[i, j] ≈ 0.0) +let i, j + for i in 1:3, j in 1:3 + i != j && @test h[i, j] ≈ 0.0 + end end ######## @@ -144,8 +148,8 @@ end # issue 267 @noinline f267(z, x) = x[1] z267 = ([(1, (2), [(3, (4, 5, [1, 2, (3, (4, 5), [5])]), (5))])]) -let z = z267 - g = x -> f267(z, x) +let z = z267, + g = x -> f267(z, x), h = x -> g(x) @test ForwardDiff.hessian(h, [1.]) == fill(0.0, 1, 1) end diff --git a/test/PartialsTest.jl b/test/PartialsTest.jl index 20f7b265..c6ff0e8b 100644 --- a/test/PartialsTest.jl +++ b/test/PartialsTest.jl @@ -36,10 +36,6 @@ for N in (0, 3), T in (Int, Float32, Float64) @test PARTIALS[i] == VALUES[i] end - @test start(PARTIALS) == start(VALUES) - @test N == 0 || (next(PARTIALS, start(PARTIALS)) == next(VALUES, start(VALUES))) - @test done(PARTIALS, start(PARTIALS)) == done(VALUES, start(VALUES)) - i = 1 for p in PARTIALS @test p == VALUES[i] diff --git a/test/runtests.jl b/test/runtests.jl index 0514985a..f33fefc7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,7 +5,7 @@ t = @elapsed include("PartialsTest.jl") println("done (took $t seconds).") println("Testing Dual...") -# t = @elapsed include("DualTest.jl") +t = @elapsed include("DualTest.jl") println("done (took $t seconds).") println("Testing derivative functionality...") @@ -37,7 +37,3 @@ if Base.JLOptions().opt_level >= 3 t = @elapsed include("SIMDTest.jl") println("done (took $t seconds).") end - -println("Testing deprecations...") -t = @elapsed include("DeprecatedTest.jl") -println("done (took $t seconds).") diff --git a/test/utils.jl b/test/utils.jl index 13350da0..ff31550f 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -5,7 +5,7 @@ using Random # seed RNG, thus making result inaccuracies deterministic # so we don't have to retune EPS for arbitrary inputs -srand(1) +Random.seed!(1) const XLEN = DEFAULT_CHUNK_THRESHOLD + 1 const YLEN = div(DEFAULT_CHUNK_THRESHOLD, 2) + 1