Skip to content

Commit

Permalink
added GradientResult example
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Mar 21, 2017
1 parent b1496d0 commit a7f2c4b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/gradient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const compiled_f_tape = compile(f_tape)
a, b = rand(100, 100), rand(100, 100)
inputs = (a, b)
results = (similar(a), similar(b))
all_results = map(DiffBase.GradientResult, results)
cfg = GradientConfig(inputs)

####################
Expand All @@ -29,6 +30,10 @@ cfg = GradientConfig(inputs)
# this should be the fastest method, and non-allocating
gradient!(results, compiled_f_tape, inputs)

# the same as the above, but in addition to calculating the gradients, the value `f(a, b)`
# is loaded into the the provided `DiffResult` instances (see DiffBase.jl documentation).
gradient!(all_results, compiled_f_tape, inputs)

# this should be the second fastest method, and also non-allocating
gradient!(results, f_tape, inputs)

Expand Down

0 comments on commit a7f2c4b

Please sign in to comment.