Skip to content

Commit 5ef9860

Browse files
remove docstring changes
clean new dispatches out Update src/config.jl Update src/config.jl Update src/config.jl Update src/config.jl Update src/config.jl Update src/config.jl Update src/config.jl Add a preferences version Update src/config.jl Update src/config.jl
1 parent dd606d7 commit 5ef9860

File tree

2 files changed

+17
-77
lines changed

2 files changed

+17
-77
lines changed

src/config.jl

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ Base.eltype(cfg::AbstractConfig) = eltype(typeof(cfg))
104104
@inline (chunksize(::AbstractConfig{N})::Int) where {N} = N
105105

106106
function maketag(tagstyle::Union{Symbol,Nothing}, f, X)
107-
@static if VERSION v"1.11"
107+
if HASHTAG_MODE_ENABLED
108108
return HashTag(f, X)
109109
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.
113110
return Tag(f, X)
114111
end
115112
end
@@ -136,22 +133,12 @@ If `f!` is `nothing` instead of the actual target function, then the returned in
136133
be used with any target function. However, this will reduce ForwardDiff's ability to catch
137134
and prevent perturbation confusion (see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
138135
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-
142136
This constructor does not store/modify `y` or `x`.
143137
"""
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-
151138
function DerivativeConfig(f::F,
152139
y::AbstractArray{Y},
153140
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}
155142
duals = similar(y, Dual{T,Y,1})
156143
return DerivativeConfig{T,typeof(duals)}(duals)
157144
end
@@ -181,22 +168,12 @@ If `f` or `tag` is `nothing`, then the returned instance can be used with any ta
181168
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
182169
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
183170
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-
187171
This constructor does not store/modify `x`.
188172
"""
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-
196173
function GradientConfig(f::F,
197174
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}
200177
seeds = construct_seeds(Partials{N,V})
201178
duals = similar(x, Dual{T,V,N})
202179
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
228205
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
229206
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
230207
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-
234208
This constructor does not store/modify `x`.
235209
"""
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-
243210
function JacobianConfig(f::F,
244211
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}
247214
seeds = construct_seeds(Partials{N,V})
248215
duals = similar(x, Dual{T,V,N})
249216
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
263230
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
264231
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
265232
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-
269233
This constructor does not store/modify `y` or `x`.
270234
"""
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-
279235
function JacobianConfig(f::F,
280236
y::AbstractArray{Y},
281237
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}
284240
seeds = construct_seeds(Partials{N,X})
285241
yduals = similar(y, Dual{T,Y,N})
286242
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
316272
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
317273
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
318274
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-
322275
This constructor does not store/modify `x`.
323276
"""
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-
331277
function HessianConfig(f::F,
332278
x::AbstractArray{V},
333-
chunk::Chunk,
334-
tag) where {F,V}
279+
chunk::Chunk = Chunk(x),
280+
tag = Tag(f, V)) where {F,V}
335281
jacobian_config = JacobianConfig(f, x, chunk, tag)
336282
gradient_config = GradientConfig(f, jacobian_config.duals, chunk, tag)
337283
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
350296
However, this will reduce ForwardDiff's ability to catch and prevent perturbation confusion
351297
(see https://github.com/JuliaDiff/ForwardDiff.jl/issues/83).
352298
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-
356299
This constructor does not store/modify `x`.
357300
"""
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-
366301
function HessianConfig(f::F,
367302
result::DiffResult,
368303
x::AbstractArray{V},
369-
chunk::Chunk,
370-
tag) where {F,V}
304+
chunk::Chunk = Chunk(x),
305+
tag = Tag(f, V)) where {F,V}
371306
jacobian_config = JacobianConfig((f,gradient), DiffResults.gradient(result), x, chunk, tag)
372307
gradient_config = GradientConfig(f, jacobian_config.duals[2], chunk, tag)
373308
return HessianConfig(jacobian_config, gradient_config)

src/prelude.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
22
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
33

4+
# On ≤1.10, the hash of a type cannot be computed at compile-time,
5+
# making `HashTag(...)` type-unstable, so `Tag(...)` is left as
6+
# as the default.
7+
const HASHTAG_MODE_ENABLED = @load_preference("hashtag_mode", VERSION v"1.11")
8+
49
const AMBIGUOUS_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real, RoundingMode)
510

611
const UNARY_PREDICATES = Symbol[:isinf, :isnan, :isfinite, :iseven, :isodd, :isreal, :isinteger]

0 commit comments

Comments
 (0)