@@ -10,37 +10,24 @@ struct FixedSizeDiffCache{T <: AbstractArray, S <: AbstractArray}
1010end
1111
1212# Mutable container to hold dual array creator that can be updated by extension
13- const DUAL_ARRAY_CREATOR = Ref {Union{Nothing,Function}} ( nothing )
13+ dualarraycreator (args ... ) = nothing
1414
1515function FixedSizeDiffCache (u:: AbstractArray{T} , siz,
1616 :: Type{Val{chunk_size}} ) where {T, chunk_size}
17- # Try to use ForwardDiff if available, otherwise fallback
18- x = if ! isnothing (DUAL_ARRAY_CREATOR[])
19- DUAL_ARRAY_CREATOR[](u, siz, Val{chunk_size})
20- else
21- similar (u, siz... )
22- end
17+ dualarraycreator (u, siz, Val{chunk_size})
2318 xany = Any[]
2419 FixedSizeDiffCache (deepcopy (u), x, xany)
2520end
2621
22+ forwarddiff_compat_chunk_size (n) = nothing
23+
2724"""
2825`FixedSizeDiffCache(u::AbstractArray, N = Val{default_cache_size(length(u))})`
2926
3027Builds a `FixedSizeDiffCache` object that stores both a version of the cache for `u`
3128and for the `Dual` version of `u`, allowing use of pre-cached vectors with
3229forward-mode automatic differentiation.
3330"""
34- # Default chunk size calculation without ForwardDiff
35- default_chunk_size (n) = min (n, 12 )
36-
37- # Mutable container to hold chunk size function that can be updated by extension
38- const CHUNK_SIZE_FUNC = Ref {Function} (default_chunk_size)
39-
40- function forwarddiff_compat_chunk_size (n)
41- CHUNK_SIZE_FUNC[](n)
42- end
43-
4431function FixedSizeDiffCache (u:: AbstractArray ,
4532 :: Type{Val{N}} = Val{forwarddiff_compat_chunk_size (length (u))}) where {
4633 N,
0 commit comments