Skip to content

Commit d5c9763

Browse files
committed
Use broadcasting to construct the Kronecker's delta
1 parent 36c5256 commit d5c9763

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/back.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,8 @@ Calculate the output jacobian `J = d/dx m(x)` such that each row `i` of `J` corr
173173
"""
174174
function jacobian(f, x::AbstractVector)
175175
y::AbstractVector, back = forward(f, x)
176-
function (i)
177-
δ = fill!(similar(y, Bool), false)
178-
δ[i] = true
179-
return δ
180-
end
176+
# Using broadcasting so that output of `ȳ` is a GPU array if `x` is so:
177+
(i) = ((j, _) -> i == j).(1:length(x), x)
181178
vcat([transpose(back((i))[1]) for i = 1:length(y)]...)
182179
end
183180

0 commit comments

Comments
 (0)