Skip to content

Commit

Permalink
Use broadcasting to construct the Kronecker's delta
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed May 30, 2019
1 parent 36c5256 commit aa4e64a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/back.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,8 @@ Calculate the output jacobian `J = d/dx m(x)` such that each row `i` of `J` corr
"""
function jacobian(f, x::AbstractVector)
y::AbstractVector, back = forward(f, x)
function (i)
δ = fill!(similar(y, Bool), false)
δ[i] = true
return δ
end
# Using broadcasting so that output of `ȳ` is a GPU array if `y` is so:
(i) = ((j, _) -> i == j).(1:length(y), y)
vcat([transpose(back((i))[1]) for i = 1:length(y)]...)
end

Expand Down

0 comments on commit aa4e64a

Please sign in to comment.