Skip to content

Commit 20ee111

Browse files
femtocleaner[bot]jrevels
authored andcommitted
Fix deprecations (#106)
1 parent b2e0e1b commit 20ee111

File tree

12 files changed

+188
-217
lines changed

12 files changed

+188
-217
lines changed

src/api/Config.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
# AbstractConfig #
33
##################
44

5-
@compat abstract type AbstractConfig end
5+
abstract type AbstractConfig end
66

77
Base.show(io::IO, cfg::AbstractConfig) = print(io, typeof(cfg).name)
88

99
##################
1010
# GradientConfig #
1111
##################
1212

13-
@compat immutable GradientConfig{I} <: AbstractConfig
13+
struct GradientConfig{I} <: AbstractConfig
1414
input::I
1515
tape::InstructionTape
1616
# disable default outer constructor
17-
(::Type{GradientConfig{I}}){I}(input, tape) = new{I}(input, tape)
17+
GradientConfig{I}(input, tape) where {I} = new{I}(input, tape)
1818
end
1919

2020
# "private" convienence constructor
21-
_GradientConfig{I}(input::I, tape::InstructionTape) = GradientConfig{I}(input, tape)
21+
_GradientConfig(input::I, tape::InstructionTape) where {I} = GradientConfig{I}(input, tape)
2222

2323
"""
2424
ReverseDiff.GradientConfig(input, tp::InstructionTape = InstructionTape())
@@ -32,7 +32,7 @@ the target function's output.
3232
3333
See `ReverseDiff.gradient` for a description of acceptable types for `input`.
3434
"""
35-
GradientConfig{T}(input::AbstractArray{T}, tp::InstructionTape = InstructionTape()) = GradientConfig(input, T, tp)
35+
GradientConfig(input::AbstractArray{T}, tp::InstructionTape = InstructionTape()) where {T} = GradientConfig(input, T, tp)
3636

3737
GradientConfig(input::Tuple, tp::InstructionTape = InstructionTape()) = GradientConfig(input, eltype(first(input)), tp)
3838

@@ -42,28 +42,28 @@ GradientConfig(input::Tuple, tp::InstructionTape = InstructionTape()) = Gradient
4242
Like `GradientConfig(input, tp)`, except the provided type `D` is assumed to be the element
4343
type of the target function's output.
4444
"""
45-
function GradientConfig{D}(input::Tuple, ::Type{D}, tp::InstructionTape = InstructionTape())
45+
function GradientConfig(input::Tuple, ::Type{D}, tp::InstructionTape = InstructionTape()) where D
4646
return _GradientConfig(map(x -> track(similar(x), D, tp), input), tp)
4747
end
4848

49-
function GradientConfig{D}(input::AbstractArray, ::Type{D}, tp::InstructionTape = InstructionTape())
49+
function GradientConfig(input::AbstractArray, ::Type{D}, tp::InstructionTape = InstructionTape()) where D
5050
return _GradientConfig(track(similar(input), D, tp), tp)
5151
end
5252

5353
##################
5454
# JacobianConfig #
5555
##################
5656

57-
@compat immutable JacobianConfig{I,O} <: AbstractConfig
57+
struct JacobianConfig{I,O} <: AbstractConfig
5858
input::I
5959
output::O
6060
tape::InstructionTape
6161
# disable default outer constructor
62-
(::Type{JacobianConfig{I,O}}){I,O}(input, output, tape) = new{I,O}(input, output, tape)
62+
JacobianConfig{I,O}(input, output, tape) where {I,O} = new{I,O}(input, output, tape)
6363
end
6464

6565
# "private" convienence constructor
66-
_JacobianConfig{I,O}(input::I, output::O, tape::InstructionTape) = JacobianConfig{I,O}(input, output, tape)
66+
_JacobianConfig(input::I, output::O, tape::InstructionTape) where {I,O} = JacobianConfig{I,O}(input, output, tape)
6767

6868
"""
6969
ReverseDiff.JacobianConfig(input, tp::InstructionTape = InstructionTape())
@@ -99,14 +99,14 @@ stored or modified in any way.
9999
100100
See `ReverseDiff.jacobian` for a description of acceptable types for `input`.
101101
"""
102-
function JacobianConfig{D}(output::AbstractArray{D}, input::Tuple, tp::InstructionTape = InstructionTape())
102+
function JacobianConfig(output::AbstractArray{D}, input::Tuple, tp::InstructionTape = InstructionTape()) where D
103103
cfg_input = map(x -> track(similar(x), D, tp), input)
104104
cfg_output = track!(similar(output, TrackedReal{D,D,Void}), output, tp)
105105
return _JacobianConfig(cfg_input, cfg_output, tp)
106106
end
107107

108108
# we dispatch on V<:Real here because InstructionTape is actually also an AbstractArray
109-
function JacobianConfig{D,V<:Real}(output::AbstractArray{D}, input::AbstractArray{V}, tp::InstructionTape = InstructionTape())
109+
function JacobianConfig(output::AbstractArray{D}, input::AbstractArray{V}, tp::InstructionTape = InstructionTape()) where {D,V<:Real}
110110
cfg_input = track(similar(input), D, tp)
111111
cfg_output = track!(similar(output, TrackedReal{D,D,Void}), output, tp)
112112
return _JacobianConfig(cfg_input, cfg_output, tp)
@@ -123,7 +123,7 @@ JacobianConfig(result::DiffResult, input, tp::InstructionTape) = JacobianConfig(
123123
# HessianConfig #
124124
#################
125125

126-
immutable HessianConfig{G<:GradientConfig,J<:JacobianConfig} <: AbstractConfig
126+
struct HessianConfig{G<:GradientConfig,J<:JacobianConfig} <: AbstractConfig
127127
gradient_config::G
128128
jacobian_config::J
129129
end
@@ -149,7 +149,7 @@ end
149149
Like `HessianConfig(input, tp)`, except the provided type `D` is assumed to be the element
150150
type of the target function's output.
151151
"""
152-
function HessianConfig{D}(input::AbstractArray, ::Type{D}, gtp::InstructionTape = InstructionTape(), jtp::InstructionTape = InstructionTape())
152+
function HessianConfig(input::AbstractArray, ::Type{D}, gtp::InstructionTape = InstructionTape(), jtp::InstructionTape = InstructionTape()) where D
153153
jcfg = JacobianConfig(input, D, jtp)
154154
gcfg = GradientConfig(jcfg.input, gtp)
155155
return HessianConfig(gcfg, jcfg)

src/api/tape.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# AbstractTape #
33
################
44

5-
@compat abstract type AbstractTape end
5+
abstract type AbstractTape end
66

77
Base.show(io::IO, t::AbstractTape) = print(io, typeof(t).name, "(", t.func, ")")
88

@@ -11,17 +11,17 @@ Base.show(io::IO, t::AbstractTape) = print(io, typeof(t).name, "(", t.func, ")")
1111
for T in (:GradientTape, :JacobianTape, :HessianTape)
1212
_T = Symbol(string("_", T))
1313
@eval begin
14-
immutable $(T){F,I,O} <: AbstractTape
14+
struct $(T){F,I,O} <: AbstractTape
1515
func::F
1616
input::I
1717
output::O
1818
tape::InstructionTape
1919
# disable default outer constructor
20-
(::Type{$(T){F,I,O}}){F,I,O}(func, input, output, tape) = new{F,I,O}(func, input, output, tape)
20+
$(T){F,I,O}(func, input, output, tape) where {F,I,O} = new{F,I,O}(func, input, output, tape)
2121
end
2222

2323
# "private" convienence constructor
24-
$(_T){F,I,O}(func::F, input::I, output::O, tape::InstructionTape) = $(T){F,I,O}(func, input, output, tape)
24+
$(_T)(func::F, input::I, output::O, tape::InstructionTape) where {F,I,O} = $(T){F,I,O}(func, input, output, tape)
2525

2626
Base.length(t::$T) = length(t.tape)
2727

@@ -52,7 +52,7 @@ end
5252
# CompiledTape #
5353
################
5454

55-
immutable CompiledTape{T<:AbstractTape} <: AbstractTape
55+
struct CompiledTape{T<:AbstractTape} <: AbstractTape
5656
tape::T
5757
forward_exec::Vector{FunctionWrapper{Void, Tuple{}}}
5858
reverse_exec::Vector{FunctionWrapper{Void, Tuple{}}}
@@ -69,7 +69,7 @@ is stored as a vector of non-concrete AbstractInstruction elements, so calling
6969
dispatch. Instead, we can create a ForwardExecutor and a FunctionWrapper for
7070
each instruction and store those in a concretely-typed Vector.
7171
"""
72-
immutable ForwardExecutor{I <: AbstractInstruction}
72+
struct ForwardExecutor{I <: AbstractInstruction}
7373
instruction::I
7474
end
7575

@@ -86,7 +86,7 @@ is stored as a vector of non-concrete AbstractInstruction elements, so calling
8686
dispatch. Instead, we can create a ReverseExecutor and a FunctionWrapper for
8787
each instruction and store those in a concretely-typed Vector.
8888
"""
89-
immutable ReverseExecutor{I <: AbstractInstruction}
89+
struct ReverseExecutor{I <: AbstractInstruction}
9090
instruction::I
9191
end
9292

@@ -98,7 +98,7 @@ end
9898
Construct a compiled type by wrapping the `forward_exec!` and `reverse_exec!`
9999
methods on each instruction in the tape.
100100
"""
101-
function (::Type{CompiledTape}){T<:AbstractTape}(t::T)
101+
function CompiledTape(t::T) where T<:AbstractTape
102102
CompiledTape{T}(t,
103103
[FunctionWrapper{Void, Tuple{}}(ForwardExecutor(instruction)) for instruction in t.tape],
104104
[FunctionWrapper{Void, Tuple{}}(ReverseExecutor(t.tape[i])) for i in length(t.tape):-1:1]
@@ -107,9 +107,9 @@ end
107107

108108
Base.show(io::IO, t::CompiledTape) = print(io, typeof(t).name, "($(t.tape.func))")
109109

110-
@compat const CompiledGradient{T<:GradientTape} = CompiledTape{T}
111-
@compat const CompiledJacobian{T<:JacobianTape} = CompiledTape{T}
112-
@compat const CompiledHessian{T<:HessianTape} = CompiledTape{T}
110+
const CompiledGradient{T<:GradientTape} = CompiledTape{T}
111+
const CompiledJacobian{T<:JacobianTape} = CompiledTape{T}
112+
const CompiledHessian{T<:HessianTape} = CompiledTape{T}
113113

114114
Base.length(ct::CompiledTape) = length(ct.tape)
115115

0 commit comments

Comments
 (0)