@@ -36,10 +36,8 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
36
36
37
37
if x isa Array
38
38
p = generate_chunked_partials (x,colorvec,chunksize)
39
- t = Array {Dual{T,eltype(x),length(first(first(p)))}} (undef,size (x))
40
- for i in eachindex (t)
41
- t[i] = Dual {T,eltype(x),length(first(first(p)))} (x[i],ForwardDiff. Partials (first (p)[i]))
42
- end
39
+ DT = Dual{T,eltype (x),length (first (first (p)))}
40
+ t = _get_t (DT, x, p)
43
41
else
44
42
p = adapt .(parameterless_type (x),generate_chunked_partials (x,colorvec,chunksize))
45
43
_t = Dual {T,eltype(x),getsize(chunksize)} .(vec (x),ForwardDiff. Partials .(first (p)))
@@ -60,6 +58,15 @@ function ForwardColorJacCache(f::F,x,_chunksize = nothing;
60
58
ForwardColorJacCache (t,fx,_dx,p,colorvec,sparsity,getsize (chunksize))
61
59
end
62
60
61
+ # Function barrier for unknown constructor type
62
+ function _get_t (:: Type{DT} , x, p) where DT
63
+ t = similar (x, DT)
64
+ for i in eachindex (t)
65
+ t[i] = DT (x[i],ForwardDiff. Partials (first (p)[i]))
66
+ end
67
+ t
68
+ end
69
+
63
70
generate_chunked_partials (x,colorvec,N:: Integer ) = generate_chunked_partials (x,colorvec,Val (N))
64
71
function generate_chunked_partials (x,colorvec,cs:: Val{chunksize} ) where chunksize
65
72
maxcolor = maximum (colorvec)
0 commit comments