Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/auxiliary/caches.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
"""
const GLOBAL_CACHES

Registry of the global caches TensorKit maintains, as `name => cache` pairs.

See also [`empty_globalcaches!`](@ref) and [`global_cache_info`](@ref).
"""
const GLOBAL_CACHES = Pair{Symbol, Any}[]

"""
empty_globalcaches!()

Empty every global cache in [`GLOBAL_CACHES`](@ref).
Comment thread
lkdvos marked this conversation as resolved.
These mostly contain bookkeeping for various different index manipulations and tensor structures,
so clearing this out can free up some memory whenever you have a workflow that involves a large variety of structures.
For example, you may want to clear the cache when working with different symmetries, or in algorithms that dynamically alter the sizes of tensors.
Since everything is recomputed on demand, this is purely a memory measure.

See also [`global_cache_info`](@ref) to display the status.
"""
function empty_globalcaches!()
foreach(empty! ∘ last, GLOBAL_CACHES)
return nothing
end

"""
global_cache_info([io::IO = stdout])

Print the hit/miss statistics and current size of every global cache in [`GLOBAL_CACHES`](@ref).

See also [`empty_globalcaches!`](@ref).
"""
function global_cache_info(io::IO = stdout)
for (name, cache) in GLOBAL_CACHES
println(io, name, ":\t", LRUCache.cache_info(cache))
Expand Down