@@ -5,6 +5,15 @@ import ForwardDiff
55
66const DiffResult = ForwardDiff. DiffResults. DiffResult
77
8+ # ForwardDiff 1.4.4 split the zero-partials forms of `seed!` out under the name
9+ # `seed_zero_partials!`. On older versions the equivalent forms of `seed!` write through to
10+ # the end of the array rather than just the chunk, which is redundant but not incorrect.
11+ if isdefined (ForwardDiff, :seed_zero_partials! )
12+ const seed_zero_partials! = ForwardDiff. seed_zero_partials!
13+ else
14+ const seed_zero_partials! = ForwardDiff. seed!
15+ end
16+
817function cld_fast (a:: A ,b:: B ) where {A,B}
918 T = promote_type (A,B)
1019 cld_fast (a% T,b% T)
@@ -31,13 +40,13 @@ function evaluate_chunks!(f::F, (r,Δx,x), start, stop, ::ForwardDiff.Chunk{C},
3140
3241 xdual = cfg. duals
3342 seeds = cfg. seeds
34- ForwardDiff . seed ! (xdual, x)
43+ seed_zero_partials ! (xdual, x)
3544 for c ∈ start: stop
3645 i = (c- 1 ) * C + 1
3746 ForwardDiff. seed! (xdual, x, i, seeds)
3847 ydual = f (xdual)
3948 ForwardDiff. extract_gradient_chunk! (TagType, Δx, ydual, i, C)
40- ForwardDiff . seed ! (xdual, x, i)
49+ seed_zero_partials ! (xdual, x, i)
4150 end
4251 if is_last
4352 lastchunksize = C + N - last_stop* C
@@ -73,7 +82,7 @@ function evaluate_jacobian_chunks!(f::F, (Δx,x), start, stop, ::ForwardDiff.Chu
7382
7483 # seed work arrays
7584 xdual = cfg. duals
76- ForwardDiff . seed ! (xdual, x)
85+ seed_zero_partials ! (xdual, x)
7786 seeds = cfg. seeds
7887
7988 # handle intermediate chunks
@@ -88,7 +97,7 @@ function evaluate_jacobian_chunks!(f::F, (Δx,x), start, stop, ::ForwardDiff.Chu
8897 # extract part of the Jacobian
8998 Δx_reshaped = ForwardDiff. reshape_jacobian (Δx, ydual, xdual)
9099 ForwardDiff. extract_jacobian_chunk! (TagType, Δx_reshaped, ydual, i, C)
91- ForwardDiff . seed ! (xdual, x, i)
100+ seed_zero_partials ! (xdual, x, i)
92101 end
93102
94103 # handle the last chunk
@@ -132,7 +141,7 @@ function evaluate_f_and_jacobian_chunks!(f!::F, (y,Δx,x), start, stop, ::Forwar
132141
133142 # seed work arrays
134143 ydual, xdual = cfg. duals
135- ForwardDiff . seed ! (xdual, x)
144+ seed_zero_partials ! (xdual, x)
136145 seeds = cfg. seeds
137146 Δx_reshaped = ForwardDiff. reshape_jacobian (Δx, ydual, xdual)
138147
@@ -143,11 +152,11 @@ function evaluate_f_and_jacobian_chunks!(f!::F, (y,Δx,x), start, stop, ::Forwar
143152 ForwardDiff. seed! (xdual, x, i, seeds)
144153
145154 # compute ydual
146- f! (ForwardDiff . seed ! (ydual, y), xdual)
155+ f! (seed_zero_partials ! (ydual, y), xdual)
147156
148157 # extract part of the Jacobian
149158 ForwardDiff. extract_jacobian_chunk! (TagType, Δx_reshaped, ydual, i, C)
150- ForwardDiff . seed ! (xdual, x, i)
159+ seed_zero_partials ! (xdual, x, i)
151160 end
152161
153162 # handle the last chunk
@@ -159,7 +168,7 @@ function evaluate_f_and_jacobian_chunks!(f!::F, (y,Δx,x), start, stop, ::Forwar
159168 ForwardDiff. seed! (xdual, x, lastchunkindex, seeds, lastchunksize)
160169
161170 # compute ydual
162- f! (ForwardDiff . seed ! (ydual, y), xdual)
171+ f! (seed_zero_partials ! (ydual, y), xdual)
163172
164173 # extract part of the Jacobian
165174 ForwardDiff. extract_jacobian_chunk! (TagType, Δx_reshaped, ydual, lastchunkindex, lastchunksize)
0 commit comments