We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36c5256 commit aa4e64aCopy full SHA for aa4e64a
src/back.jl
@@ -173,11 +173,8 @@ Calculate the output jacobian `J = d/dx m(x)` such that each row `i` of `J` corr
173
"""
174
function jacobian(f, x::AbstractVector)
175
y::AbstractVector, back = forward(f, x)
176
- function ȳ(i)
177
- δ = fill!(similar(y, Bool), false)
178
- δ[i] = true
179
- return δ
180
- end
+ # Using broadcasting so that output of `ȳ` is a GPU array if `y` is so:
+ ȳ(i) = ((j, _) -> i == j).(1:length(y), y)
181
vcat([transpose(back(ȳ(i))[1]) for i = 1:length(y)]...)
182
end
183
0 commit comments