Skip to content

Commit 3077036

Browse files
committed
misc v0.7 deprecation fixes
1 parent a89aa96 commit 3077036

17 files changed

+89
-93
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
julia 0.6.0
2-
Compat 0.31.0
2+
Compat 0.45.0
33
StaticArrays 0.5.0
44
DiffResults 0.0.1
55
DiffRules 0.0.1

docs/src/user/advanced.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ SIMD instructions (i.e. not starting Julia with `-O3`):
219219
julia> using ForwardDiff: Dual
220220

221221
julia> a = Dual(1., 2., 3., 4.)
222-
Dual{Void}(1.0,2.0,3.0,4.0)
222+
Dual{Nothing}(1.0,2.0,3.0,4.0)
223223

224224
julia> b = Dual(5., 6., 7., 8.)
225-
Dual{Void}(5.0,6.0,7.0,8.0)
225+
Dual{Nothing}(5.0,6.0,7.0,8.0)
226226

227227
julia> @code_llvm a + b
228228

src/config.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Tag(f::F, ::Type{V}) where {F,V}
1818
Tag{F,V}()
1919
end
2020

21-
Tag(::Void, ::Type{V}) where {V} = nothing
21+
Tag(::Nothing, ::Type{V}) where {V} = nothing
2222

2323

2424
@inline function (::Type{Tag{F1,V1}}, ::Type{Tag{F2,V2}}) where {F1,V1,F2,V2}

src/dual.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
@inline (::Type{Dual{T}})(value::Real, partials::Real...) where {T} = Dual{T}(value, partials)
4747
@inline (::Type{Dual{T}})(value::V, ::Chunk{N}, p::Val{i}) where {T,V<:Real,N,i} = Dual{T}(value, single_seed(Partials{N,V}, p))
4848

49-
@inline Dual(args...) = Dual{Void}(args...)
49+
@inline Dual(args...) = Dual{Nothing}(args...)
5050

