Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.
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
15 changes: 11 additions & 4 deletions src/differentiation/compute_jacobian_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;

if x isa Array
p = generate_chunked_partials(x,colorvec,chunksize)
t = Array{Dual{T,eltype(x),length(first(first(p)))}}(undef,size(x))
for i in eachindex(t)
t[i] = Dual{T,eltype(x),length(first(first(p)))}(x[i],ForwardDiff.Partials(first(p)[i]))
end
DT = Dual{T,eltype(x),length(first(first(p)))}
t = _get_t(DT, x, p)
else
p = adapt.(parameterless_type(x),generate_chunked_partials(x,colorvec,chunksize))
_t = Dual{T,eltype(x),getsize(chunksize)}.(vec(x),ForwardDiff.Partials.(first(p)))
Expand All @@ -60,6 +58,15 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
ForwardColorJacCache(t,fx,_dx,p,colorvec,sparsity,getsize(chunksize))
end

# Function barrier for unknown constructor type
function _get_t(::Type{DT}, x, p) where DT
t = similar(x, DT)
for i in eachindex(t)
t[i] = DT(x[i],ForwardDiff.Partials(first(p)[i]))
end
t
end

generate_chunked_partials(x,colorvec,N::Integer) = generate_chunked_partials(x,colorvec,Val(N))
function generate_chunked_partials(x,colorvec,cs::Val{chunksize}) where chunksize
maxcolor = maximum(colorvec)
Expand Down