@@ -104,12 +104,9 @@ Base.eltype(cfg::AbstractConfig) = eltype(typeof(cfg))
104
104
@inline (chunksize (:: AbstractConfig{N} ):: Int ) where {N} = N
105
105
106
106
function maketag (tagstyle:: Union{Symbol,Nothing} , f, X)
107
- @static if VERSION ≥ v " 1.11 "
107
+ if HASHTAG_MODE_ENABLED
108
108
return HashTag (f, X)
109
109
else
110
- # On ≤1.10, the hash of a type cannot be computed at compile-time,
111
- # making `HashTag(...)` type-unstable, so `Tag(...)` is left as
112
- # as the default.
113
110
return Tag (f, X)
114
111
end
115
112
end
@@ -136,22 +133,12 @@ If `f!` is `nothing` instead of the actual target function, then the returned in
136
133
be used with any target function. However, this will reduce ForwardDiff's ability to catch
137
134
and prevent perturbation confusion (see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
138
135
139
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
140
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
141
-
142
136
This constructor does not store/modify `y` or `x`.
143
137
"""
144
- @inline function DerivativeConfig (f:: F ,
145
- y:: AbstractArray{Y} ,
146
- x:: X ) where {F,X<: Real ,Y<: Real }
147
- T = maketag (f, X)
148
- return DerivativeConfig (f,y,x,T)
149
- end
150
-
151
138
function DerivativeConfig (f:: F ,
152
139
y:: AbstractArray{Y} ,
153
140
x:: X ,
154
- tag:: T ) where {F,X<: Real ,Y<: Real ,T}
141
+ tag:: T = Tag (f, X) ) where {F,X<: Real ,Y<: Real ,T}
155
142
duals = similar (y, Dual{T,Y,1 })
156
143
return DerivativeConfig {T,typeof(duals)} (duals)
157
144
end
@@ -181,22 +168,12 @@ If `f` or `tag` is `nothing`, then the returned instance can be used with any ta
181
168
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
182
169
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
183
170
184
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
185
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
186
-
187
171
This constructor does not store/modify `x`.
188
172
"""
189
- @inline function GradientConfig (f:: F ,
190
- x:: AbstractArray{V} ,
191
- c:: Chunk{N} = Chunk (x)) where {F,V,N}
192
- T = maketag (f, V)
193
- return GradientConfig (f,x,c,T)
194
- end
195
-
196
173
function GradientConfig (f:: F ,
197
174
x:: AbstractArray{V} ,
198
- :: Chunk{N} ,
199
- :: T ) where {F,V,N,T}
175
+ :: Chunk{N} = Chunk (x) ,
176
+ :: T = Tag (f, V) ) where {F,V,N,T}
200
177
seeds = construct_seeds (Partials{N,V})
201
178
duals = similar (x, Dual{T,V,N})
202
179
return GradientConfig {T,V,N,typeof(duals)} (seeds, duals)
@@ -228,22 +205,12 @@ If `f` or `tag` is `nothing`, then the returned instance can be used with any ta
228
205
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
229
206
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
230
207
231
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
232
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
233
-
234
208
This constructor does not store/modify `x`.
235
209
"""
236
- @inline function JacobianConfig (f:: F ,
237
- x:: AbstractArray{V} ,
238
- c:: Chunk{N} = Chunk (x)) where {F,V,N}
239
- T = maketag (f, V)
240
- return JacobianConfig (f,x,c,T)
241
- end
242
-
243
210
function JacobianConfig (f:: F ,
244
211
x:: AbstractArray{V} ,
245
- :: Chunk{N} ,
246
- :: T ) where {F,V,N,T}
212
+ :: Chunk{N} = Chunk (x) ,
213
+ :: T = Tag (f, V) ) where {F,V,N,T}
247
214
seeds = construct_seeds (Partials{N,V})
248
215
duals = similar (x, Dual{T,V,N})
249
216
return JacobianConfig {T,V,N,typeof(duals)} (seeds, duals)
@@ -263,24 +230,13 @@ If `f!` or `tag` is `nothing`, then the returned instance can be used with any t
263
230
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
264
231
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
265
232
266
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
267
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
268
-
269
233
This constructor does not store/modify `y` or `x`.
270
234
"""
271
- @inline function JacobianConfig (f:: F ,
272
- y:: AbstractArray{Y} ,
273
- x:: AbstractArray{X} ,
274
- c:: Chunk{N} = Chunk (x)) where {F,Y,X,N}
275
- T = maketag (f, X)
276
- return JacobianConfig (f,y,x,c,T)
277
- end
278
-
279
235
function JacobianConfig (f:: F ,
280
236
y:: AbstractArray{Y} ,
281
237
x:: AbstractArray{X} ,
282
- :: Chunk{N} ,
283
- :: T ) where {F,Y,X,N,T}
238
+ :: Chunk{N} = Chunk (x) ,
239
+ :: T = Tag (f, X) ) where {F,Y,X,N,T}
284
240
seeds = construct_seeds (Partials{N,X})
285
241
yduals = similar (y, Dual{T,Y,N})
286
242
xduals = similar (x, Dual{T,X,N})
@@ -316,22 +272,12 @@ If `f` or `tag` is `nothing`, then the returned instance can be used with any ta
316
272
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
317
273
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
318
274
319
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
320
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
321
-
322
275
This constructor does not store/modify `x`.
323
276
"""
324
- @inline function HessianConfig (f:: F ,
325
- x:: AbstractArray{V} ,
326
- chunk:: Chunk = Chunk (x)) where {F,V}
327
- T = maketag (f, V)
328
- return HessianConfig (f, x, chunk, T)
329
- end
330
-
331
277
function HessianConfig (f:: F ,
332
278
x:: AbstractArray{V} ,
333
- chunk:: Chunk ,
334
- tag) where {F,V}
279
+ chunk:: Chunk = Chunk (x) ,
280
+ tag = Tag (f, V) ) where {F,V}
335
281
jacobian_config = JacobianConfig (f, x, chunk, tag)
336
282
gradient_config = GradientConfig (f, jacobian_config. duals, chunk, tag)
337
283
return HessianConfig (jacobian_config, gradient_config)
@@ -350,24 +296,13 @@ If `f` or `tag` is `nothing`, then the returned instance can be used with any ta
350
296
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
351
297
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
352
298
353
- If `tag` is `:hash`, a small hash-based tag is provided. This tracks perturbation confusion
354
- with similar accuracy, but is much smaller than `tag = :type`, which stores the full type.
355
-
356
299
This constructor does not store/modify `x`.
357
300
"""
358
- @inline function HessianConfig (f:: F ,
359
- result:: DiffResult ,
360
- x:: AbstractArray{V} ,
361
- chunk:: Chunk = Chunk (x)) where {F,V}
362
- T = maketag (f, V)
363
- return HessianConfig (f, result, x, chunk, T)
364
- end
365
-
366
301
function HessianConfig (f:: F ,
367
302
result:: DiffResult ,
368
303
x:: AbstractArray{V} ,
369
- chunk:: Chunk ,
370
- tag) where {F,V}
304
+ chunk:: Chunk = Chunk (x) ,
305
+ tag = Tag (f, V) ) where {F,V}
371
306
jacobian_config = JacobianConfig ((f,gradient), DiffResults. gradient (result), x, chunk, tag)
372
307
gradient_config = GradientConfig (f, jacobian_config. duals[2 ], chunk, tag)
373
308
return HessianConfig (jacobian_config, gradient_config)
0 commit comments