API
PreallocationTools.DiffCache
— TypeDiffCache(u::AbstractArray, N::Int = ForwardDiff.pickchunksize(length(u)); levels::Int = 1)
DiffCache(u::AbstractArray; N::AbstractArray{<:Int})
Builds a DiffCache
object that stores both a version of the cache for u
and for the Dual
version of u
, allowing use of pre-cached vectors with forward-mode automatic differentiation via ForwardDiff.jl. Supports nested AD via keyword levels
or specifying an array of chunk sizes.
The DiffCache
also supports sparsity detection via SparseConnectivityTracer.jl.
PreallocationTools.FixedSizeDiffCache
— MethodFixedSizeDiffCache(u::AbstractArray, N = Val{default_cache_size(length(u))})
Builds a FixedSizeDiffCache
object that stores both a version of the cache for u
and for the Dual
version of u
, allowing use of pre-cached vectors with forward-mode automatic differentiation.
PreallocationTools.GeneralLazyBufferCache
— Typeb = GeneralLazyBufferCache(f=identity)
A lazily allocated buffer object. Given an array u
, b[u]
returns a cache object generated by f(u)
, but the generator is only run the first time (and all subsequent times it reuses the same cache)
Limitation
The main limitation of this method is that its return is not type-inferred, and thus it can be slower than some other preallocation techniques. However, if used correct using things like function barriers, then this is a general technique that is sufficiently fast.
PreallocationTools.LazyBufferCache
— Typeb = LazyBufferCache(f = identity; initializer! = identity)
A lazily allocated buffer object. Given an array u
, b[u]
returns an array of the same type and size f(size(u))
(defaulting to the same size), which is allocated as needed and then cached within b
for subsequent usage.
By default the created buffers are not initialized, but a function initializer!
can be supplied which is applied to the buffer when it is created, for instance buf -> fill!(buf, 0.0)
.
Optionally, the size can be explicitly given at calltime using b[u,s]
, which will return a cache of size s
.
PreallocationTools.get_tmp
— Methodget_tmp(dc::DiffCache, u)
Returns the Dual
or normal cache array stored in dc
based on the type of u
.