Skip to content

Commit f3bf6d6

Browse files
Fix deprecations
1 parent 4a5c87b commit f3bf6d6

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ variables. This is summarized as:
3636

3737
```julia
3838
finite_difference_derivative(f, x::T, fdtype::Type{T1}=Val{:central},
39-
returntype::Type{T2}=eltype(x), f_x::Union{Void,T}=nothing)
39+
returntype::Type{T2}=eltype(x), f_x::Union{Nothing,T}=nothing)
4040
```
4141

4242
## Multi-Point Derivatives
@@ -51,17 +51,17 @@ finite_difference_derivative(
5151
x :: AbstractArray{<:Number},
5252
fdtype :: Type{T1} = Val{:central},
5353
returntype :: Type{T2} = eltype(x), # return type of f
54-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
55-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing)
54+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
55+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing)
5656

5757
finite_difference_derivative!(
5858
df :: AbstractArray{<:Number},
5959
f,
6060
x :: AbstractArray{<:Number},
6161
fdtype :: Type{T1} = Val{:central},
6262
returntype :: Type{T2} = eltype(x),
63-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
64-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing)
63+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
64+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing)
6565

6666
# Cached
6767
finite_difference_derivative!(df::AbstractArray{<:Number}, f,
@@ -74,8 +74,8 @@ finite_difference_derivative!(df::AbstractArray{<:Number}, f,
7474
```julia
7575
DerivativeCache(
7676
x :: AbstractArray{<:Number},
77-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
78-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing,
77+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
78+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing,
7979
fdtype :: Type{T1} = Val{:central},
8080
returntype :: Type{T2} = eltype(x))
8181
```
@@ -118,9 +118,9 @@ GradientCache(
118118

119119
```julia
120120
GradientCache(
121-
c1 :: Union{Void,AbstractArray{<:Number}},
122-
c2 :: Union{Void,AbstractArray{<:Number}},
123-
fx :: Union{Void,<:Number,AbstractArray{<:Number}} = nothing,
121+
c1 :: Union{Nothing,AbstractArray{<:Number}},
122+
c2 :: Union{Nothing,AbstractArray{<:Number}},
123+
fx :: Union{Nothing,<:Number,AbstractArray{<:Number}} = nothing,
124124
fdtype :: Type{T1} = Val{:central},
125125
returntype :: Type{T2} = eltype(df),
126126
inplace :: Type{Val{T3}} = Val{true})

src/derivatives.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Single-point derivatives of scalar->scalar maps.
33
=#
44
function finite_difference_derivative(f, x::T, fdtype::Type{T1}=Val{:central},
5-
returntype::Type{T2}=eltype(x), f_x::Union{Void,T}=nothing) where {T<:Number,T1,T2}
5+
returntype::Type{T2}=eltype(x), f_x::Union{Nothing,T}=nothing) where {T<:Number,T1,T2}
66

77
epsilon = compute_epsilon(fdtype, x)
88
if fdtype==Val{:forward}
@@ -27,31 +27,31 @@ end
2727

2828
function DerivativeCache(
2929
x :: AbstractArray{<:Number},
30-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
31-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing,
30+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
31+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing,
3232
fdtype :: Type{T1} = Val{:central},
3333
returntype :: Type{T2} = eltype(x)) where {T1,T2}
3434

3535
if fdtype==Val{:complex} && !(eltype(returntype)<:Real)
3636
fdtype_error(returntype)
3737
end
3838

39-
if fdtype!=Val{:forward} && typeof(fx)!=Void
39+
if fdtype!=Val{:forward} && typeof(fx)!=Nothing
4040
warn("Pre-computed function values are only useful for fdtype==Val{:forward}.")
4141
_fx = nothing
4242
else
4343
# more runtime sanity checks?
4444
_fx = fx
4545
end
4646

47-
if typeof(epsilon)!=Void && typeof(x)<:StridedArray && typeof(fx)<:Union{Void,StridedArray} && 1==2
47+
if typeof(epsilon)!=Nothing && typeof(x)<:StridedArray && typeof(fx)<:Union{Nothing,StridedArray} && 1==2
4848
warn("StridedArrays don't benefit from pre-allocating epsilon.")
4949
_epsilon = nothing
50-
elseif typeof(epsilon)!=Void && fdtype==Val{:complex}
50+
elseif typeof(epsilon)!=Nothing && fdtype==Val{:complex}
5151
warn("Val{:complex} makes the epsilon array redundant.")
5252
_epsilon = nothing
5353
else
54-
if typeof(epsilon)==Void || eltype(epsilon)!=real(eltype(x))
54+
if typeof(epsilon)==Nothing || eltype(epsilon)!=real(eltype(x))
5555
epsilon = zeros(real(eltype(x)), size(x))
5656
end
5757
_epsilon = epsilon
@@ -67,8 +67,8 @@ function finite_difference_derivative(
6767
x :: AbstractArray{<:Number},
6868
fdtype :: Type{T1} = Val{:central},
6969
returntype :: Type{T2} = eltype(x), # return type of f
70-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
71-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing) where {T1,T2}
70+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
71+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing) where {T1,T2}
7272

7373
df = zeros(returntype, size(x))
7474
finite_difference_derivative!(df, f, x, fdtype, returntype, fx, epsilon)
@@ -80,8 +80,8 @@ function finite_difference_derivative!(
8080
x :: AbstractArray{<:Number},
8181
fdtype :: Type{T1} = Val{:central},
8282
returntype :: Type{T2} = eltype(x),
83-
fx :: Union{Void,AbstractArray{<:Number}} = nothing,
84-
epsilon :: Union{Void,AbstractArray{<:Real}} = nothing) where {T1,T2}
83+
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
84+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing) where {T1,T2}
8585

8686
cache = DerivativeCache(x, fx, epsilon, fdtype, returntype)
8787
finite_difference_derivative!(df, f, x, cache)
@@ -91,12 +91,12 @@ function finite_difference_derivative!(df::AbstractArray{<:Number}, f, x::Abstra
9191
cache::DerivativeCache{T1,T2,fdtype,returntype}) where {T1,T2,fdtype,returntype}
9292

9393
fx, epsilon = cache.fx, cache.epsilon
94-
if typeof(epsilon) != Void
94+
if typeof(epsilon) != Nothing
9595
epsilon_factor = compute_epsilon_factor(fdtype, eltype(x))
9696
@. epsilon = compute_epsilon(fdtype, x, epsilon_factor)
9797
end
9898
if fdtype == Val{:forward}
99-
if typeof(fx) == Void
99+
if typeof(fx) == Nothing
100100
@. df = (f(x+epsilon) - f(x)) / epsilon
101101
else
102102
@. df = (f(x+epsilon) - fx) / epsilon

src/finitediff.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
eps_cbrt * max(one(real(T)), abs(x))
1515
end
1616

17-
@inline function compute_epsilon(::Type{Val{:complex}}, x::T, ::Union{Void,T}=nothing) where T<:Real
17+
@inline function compute_epsilon(::Type{Val{:complex}}, x::T, ::Union{Nothing,T}=nothing) where T<:Real
1818
eps(T)
1919
end
2020

src/gradients.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ function GradientCache(
4444
end
4545
end
4646

47-
GradientCache{Void,typeof(_c1),typeof(_c2),fdtype,
47+
GradientCache{Nothing,typeof(_c1),typeof(_c2),fdtype,
4848
returntype,inplace}(nothing,_c1,_c2)
4949

5050
end
5151

5252
function GradientCache(
53-
c1 :: Union{Void,AbstractArray{<:Number}},
54-
c2 :: Union{Void,AbstractArray{<:Number}},
55-
fx :: Union{Void,<:Number,AbstractArray{<:Number}} = nothing,
53+
c1 :: Union{Nothing,AbstractArray{<:Number}},
54+
c2 :: Union{Nothing,AbstractArray{<:Number}},
55+
fx :: Union{Nothing,<:Number,AbstractArray{<:Number}} = nothing,
5656
fdtype :: Type{T1} = Val{:central},
5757
returntype :: Type{T2} = eltype(c1),
5858
inplace :: Type{Val{T3}} = Val{true}) where {T1,T2,T3}
5959

60-
if fdtype!=Val{:forward} && typeof(fx)!=Void
60+
if fdtype!=Val{:forward} && typeof(fx)!=Nothing
6161
warn("Pre-computed function values are only useful for fdtype == Val{:forward}.")
6262
_fx = nothing
6363
else
@@ -75,7 +75,7 @@ function GradientCache(
7575
else
7676
_c1 = nothing
7777
_c2 = nothing
78-
if typeof(c1)!=Void || typeof(c2)!=Void
78+
if typeof(c1)!=Nothing || typeof(c2)!=Nothing
7979
warn("For StridedVectors, neither c1 nor c2 are necessary.")
8080
end
8181
end
@@ -107,15 +107,15 @@ end
107107

108108
function finite_difference_gradient(f, x, fdtype::Type{T1}=Val{:central},
109109
returntype::Type{T2}=eltype(x), inplace::Type{Val{T3}}=Val{true},
110-
fx::Union{Void,AbstractArray{<:Number}}=nothing,
111-
c1::Union{Void,AbstractArray{<:Number}}=nothing,
112-
c2::Union{Void,AbstractArray{<:Number}}=nothing) where {T1,T2,T3}
110+
fx::Union{Nothing,AbstractArray{<:Number}}=nothing,
111+
c1::Union{Nothing,AbstractArray{<:Number}}=nothing,
112+
c2::Union{Nothing,AbstractArray{<:Number}}=nothing) where {T1,T2,T3}
113113

114114
if typeof(x) <: AbstractArray
115115
df = zeros(returntype, size(x))
116116
else
117117
if inplace == Val{true}
118-
if typeof(fx)==Void && typeof(c1)==Void && typeof(c2)==Void
118+
if typeof(fx)==Nothing && typeof(c1)==Nothing && typeof(c2)==Nothing
119119
error("In the scalar->vector in-place map case, at least one of fx, c1 or c2 must be provided, otherwise we cannot infer the return size.")
120120
else
121121
if c1 != nothing df = similar(c1)
@@ -133,9 +133,9 @@ end
133133

134134
function finite_difference_gradient!(df, f, x, fdtype::Type{T1}=Val{:central},
135135
returntype::Type{T2}=eltype(df), inplace::Type{Val{T3}}=Val{true},
136-
fx::Union{Void,AbstractArray{<:Number}}=nothing,
137-
c1::Union{Void,AbstractArray{<:Number}}=nothing,
138-
c2::Union{Void,AbstractArray{<:Number}}=nothing,
136+
fx::Union{Nothing,AbstractArray{<:Number}}=nothing,
137+
c1::Union{Nothing,AbstractArray{<:Number}}=nothing,
138+
c2::Union{Nothing,AbstractArray{<:Number}}=nothing,
139139
) where {T1,T2,T3}
140140

141141
cache = GradientCache(df,x,fdtype,returntype,inplace)
@@ -241,7 +241,7 @@ function finite_difference_gradient!(df::StridedVector{<:Number}, f, x::StridedV
241241
for i eachindex(x)
242242
epsilon = compute_epsilon(fdtype, x[i], epsilon_factor)
243243
x_old = x[i]
244-
if typeof(fx) != Void
244+
if typeof(fx) != Nothing
245245
x[i] += epsilon
246246
dfi = (f(x) - fx) / epsilon
247247
x[i] = x_old
@@ -256,15 +256,15 @@ function finite_difference_gradient!(df::StridedVector{<:Number}, f, x::StridedV
256256
if eltype(df)<:Complex
257257
if eltype(x)<:Complex
258258
x[i] += im * epsilon
259-
if typeof(fx) != Void
259+
if typeof(fx) != Nothing
260260
dfi = (f(x) - fx) / (im*epsilon)
261261
else
262262
dfi = (f(x) - fx0) / (im*epsilon)
263263
end
264264
x[i] = x_old
265265
else
266266
c1[i] += im * epsilon
267-
if typeof(fx) != Void
267+
if typeof(fx) != Nothing
268268
dfi = (f(c1) - fx) / (im*epsilon)
269269
else
270270
dfi = (f(c1) - fx0) / (im*epsilon)
@@ -334,7 +334,7 @@ function finite_difference_gradient!(df::AbstractArray{<:Number}, f, x::Number,
334334
else
335335
c1 .= f(x+epsilon)
336336
end
337-
if typeof(fx) != Void
337+
if typeof(fx) != Nothing
338338
@. df = (c1 - fx) / epsilon
339339
else
340340
if inplace == Val{true}

test/finitedifftests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using DiffEqDiffTools, Base.Test
1+
using DiffEqDiffTools, Test
22

33
# TODO: add tests for GPUArrays
44
# TODO: add tests for DEDataArrays
55

66
# Derivative tests
7-
x = collect(linspace(-2π, 2π, 100))
7+
x = collect(range(-2π, stop=2π, length=100))
88
y = sin.(x)
99
df = zeros(100)
1010
epsilon = zeros(100)
@@ -80,7 +80,7 @@ end
8080
@test err_func(DiffEqDiffTools.finite_difference_derivative!(df, f, x, central_cache), df_ref) < 1e-6
8181
end
8282

83-
x = collect(linspace(-2π, 2π, 100))
83+
x = collect(range(-2π, stop=2π, length=100))
8484
f(x) = sin(x) + im*cos(x)
8585
y = f.(x)
8686
df = zeros(Complex{eltype(x)}, size(x))

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using DiffEqDiffTools
2-
using Base.Test
2+
using Test
33

44
tic()
55
include("finitedifftests.jl")

0 commit comments

Comments
 (0)