Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 789af88

Browse files
Merge pull request #169 from JuliaDiff/myb/inf
Better inference
2 parents f10cda4 + dc0900c commit 789af88

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
5252
end
5353

5454
generate_chunked_partials(x,colorvec,N::Integer) = generate_chunked_partials(x,colorvec,Val(N))
55-
function generate_chunked_partials(x,colorvec,::Val{chunksize}) where chunksize
55+
function generate_chunked_partials(x,colorvec,cs::Val{chunksize}) where chunksize
5656
maxcolor = maximum(colorvec)
57-
num_of_chunks = Int(ceil(maxcolor / chunksize))
57+
num_of_chunks = cld(maxcolor, chunksize)
5858
padding_size = (chunksize - (maxcolor % chunksize)) % chunksize
5959

6060
# partials = colorvec .== (1:maxcolor)'
@@ -72,13 +72,17 @@ function generate_chunked_partials(x,colorvec,::Val{chunksize}) where chunksize
7272
for i in 1:num_of_chunks
7373
tmp = Vector{NTuple{chunksize,eltype(x)}}(undef, size(partials,1))
7474
for j in 1:size(partials,1)
75-
tmp[j] = Tuple(@view partials[j,(i-1)*chunksize+1:i*chunksize])
75+
tmp[j] = partials_view_tup(partials, j, i, cs)
7676
end
7777
chunked_partials[i] = tmp
7878
end
7979
chunked_partials
8080
end
8181

82+
@generated function partials_view_tup(partials, j, i, ::Val{chunksize}) where chunksize
83+
:(Base.@ntuple $chunksize k->partials[j,(i-1)*$chunksize+k])
84+
end
85+
8286
function forwarddiff_color_jacobian(f::F,
8387
x::AbstractArray{<:Number};
8488
colorvec = 1:length(x),

0 commit comments

Comments
 (0)