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

Commit b8ee652

Browse files
Merge pull request #98 from JuliaDiff/speed
Fix type instability due to mapslices in colorvec partial generation
2 parents 7acf009 + 6146783 commit b8ee652

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ function ForwardColorJacCache(f,x,_chunksize = nothing;
3737
fx = similar(t)
3838
_dx = similar(x)
3939
else
40-
pi = first(p) #perform trim (length(dx)<length(x)) or padding (length(dx)>length(x)) to first(p)
41-
if length(dx)>length(x)
42-
pi = vcat(pi,reshape(mapslices(Tuple,zeros(Bool,length(first(pi)),length(dx)-length(x)),dims=1),:))
43-
else
44-
pi = pi[1:length(dx)]
45-
end
40+
tup = first(first(p)) .* false
41+
pi = adapt.(typeof(dx),[tup for i in 1:length(dx)])
4642
fx = reshape(Dual{ForwardDiff.Tag(f,eltype(vec(x)))}.(vec(dx),pi),size(dx)...)
4743
_dx = dx
4844
end

0 commit comments

Comments
 (0)