Skip to content

Commit d2dada3

Browse files
committed
prepare for repo change
1 parent 481d02e commit d2dada3

22 files changed

+317
-238
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ notifications:
99
email: false
1010
script:
1111
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
12-
- julia -e 'Pkg.clone(pwd()); Pkg.build("ReverseDiffPrototype"); Pkg.test("ReverseDiffPrototype"; coverage=true)'
12+
- julia -e 'Pkg.clone(pwd()); Pkg.build("ReverseDiff"); Pkg.test("ReverseDiff"; coverage=true)'
1313
after_success:
1414
# push coverage results to Coveralls
15-
- julia -e 'cd(Pkg.dir("ReverseDiffPrototype")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
15+
- julia -e 'cd(Pkg.dir("ReverseDiff")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The ReverseDiffPrototype.jl package is licensed under the MIT "Expat" License:
1+
The ReverseDiff.jl package is licensed under the MIT "Expat" License:
22

33
> Copyright (c) 2016: Jarrett Revels, John Pearson
44
>

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# ReverseDiffPrototype
1+
# ReverseDiff
22

3-
This is a prototype Julia implementation of reverse mode AD.
3+
A Julia implementation of reverse mode AD.
44

5-
[![Build Status](https://travis-ci.org/jrevels/ReverseDiffPrototype.jl.svg?branch=master)](https://travis-ci.org/jrevels/ReverseDiffPrototype.jl)
5+
Documentation coming soon!
6+
7+
[![Build Status](https://travis-ci.org/jrevels/ReverseDiff.jl.svg?branch=master)](https://travis-ci.org/jrevels/ReverseDiff.jl)

appveyor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ build_script:
2828
# Need to convert from shallow to complete for Pkg.clone to work
2929
- IF EXIST .git\shallow (git fetch --unshallow)
3030
- C:\projects\julia\bin\julia -e "versioninfo();
31-
Pkg.clone(pwd(), \"ReverseDiffPrototype\"); Pkg.build(\"ReverseDiffPrototype\")"
31+
Pkg.clone(pwd(), \"ReverseDiff\"); Pkg.build(\"ReverseDiff\")"
3232

3333
test_script:
34-
- C:\projects\julia\bin\julia -e "Pkg.test(\"ReverseDiffPrototype\")"
34+
- C:\projects\julia\bin\julia -e "Pkg.test(\"ReverseDiff\")"

benchmark/benchmark.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
using ReverseDiffPrototype
2-
3-
const RDP = ReverseDiffPrototype
1+
using ReverseDiff
42

53
####################################################################
64

75
function grad_benchmark_driver(f, x)
86
println("benchmarking ∇$(f)(x) on $(length(x)) elements...")
97

108
out = zeros(x)
11-
opts = RDP.Options(out, RDP.Tape(), x)
9+
opts = ReverseDiff.Options(x, ReverseDiff.Tape())
1210
tp = opts.tape
13-
xt = opts.data
11+
xt = opts.state
1412

1513
# warmup
16-
RDP.seed!(f(xt))
17-
RDP.backprop!(tp)
14+
ReverseDiff.track!(xt, x, tp)
15+
ReverseDiff.seed!(f(xt))
16+
ReverseDiff.reverse_pass!(tp)
1817
empty!(tp)
19-
RDP.gradient!(out, f, x, opts)
18+
ReverseDiff.gradient!(out, f, x, opts)
2019
empty!(tp)
2120

2221
# actual
22+
ReverseDiff.track!(xt, x, tp)
2323
gc()
24-
@time RDP.seed!(f(xt))
24+
@time ReverseDiff.seed!(f(xt))
2525
gc()
26-
@time RDP.backprop!(tp)
26+
@time ReverseDiff.reverse_pass!(tp)
2727
empty!(tp)
2828
gc()
29-
@time RDP.gradient!(out, f, x, opts)
29+
@time ReverseDiff.gradient!(out, f, x, opts)
3030
empty!(tp)
3131

3232
println("done.")
3333
end
3434

3535
####################################################################
3636

37-
rosenbrock(x) = sum(map(RDP.@forward((i, j) -> (1 - j)^2 + 100*(i - j^2)^2), x[2:end], x[1:end-1]))
37+
rosenbrock(x) = sum(map(ReverseDiff.@forward((i, j) -> (1 - j)^2 + 100*(i - j^2)^2), x[2:end], x[1:end-1]))
3838

3939
grad_benchmark_driver(rosenbrock, rand(100000))
4040

@@ -75,15 +75,15 @@ grad_benchmark_driver(matrix_test, collect(1.0:(2n^2 + n)))
7575

7676
relu(x) = log.(1.0 .+ exp(x))
7777

78-
RDP.@forward sigmoid(n) = 1. / (1. + exp(-n))
78+
ReverseDiff.@forward sigmoid(n) = 1. / (1. + exp(-n))
7979

8080
function neural_net(w1, w2, w3, x1)
8181
x2 = relu(w1 * x1)
8282
x3 = relu(w2 * x2)
8383
return sigmoid(dot(w3, x3))
8484
end
8585

86-
neural_net_grads!(outputs, inputs) = RDP.gradient!(outputs, neural_net, inputs)
86+
neural_net_grads!(outputs, inputs) = ReverseDiff.gradient!(outputs, neural_net, inputs)
8787

8888
inputs = (randn(10,10), randn(10,10), randn(10), rand(10))
8989
outputs = map(similar, inputs)

src/ReverseDiffPrototype.jl src/ReverseDiff.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ReverseDiffPrototype
1+
module ReverseDiff
22

33
using DiffBase
44
using DiffBase: DiffResult

src/api/gradients.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function gradient!(out, f, x, opts::Options = Options(x, eltype(out)))
4747
return out
4848
end
4949

50-
function gradient!(outs::Tuple, f, xs::Tuple, opts::Options = Options(xs, map(eltype, outs)))
50+
function gradient!(outs::Tuple, f, xs::Tuple, opts::Options = Options(xs, eltype(first(outs))))
5151
xts, tp = opts.state, opts.tape
5252
track!(xts, xs, tp)
5353
yt = f(xts...)

src/api/jacobians.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function jacobian(f, xs::Tuple, opts::Options = Options(xs))
2222
outs = construct_jacobian_output(yt, xts)
2323
jacobian_reverse_pass!(outs, yt, xts, tp)
2424
empty!(tp)
25-
return out
25+
return outs
2626
end
2727

2828
# jacobian! #
@@ -38,7 +38,7 @@ function jacobian!(out, f, x, opts::Options = Options(x, eltype(out)))
3838
return out
3939
end
4040

41-
function jacobian!(outs::Tuple, f, xs::Tuple, opts::Options = Options(xs, map(eltype, outs)))
41+
function jacobian!(outs::Tuple, f, xs::Tuple, opts::Options = Options(xs, eltype(first(outs))))
4242
xts, tp = opts.state, opts.tape
4343
track!(xts, xs, tp)
4444
yt = f(xts...)
@@ -140,7 +140,7 @@ function jacobian_reverse_pass!(out, yt, xt, tp::Tape)
140140
return out
141141
end
142142

143-
function jacobian_reverse_pass!(outs::Tuple, yt, xts::Tuple, tp)
143+
function jacobian_reverse_pass!(outs::Tuple, yt, xts::Tuple, tp::Tape)
144144
for i in eachindex(outs)
145145
jacobian_reverse_pass!(outs[i], yt, xts[i], tp)
146146
end

src/derivatives/elementwise.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ end
187187
# broadcast #
188188
#-----------#
189189

190-
function special_reverse_step!(::typeof(broadcast), input::AbstractArray, output, duals)
191-
return special_reverse_step!(map, input, output, duals)
192-
end
193-
194190
function special_reverse_step!{A,B}(::typeof(broadcast), inputs::Tuple{A,B}, output, duals)
195191
a, b = inputs
196192
if size(a) == size(b)
@@ -202,8 +198,12 @@ function special_reverse_step!{A,B}(::typeof(broadcast), inputs::Tuple{A,B}, out
202198
return nothing
203199
end
204200

205-
function special_reverse_step!(::typeof(broadcast), input::Number, output, duals)
206-
broadcast_adjoint_reduce!(input, output, duals, 1)
201+
function special_reverse_step!(::typeof(broadcast), input, output, duals)
202+
if size(input) == size(output)
203+
special_reverse_step!(map, input, output, duals)
204+
else
205+
broadcast_adjoint_reduce!(input, output, duals, 1)
206+
end
207207
return nothing
208208
end
209209

@@ -213,10 +213,10 @@ end
213213
# Base.mapreducedim, but that strategy is less cache efficient and more complicated to
214214
# implement.
215215
function broadcast_adjoint_reduce!{T,N}(input::AbstractArray, output::AbstractArray{T,N}, duals, p)
216-
dims = (size(input, i) != size(duals, i) ? 1 : size(duals, i) for i in 1:ndims(duals))
217-
max_index = CartesianIndex((dims...)::NTuple{N,Int})
218-
for i in CartesianRange(size(input))
219-
increment_adjoint!(input[min(max_index, i)], adjoint(output[i]) * partials(duals[i], p))
216+
max_input_index = CartesianIndex(ntuple(i -> size(input, i), N)::NTuple{N,Int})
217+
output_index_range = CartesianRange(size(output))
218+
for i in output_index_range
219+
increment_adjoint!(input[min(max_input_index, i)], adjoint(output[i]) * partials(duals[i], p))
220220
end
221221
return nothing
222222
end

src/derivatives/macros.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ function annotate_func_expr(typesym, expr)
2626
return quote
2727
$expr
2828
@inline function $(old_name_and_types)($(args_signature...))
29-
return ReverseDiffPrototype.$(typesym)($(hidden_name))($(args_signature...))
29+
return ReverseDiff.$(typesym)($(hidden_name))($(args_signature...))
3030
end
3131
end
3232
elseif isa(lhs, Symbol) # variable assignment site
33-
expr.args[2] = :(ReverseDiffPrototype.$(typesym)($(expr.args[2])))
33+
expr.args[2] = :(ReverseDiff.$(typesym)($(expr.args[2])))
3434
return expr
3535
else
3636
error("failed to apply $typesym to expression $expr")
3737
end
3838
else # call site
39-
return :(ReverseDiffPrototype.$(typesym)($expr))
39+
return :(ReverseDiff.$(typesym)($expr))
4040
end
4141
end
4242

test/TapeTests.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module TapeTests
22

3-
using ReverseDiffPrototype, Base.Test
3+
using ReverseDiff, Base.Test
44

55
include("utils.jl")
66

@@ -24,7 +24,7 @@ tn = TapeNode(+, (x, y, k), z, c)
2424

2525
tp = Tape()
2626
ntp = Nullable(tp)
27-
RDP.record!(ntp, +, (x, y, k), z, c)
27+
ReverseDiff.record!(ntp, +, (x, y, k), z, c)
2828
tp1 = first(tp)
2929
@test tp1 == tn
3030
@test tp1.inputs[1] !== x
@@ -34,20 +34,20 @@ tp1 = first(tp)
3434
@test tp1.cache === c
3535

3636
ntp = Nullable{Tape}()
37-
RDP.record!(ntp, +, (x, y, k), z, c)
37+
ReverseDiff.record!(ntp, +, (x, y, k), z, c)
3838
@test ntp === Nullable{Tape}()
3939

4040
t = Tracked(1)
4141
x = [t, t]
42-
@test RDP.capture(t) === t
42+
@test ReverseDiff.capture(t) === t
4343

44-
cx = RDP.capture(x)
44+
cx = ReverseDiff.capture(x)
4545
@test cx !== x
4646
@test cx == x
4747
@test cx[1] === x[1]
4848
@test cx[2] === x[2]
4949

50-
cs = RDP.capture((x, t, x))
50+
cs = ReverseDiff.capture((x, t, x))
5151
@test cs[1] !== x
5252
@test cs[1] == x
5353
@test cs[1][1] === x[1]

test/TrackedTests.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module TrackedTests
22

3-
using ReverseDiffPrototype, Base.Test
3+
using ReverseDiff, Base.Test
44

55
include("utils.jl")
66

@@ -18,7 +18,7 @@ tp = Tape()
1818
ntp = Nullable(tp)
1919

2020
@test value(a) === a
21-
@test !(RDP.hastape(a))
21+
@test !(ReverseDiff.hastape(a))
2222

2323
at = Tracked(a)
2424
@test valtype(at) === typeof(a)
@@ -28,7 +28,7 @@ at = Tracked(a)
2828
@test value(at) === at.value === a
2929
@test adjoint(at) === at.adjoint === zero(a)
3030
@test tape(at) === at.tape === Nullable{Tape}()
31-
@test !(RDP.hastape(at))
31+
@test !(ReverseDiff.hastape(at))
3232

3333
bt = Tracked(b, Int)
3434
@test valtype(bt) === typeof(b)
@@ -38,7 +38,7 @@ bt = Tracked(b, Int)
3838
@test value(bt) === bt.value === b
3939
@test adjoint(bt) === bt.adjoint === zero(Int)
4040
@test tape(bt) === bt.tape === Nullable{Tape}()
41-
@test !(RDP.hastape(bt))
41+
@test !(ReverseDiff.hastape(bt))
4242

4343
ct = Tracked(c, Int, ntp)
4444
@test valtype(ct) === typeof(c)
@@ -48,7 +48,7 @@ ct = Tracked(c, Int, ntp)
4848
@test value(ct) === ct.value === c
4949
@test adjoint(ct) === ct.adjoint === zero(Int)
5050
@test get(tape(ct)) === get(ct.tape) === tp === get(ntp)
51-
@test RDP.hastape(ct)
51+
@test ReverseDiff.hastape(ct)
5252

5353
@test tape(at) === tape(bt) === Nullable{Tape}()
5454
@test tape(at, bt) === tape(bt, at)

test/UtilsTests.jl

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module UtilsTests
22

3-
using ReverseDiffPrototype, Base.Test
3+
using ReverseDiff, Base.Test
44

55
include("utils.jl")
66

@@ -107,17 +107,17 @@ xt, yt = track(x, tp), track(y, tp)
107107
@test value(yt) == y
108108

109109
x_sim, y_sim = similar(x), similar(y)
110-
RDP.value!(x_sim, xt)
111-
RDP.value!(y_sim, yt)
110+
ReverseDiff.value!(x_sim, xt)
111+
ReverseDiff.value!(y_sim, yt)
112112
@test x_sim == x
113113
@test y_sim == y
114114

115115
@test all(adjoint(xt) .== zero(first(x)))
116116
@test all(adjoint(yt) .== zero(first(y)))
117117

118118
x_sim, y_sim = similar(x), similar(y)
119-
RDP.adjoint!(x_sim, xt)
120-
RDP.adjoint!(y_sim, yt)
119+
ReverseDiff.adjoint!(x_sim, xt)
120+
ReverseDiff.adjoint!(y_sim, yt)
121121
@test all(x_sim .== zero(first(x)))
122122
@test all(y_sim .== zero(first(y)))
123123

@@ -140,22 +140,22 @@ RDP.adjoint!(y_sim, yt)
140140
tp = Tape()
141141
ntp = Nullable(tp)
142142

143-
@test tracked_is(RDP.seed!(Tracked(1, 0, ntp)), Tracked(1, 1, ntp))
143+
@test tracked_is(ReverseDiff.seed!(Tracked(1, 0, ntp)), Tracked(1, 1, ntp))
144144

145145
node = TapeNode(+, (Tracked(2, ntp), Tracked(1, ntp)), Tracked(3, ntp), nothing)
146-
@test tracked_is(RDP.seed!(node).outputs, Tracked(3, 1, ntp))
146+
@test tracked_is(ReverseDiff.seed!(node).outputs, Tracked(3, 1, ntp))
147147

148-
@test tracked_is(RDP.unseed!(Tracked(1, 1, ntp)), Tracked(1, 0, ntp))
148+
@test tracked_is(ReverseDiff.unseed!(Tracked(1, 1, ntp)), Tracked(1, 0, ntp))
149149

150150
node = TapeNode(+, (Tracked(2, 2, ntp), Tracked(1, 3, ntp)), Tracked(3, 4, ntp), nothing)
151-
RDP.unseed!(node)
151+
ReverseDiff.unseed!(node)
152152
@test adjoint(node.inputs[1]) === 0
153153
@test adjoint(node.inputs[2]) === 0
154154
@test adjoint(node.outputs) === 0
155155

156156
tp2 = [TapeNode(+, (Tracked(2, 2, ntp), Tracked(1, 3, ntp)), Tracked(3, 4, ntp), nothing),
157157
TapeNode(+, Tracked(1.0, 3.0, ntp), (Tracked(51.4, 3.1, ntp), Tracked(3, 4, ntp)), nothing)]
158-
RDP.unseed!(tp2)
158+
ReverseDiff.unseed!(tp2)
159159
@test adjoint(tp2[1].inputs[1]) === 0
160160
@test adjoint(tp2[1].inputs[2]) === 0
161161
@test adjoint(tp2[1].outputs) === 0
@@ -173,26 +173,26 @@ genarr = () -> [Tracked(rand(), rand(), ntp) for i in 1:3]
173173

174174
x, y = genarr(), genarr()
175175
xadj, yadj = adjoint(x), adjoint(y)
176-
RDP.extract_and_decrement_adjoint!(x, y)
176+
ReverseDiff.extract_and_decrement_adjoint!(x, y)
177177
@test adjoint(x) == (xadj - yadj)
178178

179179
x, y = genarr(), genarr()
180180
xadj, yadj = adjoint(x), adjoint(y)
181-
RDP.extract_and_increment_adjoint!(x, y)
181+
ReverseDiff.extract_and_increment_adjoint!(x, y)
182182
@test adjoint(x) == (xadj + yadj)
183183

184184
x, y = genarr(), rand(3)
185185
xadj = adjoint(x)
186-
RDP.increment_adjoint!(x, y)
186+
ReverseDiff.increment_adjoint!(x, y)
187187
@test adjoint(x) == (xadj + y)
188188

189189
x = genarr()
190190
xadj = adjoint(x)
191-
RDP.increment_adjoint!(x, 3)
191+
ReverseDiff.increment_adjoint!(x, 3)
192192
@test adjoint(x) == (xadj + 3)
193193

194194
k = Tracked(1, 3, ntp)
195-
RDP.increment_adjoint!(k, 3)
195+
ReverseDiff.increment_adjoint!(k, 3)
196196
@test tracked_is(k, Tracked(1, 6, ntp))
197197

198198
############################################################################################

0 commit comments

Comments
 (0)