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

Commit f9fd755

Browse files
fix tag construction
1 parent 7879092 commit f9fd755

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void_setindex!(args...) = (setindex!(args...); return)
1414
gettag(::Type{ForwardDiff.Dual{T}}) where {T} = T
1515

1616
const default_chunk_size = ForwardDiff.pickchunksize
17+
const SMALLTAG = ForwardDiff.Tag(missing,Float64)
1718

1819
function ForwardColorJacCache(f::F,x,_chunksize = nothing;
1920
dx = nothing,
@@ -41,7 +42,7 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
4142
end
4243
else
4344
p = adapt.(parameterless_type(x),generate_chunked_partials(x,colorvec,chunksize))
44-
_t = Dual{T,eltype(x),length(first(first(p)))}.(vec(x),first(p))
45+
_t = Dual{T,eltype(x),length(first(first(p)))}.(vec(x),ForwardDiff.Partials.(first(p)))
4546
t = ArrayInterface.restructure(x,_t)
4647
end
4748

@@ -52,7 +53,7 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
5253
else
5354
tup = ArrayInterface.allowed_getindex(ArrayInterface.allowed_getindex(p,1),1) .* false
5455
_pi = adapt(parameterless_type(dx),[tup for i in 1:length(dx)])
55-
fx = reshape(Dual{T,eltype(dx),length(tup)}.(vec(dx),_pi),size(dx)...)
56+
fx = reshape(Dual{T,eltype(dx),length(tup)}.(vec(dx),ForwardDiff.Partials.(_pi)),size(dx)...)
5657
_dx = dx
5758
end
5859

@@ -170,7 +171,7 @@ function forwarddiff_color_jacobian(J::AbstractMatrix{<:Number},f::F,x::Abstract
170171

171172
for i in eachindex(p)
172173
partial_i = p[i]
173-
t = reshape(Dual{gettag(eltype(t))}.(vecx, partial_i),size(t))
174+
t = reshape(eltype(t).(vecx, ForwardDiff.Partials.(partial_i)),size(t))
174175
fx = f(t)
175176
if !(sparsity isa Nothing)
176177
for j in 1:chunksize
@@ -238,7 +239,7 @@ function forwarddiff_color_jacobian_immutable(f,x::AbstractArray{<:Number},jac_c
238239

239240
for i in eachindex(p)
240241
partial_i = p[i]
241-
t = reshape(Dual{gettag(eltype(t))}.(vecx, partial_i),size(t))
242+
t = reshape(eltype(t).(vecx, ForwardDiff.Partials.(partial_i)),size(t))
242243
fx = f(t)
243244
if !(sparsity isa Nothing)
244245
for j in 1:chunksize
@@ -319,10 +320,10 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
319320

320321
if vect isa Array
321322
@inbounds @simd ivdep for j in eachindex(vect)
322-
vect[j] = Dual{gettag(eltype(t))}(vecx[j], partial_i[j])
323+
vect[j] = eltype(t)(vecx[j], ForwardDiff.Partials(partial_i[j]))
323324
end
324325
else
325-
vect .= Dual{gettag(eltype(t))}.(vecx, partial_i)
326+
vect .= eltype(t).(vecx, ForwardDiff.Partials.(partial_i))
326327
end
327328

328329
f(fx,t)

0 commit comments

Comments
 (0)