Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jacobian work with CuArrays #33

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use fill!/similar-based approach to reduce number of indexing
  • Loading branch information
tkf committed May 30, 2019
commit f6b0ad40a196059b50fd95045b97607ae82b0232
8 changes: 5 additions & 3 deletions src/back.jl
Original file line number Diff line number Diff line change
@@ -173,9 +173,11 @@ 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)
z = float(zero(eltype(data(y))))
# Using broadcasting so that output of `ȳ` is a GPU array if `y` is so:
ȳ(i) = ((j, _) -> i == j).(1:length(y), y) .+ z
function ȳ(i)
δ = fill!(float(similar(data(y))), false)
Copy link
Member

@ChrisRackauckas ChrisRackauckas Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

δ = false .* y .+ (1:length(y) .== i). Though you should then make it be color_i and loop through colors for it to be sparse, but this is good for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a fresh PR for this.

δ[i] = true
return δ
end
vcat([transpose(back(ȳ(i))[1]) for i = 1:length(y)]...)
end