@@ -25,43 +25,43 @@ Tag(::Nothing, ::Type{V}) where {V} = nothing
25
25
end
26
26
27
27
"""
28
- SmallTag {Hash}
28
+ HashTag {Hash}
29
29
30
- SmallTag is similar to a Tag, but carries just a small UInt64 hash,
30
+ HashTag is similar to a Tag, but carries just a small UInt64 hash,
31
31
instead of the full type, which makes stacktraces / types easier to
32
32
read while still providing good resilience to perturbation confusion.
33
33
"""
34
- struct SmallTag {H}
34
+ struct HashTag {H}
35
35
end
36
36
37
- @generated function tagcount (:: Type{SmallTag {H}} ) where {H}
37
+ @generated function tagcount (:: Type{HashTag {H}} ) where {H}
38
38
:($ (Threads. atomic_add! (TAGCOUNT, UInt (1 ))))
39
39
end
40
40
41
- function SmallTag (f:: F , :: Type{V} ) where {F,V}
41
+ function HashTag (f:: F , :: Type{V} ) where {F,V}
42
42
H = if F <: Tuple
43
43
# no easy way to check Jacobian tag used with Hessians as multiple functions may be used
44
44
# see checktag(::Type{Tag{FT,VT}}, f::F, x::AbstractArray{V}) where {FT<:Tuple,VT,F,V}
45
45
nothing
46
46
else
47
47
hash (F) ⊻ hash (V)
48
48
end
49
- tagcount (SmallTag {H}) # trigger generated function
50
- SmallTag {H} ()
49
+ tagcount (HashTag {H}) # trigger generated function
50
+ HashTag {H} ()
51
51
end
52
52
53
- SmallTag (:: Nothing , :: Type{V} ) where {V} = nothing
53
+ HashTag (:: Nothing , :: Type{V} ) where {V} = nothing
54
54
55
- @inline function ≺ (:: Type{SmallTag {H1}} , :: Type{Tag{F2,V2}} ) where {H1,F2,V2}
56
- tagcount (SmallTag {H1}) < tagcount (Tag{F2,V2})
55
+ @inline function ≺ (:: Type{HashTag {H1}} , :: Type{Tag{F2,V2}} ) where {H1,F2,V2}
56
+ tagcount (HashTag {H1}) < tagcount (Tag{F2,V2})
57
57
end
58
58
59
- @inline function ≺ (:: Type{Tag{F1,V1}} , :: Type{SmallTag {H2}} ) where {F1,V1,H2}
60
- tagcount (Tag{F1,V1}) < tagcount (SmallTag {H2})
59
+ @inline function ≺ (:: Type{Tag{F1,V1}} , :: Type{HashTag {H2}} ) where {F1,V1,H2}
60
+ tagcount (Tag{F1,V1}) < tagcount (HashTag {H2})
61
61
end
62
62
63
- @inline function ≺ (:: Type{SmallTag {H1}} , :: Type{SmallTag {H2}} ) where {H1,H2}
64
- tagcount (SmallTag {H1}) < tagcount (SmallTag {H2})
63
+ @inline function ≺ (:: Type{HashTag {H1}} , :: Type{HashTag {H2}} ) where {H1,H2}
64
+ tagcount (HashTag {H1}) < tagcount (HashTag {H2})
65
65
end
66
66
67
67
struct InvalidTagException{E,O} <: Exception
@@ -75,13 +75,13 @@ checktag(::Type{Tag{FT,VT}}, f::F, x::AbstractArray{V}) where {FT,VT,F,V} =
75
75
76
76
checktag (:: Type{Tag{F,V}} , f:: F , x:: AbstractArray{V} ) where {F,V} = true
77
77
78
- # SmallTag is a smaller tag, that only confirms the hash
79
- function checktag (:: Type{SmallTag {HT}} , f:: F , x:: AbstractArray{V} ) where {HT,F,V}
78
+ # HashTag is a smaller tag, that only confirms the hash
79
+ function checktag (:: Type{HashTag {HT}} , f:: F , x:: AbstractArray{V} ) where {HT,F,V}
80
80
H = hash (F) ⊻ hash (V)
81
81
if HT == H || HT === nothing
82
82
true
83
83
else
84
- throw (InvalidTagException {SmallTag {H},SmallTag {HT}} ())
84
+ throw (InvalidTagException {HashTag {H},HashTag {HT}} ())
85
85
end
86
86
end
87
87
@@ -103,21 +103,21 @@ Base.eltype(cfg::AbstractConfig) = eltype(typeof(cfg))
103
103
104
104
@inline (chunksize (:: AbstractConfig{N} ):: Int ) where {N} = N
105
105
106
- function maketag (kind :: Union{Symbol,Nothing} , f, X)
107
- if kind === :default
106
+ function maketag (tagstyle :: Union{Symbol,Nothing} , f, X)
107
+ if tagstyle === :default
108
108
@static if VERSION ≥ v " 1.11"
109
- return SmallTag (f, X)
109
+ return HashTag (f, X)
110
110
else
111
111
# On ≤1.10, the hash of a type cannot be computed at compile-time,
112
- # making `SmallTag (...)` type-unstable, so `Tag(...)` is left as
112
+ # making `HashTag (...)` type-unstable, so `Tag(...)` is left as
113
113
# as the default.
114
114
return Tag (f, X)
115
115
end
116
- elseif kind === :type
116
+ elseif tagstyle === :type
117
117
return Tag (f, X)
118
- elseif kind === :hash
119
- return SmallTag (f, X)
120
- elseif kind === nothing
118
+ elseif tagstyle === :hash
119
+ return HashTag (f, X)
120
+ elseif tagstyle === nothing
121
121
return nothing
122
122
else
123
123
throw (ArgumentError (" tag may be :default, :type, :hash, or nothing" ))
@@ -133,7 +133,7 @@ struct DerivativeConfig{T,D} <: AbstractConfig{1}
133
133
end
134
134
135
135
"""
136
- ForwardDiff.DerivativeConfig(f!, y::AbstractArray, x::Real; tag ::Union{Symbol,Nothing} = :default)
136
+ ForwardDiff.DerivativeConfig(f!, y::AbstractArray, x::Real; tagstyle ::Union{Symbol,Nothing} = :default)
137
137
138
138
Return a `DerivativeConfig` instance based on the type of `f!`, and the types/shapes of the
139
139
output vector `y` and the input value `x`.
@@ -154,13 +154,13 @@ This constructor does not store/modify `y` or `x`.
154
154
@inline function DerivativeConfig (f:: F ,
155
155
y:: AbstractArray{Y} ,
156
156
x:: X ;
157
- tag :: Union{Symbol,Nothing} = :default ) where {F,X<: Real ,Y<: Real }
158
- # @inline ensures that, e.g., DerivativeConfig(...; tag = :small) will be well-inferred
157
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,X<: Real ,Y<: Real }
158
+ # @inline ensures that, e.g., DerivativeConfig(...; tagstyle = :small) will be well-inferred
159
159
@static if VERSION ≥ v " 1.8"
160
- T = @inline maketag (tag , f, X)
160
+ T = @inline maketag (tagstyle , f, X)
161
161
return @noinline DerivativeConfig (f,y,x,T)
162
162
else
163
- T = maketag (tag , f, X)
163
+ T = maketag (tagstyle , f, X)
164
164
return DerivativeConfig (f,y,x,T)
165
165
end
166
166
end
@@ -186,7 +186,7 @@ struct GradientConfig{T,V,N,D} <: AbstractConfig{N}
186
186
end
187
187
188
188
"""
189
- ForwardDiff.GradientConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tag ::Union{Symbol,Nothing} = :default)
189
+ ForwardDiff.GradientConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tagstyle ::Union{Symbol,Nothing} = :default)
190
190
191
191
Return a `GradientConfig` instance based on the type of `f` and type/shape of the input
192
192
vector `x`.
@@ -206,13 +206,13 @@ This constructor does not store/modify `x`.
206
206
@inline function GradientConfig (f:: F ,
207
207
x:: AbstractArray{V} ,
208
208
c:: Chunk{N} = Chunk (x);
209
- tag :: Union{Symbol,Nothing} = :default ) where {F,V,N}
210
- # @inline ensures that, e.g., GradientConfig(...; tag = :small) will be well-inferred
209
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,V,N}
210
+ # @inline ensures that, e.g., GradientConfig(...; tagstyle = :small) will be well-inferred
211
211
@static if VERSION ≥ v " 1.8"
212
- T = @inline maketag (tag , f, V)
212
+ T = @inline maketag (tagstyle , f, V)
213
213
return @noinline GradientConfig (f,x,c,T)
214
214
else
215
- T = maketag (tag , f, V)
215
+ T = maketag (tagstyle , f, V)
216
216
return GradientConfig (f,x,c,T)
217
217
end
218
218
end
@@ -239,7 +239,7 @@ struct JacobianConfig{T,V,N,D} <: AbstractConfig{N}
239
239
end
240
240
241
241
"""
242
- ForwardDiff.JacobianConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tag ::Union{Symbol,Nothing} = :default)
242
+ ForwardDiff.JacobianConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tagstyle ::Union{Symbol,Nothing} = :default)
243
243
244
244
Return a `JacobianConfig` instance based on the type of `f` and type/shape of the input
245
245
vector `x`.
@@ -260,13 +260,13 @@ This constructor does not store/modify `x`.
260
260
@inline function JacobianConfig (f:: F ,
261
261
x:: AbstractArray{V} ,
262
262
c:: Chunk{N} = Chunk (x);
263
- tag :: Union{Symbol,Nothing} = :default ) where {F,V,N}
264
- # @inline ensures that, e.g., JacobianConfig(...; tag = :small) will be well-inferred
263
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,V,N}
264
+ # @inline ensures that, e.g., JacobianConfig(...; tagstyle = :small) will be well-inferred
265
265
@static if VERSION ≥ v " 1.8"
266
- T = @inline maketag (tag , f, V)
266
+ T = @inline maketag (tagstyle , f, V)
267
267
return @noinline JacobianConfig (f,x,c,T)
268
268
else
269
- T = maketag (tag , f, V)
269
+ T = maketag (tagstyle , f, V)
270
270
return JacobianConfig (f,x,c,T)
271
271
end
272
272
end
@@ -281,7 +281,7 @@ function JacobianConfig(f::F,
281
281
end
282
282
283
283
"""
284
- ForwardDiff.JacobianConfig(f!, y::AbstractArray, x::AbstractArray, chunk::Chunk = Chunk(x); tag ::Union{Symbol,Nothing} = :default)
284
+ ForwardDiff.JacobianConfig(f!, y::AbstractArray, x::AbstractArray, chunk::Chunk = Chunk(x); tagstyle ::Union{Symbol,Nothing} = :default)
285
285
286
286
Return a `JacobianConfig` instance based on the type of `f!`, and the types/shapes of the
287
287
output vector `y` and the input vector `x`.
@@ -303,13 +303,13 @@ This constructor does not store/modify `y` or `x`.
303
303
y:: AbstractArray{Y} ,
304
304
x:: AbstractArray{X} ,
305
305
c:: Chunk{N} = Chunk (x);
306
- tag :: Union{Symbol,Nothing} = :default ) where {F,Y,X,N}
307
- # @inline ensures that, e.g., JacobianConfig(...; tag = :small) will be well-inferred
306
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,Y,X,N}
307
+ # @inline ensures that, e.g., JacobianConfig(...; tagstyle = :small) will be well-inferred
308
308
@static if VERSION ≥ v " 1.8"
309
- T = @inline maketag (tag , f, X)
309
+ T = @inline maketag (tagstyle , f, X)
310
310
return @noinline JacobianConfig (f,y,x,c,T)
311
311
else
312
- T = maketag (tag , f, X)
312
+ T = maketag (tagstyle , f, X)
313
313
return JacobianConfig (f,y,x,c,T)
314
314
end
315
315
end
@@ -339,7 +339,7 @@ struct HessianConfig{T,V,N,DG,DJ} <: AbstractConfig{N}
339
339
end
340
340
341
341
"""
342
- ForwardDiff.HessianConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tag ::Union{Symbol,Nothing} = :default)
342
+ ForwardDiff.HessianConfig(f, x::AbstractArray, chunk::Chunk = Chunk(x); tagstyle ::Union{Symbol,Nothing} = :default)
343
343
344
344
Return a `HessianConfig` instance based on the type of `f` and type/shape of the input
345
345
vector `x`.
@@ -362,13 +362,13 @@ This constructor does not store/modify `x`.
362
362
@inline function HessianConfig (f:: F ,
363
363
x:: AbstractArray{V} ,
364
364
chunk:: Chunk = Chunk (x);
365
- tag :: Union{Symbol,Nothing} = :default ) where {F,V}
366
- # @inline ensures that, e.g., HessianConfig(...; tag = :small) will be well-inferred
365
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,V}
366
+ # @inline ensures that, e.g., HessianConfig(...; tagstyle = :small) will be well-inferred
367
367
@static if VERSION ≥ v " 1.8"
368
- T = @inline maketag (tag , f, V)
368
+ T = @inline maketag (tagstyle , f, V)
369
369
return @noinline HessianConfig (f, x, chunk, T)
370
370
else
371
- T = maketag (tag , f, V)
371
+ T = maketag (tagstyle , f, V)
372
372
return HessianConfig (f, x, chunk, T)
373
373
end
374
374
end
@@ -383,7 +383,7 @@ function HessianConfig(f::F,
383
383
end
384
384
385
385
"""
386
- ForwardDiff.HessianConfig(f, result::DiffResult, x::AbstractArray, chunk::Chunk = Chunk(x); tag ::Union{Symbol,Nothing} = :default)
386
+ ForwardDiff.HessianConfig(f, result::DiffResult, x::AbstractArray, chunk::Chunk = Chunk(x); tagstyle ::Union{Symbol,Nothing} = :default)
387
387
388
388
Return a `HessianConfig` instance based on the type of `f`, types/storage in `result`, and
389
389
type/shape of the input vector `x`.
@@ -404,13 +404,13 @@ This constructor does not store/modify `x`.
404
404
result:: DiffResult ,
405
405
x:: AbstractArray{V} ,
406
406
chunk:: Chunk = Chunk (x);
407
- tag :: Union{Symbol,Nothing} = :default ) where {F,V}
408
- # @inline ensures that, e.g., HessianConfig(...; tag = :small) will be well-inferred
407
+ tagstyle :: Union{Symbol,Nothing} = :default ) where {F,V}
408
+ # @inline ensures that, e.g., HessianConfig(...; tagstyle = :small) will be well-inferred
409
409
@static if VERSION ≥ v " 1.8"
410
- T = @inline maketag (tag , f, V)
410
+ T = @inline maketag (tagstyle , f, V)
411
411
return @noinline HessianConfig (f, result, x, chunk, T)
412
412
else
413
- T = maketag (tag , f, V)
413
+ T = maketag (tagstyle , f, V)
414
414
return HessianConfig (f, result, x, chunk, T)
415
415
end
416
416
end
0 commit comments