5151
##############################
5252
# Utility/Accessor Functions #
@@ -84,8 +84,8 @@ partials(::Type{T}, d::Dual{S}, i...) where {T,S} = throw(DualMismatchError(T,S)
8484
@inline valtype(::Dual{T,V,N}) where {T,V,N} = V
8585
@inline valtype(::Type{Dual{T,V,N}}) where {T,V,N} = V
8686

87-
@inline tagtype(::V) where {V} = Void
88-
@inline tagtype(::Type{V}) where {V} = Void
87+
@inline tagtype(::V) where {V} = Nothing
88+
@inline tagtype(::Type{V}) where {V} = Nothing
8989
@inline tagtype(::Dual{T,V,N}) where {T,V,N} = T
9090
@inline tagtype(::Type{Dual{T,V,N}}) where {T,V,N} = T
9191

@@ -302,11 +302,11 @@ for R in (:BigFloat, :Bool, :Irrational, :Real)
302302
end
303303

304304
Base.convert(::Type{Dual{T,V,N}}, d::Dual{T}) where {T,V<:Real,N} = Dual{T}(convert(V, value(d)), convert(Partials{N,V}, partials(d)))
305-
Base.convert(::Type{Dual{T,V,N}}, x::Real) where {T,V<:Real,N} = Dual{T}(V(x), zero(Partials{N,V}))
305+
Base.convert(::Type{Dual{T,V,N}}, x::Real) where {T,V<:Real,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
306306
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
307307

308-
Base.float(d::Dual{T,V,N}) where {T,V,N} = Dual{T,promote_type(V, Float16),N}(d)
309-
Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = Dual{T,promote_type(V, Float16),N}(d)
308+
Base.float(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)
309+
Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)
310310

311311
###################################
312312
# General Mathematical Operations #

src/gradient.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ function extract_gradient!(::Type{T}, result::DiffResult, dual::Dual) where {T}
7070
return result
7171
end
7272

73-
extract_gradient!(::Type{T}, result::AbstractArray, y::Real) where {T} =
74-
fill!(result, zero(y))
75-
extract_gradient!(::Type{T}, result::AbstractArray, dual::Dual) where {T}=
76-
copy!(result, partials(T, dual))
73+
extract_gradient!(::Type{T}, result::AbstractArray, y::Real) where {T} = fill!(result, zero(y))
74+
extract_gradient!(::Type{T}, result::AbstractArray, dual::Dual) where {T}= copyto!(result, partials(T, dual))
7775

7876
function extract_gradient_chunk!(::Type{T}, result, dual, index, chunksize) where {T}
7977
offset = index - 1

test/ConfusionTest.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module ConfusionTest
22

3-
using Base.Test
3+
using Compat
4+
using Compat.Test
45
using ForwardDiff
56

6-
using Base.Test
7-
8-
97
# Perturbation Confusion (Issue #83) #
108
#------------------------------------#
119

@@ -37,13 +35,13 @@ L(t,q,q̇) = m/2 * dot(q̇,q̇) - m*g*q[2]
3735

3836
∂L∂q̇(L, t, q, q̇) = ForwardDiff.gradient(a->L(t,q,a), q̇)
3937
Dqq̇(L, t, q, q̇) = ForwardDiff.jacobian(a->∂L∂q̇(L,t,a,q̇), q)
40-
@test Dqq̇(L, t, q, q̇) == zeros(2,2)
38+
@test Dqq̇(L, t, q, q̇) == fill(0.0, 2, 2)
4139

4240

4341
q = [1,2]
4442
p = [5,6]
4543
function Legendre_transformation(F, w)
46-
z = zeros(w)
44+
z = fill(0.0, size(w))
4745
M = ForwardDiff.hessian(F, z)
4846
b = ForwardDiff.gradient(F, z)
4947
v = cholfact(M)\(w-b)

test/DeprecatedTest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module DeprecatedTest
22

3-
using Base.Test
3+
using Compat
4+
using Compat.Test
45
using ForwardDiff, DiffResults
56

67
using ForwardDiff: AbstractConfig, GradientConfig,

test/DerivativeTest.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module DerivativeTest
22

33
import Calculus
44

5-
using Base.Test
5+
using Compat
6+
using Compat.Test
67
using ForwardDiff
78
using DiffTests
89

@@ -49,7 +50,7 @@ end
4950
for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
5051
println(" ...testing $f!")
5152
m, n = 3, 2
52-
y = zeros(m, n)
53+
y = fill(0.0, m, n)
5354
f = x -> (tmp = similar(y, promote_type(eltype(y), typeof(x)), m, n); f!(tmp, x); tmp)
5455
v = f(x)
5556
cfg = ForwardDiff.DerivativeConfig(f!, y, x)

test/DualTest.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module DualTest
22

3-
using Base.Test
3+
using Compat
4+
using Compat.Test
45
using ForwardDiff
56
using ForwardDiff: Partials, Dual, value, partials
67

@@ -301,8 +302,8 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
301302
@test convert(Dual{TestTag(),Dual{TestTag(),V,M},N}, NESTED_FDNUM) === NESTED_FDNUM
302303
@test convert(Dual{TestTag(),WIDE_T,N}, PRIMAL) === Dual{TestTag()}(WIDE_T(PRIMAL), zero(Partials{N,WIDE_T}))
303304
@test convert(Dual{TestTag(),Dual{TestTag(),WIDE_T,M},N}, PRIMAL) === Dual{TestTag()}(Dual{TestTag()}(WIDE_T(PRIMAL), zero(Partials{M,WIDE_T})), zero(Partials{N,Dual{TestTag(),V,M}}))
304-
@test convert(Dual{TestTag(),Dual{TestTag(),V,M},N}, FDNUM) === Dual{TestTag()}(Dual{TestTag(),V,M}(PRIMAL), convert(Partials{N,Dual{TestTag(),V,M}}, PARTIALS))
305-
@test convert(Dual{TestTag(),Dual{TestTag(),WIDE_T,M},N}, FDNUM) === Dual{TestTag()}(Dual{TestTag(),WIDE_T,M}(PRIMAL), convert(Partials{N,Dual{TestTag(),WIDE_T,M}}, PARTIALS))
305+
@test convert(Dual{TestTag(),Dual{TestTag(),V,M},N}, FDNUM) === Dual{TestTag()}(convert(Dual{TestTag(),V,M}, PRIMAL), convert(Partials{N,Dual{TestTag(),V,M}}, PARTIALS))
306+
@test convert(Dual{TestTag(),Dual{TestTag(),WIDE_T,M},N}, FDNUM) === Dual{TestTag()}(convert(Dual{TestTag(),WIDE_T,M}, PRIMAL), convert(Partials{N,Dual{TestTag(),WIDE_T,M}}, PARTIALS))
306307

307308
##############
308309
# Arithmetic #

test/GradientTest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module GradientTest
22

33
import Calculus
44

5-
using Base.Test
5+
using Compat
6+
using Compat.Test
67
using ForwardDiff
78
using ForwardDiff: Dual, Tag
89
using StaticArrays

test/HessianTest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module HessianTest
22

33
import Calculus
44

5-
using Base.Test
5+
using Compat
6+
using Compat.Test
67
using ForwardDiff
78
using ForwardDiff: Dual, Tag
89
using StaticArrays

test/JacobianTest.jl

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module JacobianTest
22

33
import Calculus
44

5-
using Base.Test
5+
using Compat
6+
using Compat.Test
67
using ForwardDiff
78
using ForwardDiff: Dual, Tag, JacobianConfig
89
using StaticArrays
@@ -22,7 +23,7 @@ f! = (y, x) -> begin
2223
y[4] = x[3]
2324
return nothing
2425
end
25-
f = x -> (y = zeros(promote_type(eltype(x), Float64), 4); f!(y, x); return y)
26+
f = x -> (y = fill(zero(promote_type(eltype(x), Float64)), 4); f!(y, x); return y)
2627
x = [1, 2, 3]
2728
v = f(x)
2829
j = [0.8242369704835132 0.4121184852417566 -10.933563142616123
@@ -34,7 +35,7 @@ for c in (1, 2, 3), tags in ((nothing, nothing),
3435
(Tag(f, eltype(x)), Tag(f!, eltype(x))))
3536
println(" ...running hardcoded test with chunk size = $c and tag = $tags")
3637
cfg = JacobianConfig(f, x, ForwardDiff.Chunk{c}(), tags[1])
37-
ycfg = JacobianConfig(f!, zeros(4), x, ForwardDiff.Chunk{c}(), tags[2])
38+
ycfg = JacobianConfig(f!, fill(0.0, 4), x, ForwardDiff.Chunk{c}(), tags[2])
3839

3940
@test eltype(cfg) == Dual{typeof(tags[1]), eltype(x), c}
4041
@test eltype(ycfg) == Dual{typeof(tags[2]), eltype(x), c}
@@ -43,47 +44,47 @@ for c in (1, 2, 3), tags in ((nothing, nothing),
4344
@test isapprox(j, ForwardDiff.jacobian(f, x, cfg))
4445
@test isapprox(j, ForwardDiff.jacobian(f, x))
4546

46-
out = zeros(4, 3)
47+
out = fill(0.0, 4, 3)
4748
ForwardDiff.jacobian!(out, f, x, cfg)
4849
@test isapprox(out, j)
4950

50-
out = zeros(4, 3)
51+
out = fill(0.0, 4, 3)
5152
ForwardDiff.jacobian!(out, f, x)
5253
@test isapprox(out, j)
5354

54-
out = DiffResults.JacobianResult(zeros(4), zeros(3))
55+
out = DiffResults.JacobianResult(fill(0.0, 4), fill(0.0, 3))
5556
ForwardDiff.jacobian!(out, f, x, cfg)
5657
@test isapprox(DiffResults.value(out), v)
5758
@test isapprox(DiffResults.jacobian(out), j)
5859

5960
# testing f!(y, x)
60-
y = zeros(4)
61+
y = fill(0.0, 4)
6162
@test isapprox(j, ForwardDiff.jacobian(f!, y, x, ycfg))
6263
@test isapprox(v, y)
6364

64-
y = zeros(4)
65+
y = fill(0.0, 4)
6566
@test isapprox(j, ForwardDiff.jacobian(f!, y, x))
6667
@test isapprox(v, y)
6768

68-
out, y = zeros(4, 3), zeros(4)
69+
out, y = fill(0.0, 4, 3), fill(0.0, 4)
6970
ForwardDiff.jacobian!(out, f!, y, x, ycfg)
7071
@test isapprox(out, j)
7172
@test isapprox(y, v)
7273

73-
out, y = zeros(4, 3), zeros(4)
74+
out, y = fill(0.0, 4, 3), fill(0.0, 4)
7475
ForwardDiff.jacobian!(out, f!, y, x)
7576
@test isapprox(out, j)
7677
@test isapprox(y, v)
7778

78-
out = DiffResults.JacobianResult(zeros(4), zeros(3))
79-
y = zeros(4)
79+
out = DiffResults.JacobianResult(fill(0.0, 4), fill(0.0, 3))
80+
y = fill(0.0, 4)
8081
ForwardDiff.jacobian!(out, f!, y, x, ycfg)
8182
@test DiffResults.value(out) == y
8283
@test isapprox(y, v)
8384
@test isapprox(DiffResults.jacobian(out), j)
8485

85-
out = DiffResults.JacobianResult(zeros(4), zeros(3))
86-
y = zeros(4)
86+
out = DiffResults.JacobianResult(fill(0.0, 4), fill(0.0, 3))
87+
y = fill(0.0, 4)
8788
ForwardDiff.jacobian!(out, f!, y, x)
8889
@test DiffResults.value(out) == y
8990
@test isapprox(y, v)
@@ -125,33 +126,33 @@ for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
125126
end
126127

127128
for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
128-
v = zeros(Y)
129+
v = fill!(similar(Y), 0.0)
129130
f!(v, X)
130-
j = ForwardDiff.jacobian(f!, zeros(Y), X)
131-
@test isapprox(j, Calculus.jacobian(x -> (y = zeros(Y); f!(y, x); vec(y)), X, :forward), atol=FINITEDIFF_ERROR)
131+
j = ForwardDiff.jacobian(f!, fill!(similar(Y), 0.0), X)
132+
@test isapprox(j, Calculus.jacobian(x -> (y = fill!(similar(Y), 0.0); f!(y, x); vec(y)), X, :forward), atol=FINITEDIFF_ERROR)
132133
for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
133134
println(" ...testing $(f!) with chunk size = $c and tag = $tag")
134-
ycfg = JacobianConfig(f!, zeros(Y), X, ForwardDiff.Chunk{c}(), tag)
135+
ycfg = JacobianConfig(f!, fill!(similar(Y), 0.0), X, ForwardDiff.Chunk{c}(), tag)
135136

136-
y = zeros(Y)
137+
y = fill!(similar(Y), 0.0)
137138
out = ForwardDiff.jacobian(f!, y, X, ycfg)
138139
@test isapprox(y, v)
139140
@test isapprox(out, j)
140141

141-
y = zeros(Y)
142+
y = fill!(similar(Y), 0.0)
142143
out = similar(Y, length(Y), length(X))
143144
ForwardDiff.jacobian!(out, f!, y, X)
144145
@test isapprox(y, v)
145146
@test isapprox(out, j)
146147

147-
y = zeros(Y)
148+
y = fill!(similar(Y), 0.0)
148149
out = DiffResults.JacobianResult(y, X)
149150
ForwardDiff.jacobian!(out, f!, y, X)
150151
@test DiffResults.value(out) == y
151152
@test isapprox(y, v)
152153
@test isapprox(DiffResults.jacobian(out), j)
153154

154-
y = zeros(Y)
155+
y = fill!(similar(Y), 0.0)
155156
out = DiffResults.JacobianResult(y, X)
156157
ForwardDiff.jacobian!(out, f!, y, X, ycfg)
157158
@test DiffResults.value(out) == y
@@ -205,7 +206,7 @@ result3 = ForwardDiff.jacobian!(result3, diff, sx, scfg)
205206
@test DiffResults.jacobian(result2) == DiffResults.jacobian(result)
206207
@test DiffResults.jacobian(result3) == DiffResults.jacobian(result)
207208

208-
sy = zeros(SVector{6,eltype(sx)})
209+
sy = @SVector fill(zero(eltype(sx)), 6)
209210
sresult1 = DiffResults.JacobianResult(sy, sx)
210211
sresult2 = DiffResults.JacobianResult(sy, sx)
211212
sresult3 = DiffResults.JacobianResult(sy, sx)

test/MiscTest.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module MiscTest
22

33
import NaNMath
44

5-
using Base.Test
5+
using Compat
6+
using Compat.Test
67
using ForwardDiff
78
using DiffTests
89

@@ -110,8 +111,8 @@ jinvx = ForwardDiff.jacobian(inv, x)
110111
#-----------------------------------#
111112

112113
N = 4
113-
a = ones(N)
114-
jac0 = reshape(vcat([[zeros(N*(i-1)); a; zeros(N^2-N*i)] for i = 1:N]...), N^2, N)
114+
a = fill(1.0, N)
115+
jac0 = reshape(vcat([[fill(0.0, N*(i-1)); a; fill(0.0, N^2-N*i)] for i = 1:N]...), N^2, N)
115116

116117
for op in (:-, :+, :.-, :.+, :./, :.*)
117118
f = @eval x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)]
@@ -146,7 +147,7 @@ z267 = ([(1, (2), [(3, (4, 5, [1, 2, (3, (4, 5), [5])]), (5))])])
146147
let z = z267
147148
g = x -> f267(z, x)
148149
h = x -> g(x)
149-
@test ForwardDiff.hessian(h, [1.]) == zeros(1, 1)
150+
@test ForwardDiff.hessian(h, [1.]) == fill(0.0, 1, 1)
150151
end
151152

152153
# issue #290

test/PartialsTest.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
module PartialsTest
22

3-
using Base.Test
3+
using Compat
4+
using Compat.Test
45
using ForwardDiff
5-
using ForwardDiff.Partials
6+
using ForwardDiff: Partials
67

78
samerng() = MersenneTwister(1)
89

910
for N in (0, 3), T in (Int, Float32, Float64)
1011
println(" ...testing Partials{$N,$T}")
1112

12-
VALUES = (rand(T,N)...)
13+
VALUES = (rand(T,N)...,)
1314
PARTIALS = Partials{N,T}(VALUES)
1415

15-
VALUES2 = (rand(T,N)...)
16+
VALUES2 = (rand(T,N)...,)
1617
PARTIALS2 = Partials{N,T}(VALUES2)
1718

1819
##############################
@@ -122,7 +123,7 @@ for N in (0, 3), T in (Int, Float32, Float64)
122123
@test ForwardDiff._mul_partials(PARTIALS, ZERO_PARTIALS, X, Y) == X * PARTIALS
123124

124125
if ForwardDiff.NANSAFE_MODE_ENABLED
125-
ZEROS = Partials((zeros(T, N)...))
126+
ZEROS = Partials((fill(zero(T), N)...,))
126127

127128
@test (NaN * ZEROS).values == ZEROS.values
128129
@test (Inf * ZEROS).values == ZEROS.values

test/SIMDTest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SIMDTest
22

3-
using Base.Test
3+
using Compat
4+
using Compat.Test
45
using ForwardDiff: Dual, valtype
56

67
const DUALS = (Dual(1., 2., 3., 4.),

0 commit comments

Comments
 (0)