Skip to content

Some AD fixes #37

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

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/differentiation/compute_jacobian_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ function ForwardColorJacCache(f,x,_chunksize = nothing;
end

generate_chunked_partials(x,color,N::Integer) = generate_chunked_partials(x,color,Val(N))
function generate_chunked_partials(x,color,::Val{N}) where N
function generate_chunked_partials(x,color,::Val{chunksize}) where chunksize

chunksize = getsize(default_chunk_size(maximum(color)))
num_of_chunks = Int64(ceil(maximum(color) / chunksize))

padding_size = (chunksize - (maximum(color) % chunksize)) % chunksize

partials = BitMatrix(undef, length(x), maximum(color))
partial = BitMatrix(undef, length(x), chunksize)
chunked_partials = Array{Array{NTuple,1},1}(undef, num_of_chunks)
chunked_partials = Array{Array{Tuple{Vararg{Bool,chunksize}},1},1}(
undef, num_of_chunks)

for color_i in 1:maximum(color)
for j in 1:length(x)
Expand Down Expand Up @@ -92,9 +92,8 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
dx = jac_cache.dx
p = jac_cache.p
color = jac_cache.color

color_i = 1
chunksize = getsize(default_chunk_size(maximum(color)))
chunksize = length(first(first(jac_cache.p)))

for i in 1:length(p)
partial_i = p[i]
Expand All @@ -115,6 +114,7 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
else
for j in 1:chunksize
col_index = (i-1)*chunksize + j
(col_index > maximum(color)) && continue
J[:, col_index] .= partials.(fx, j)
end
end
Expand Down