Skip to content

Commit 7a99367

Browse files
committed
Add abstract type for utiltiy processing steps
1 parent c65ce76 commit 7a99367

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

docs/src/literate/howto/caching.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include("../../literate/example/example_include_all.jl") #hide
1010
# This How-To builds on the results of the example sections.
1111

1212
# ## ProcessResultCache
13-
# The caching mechanism is based on the `ProcessResultCache` type. This type wraps around a different `ÀbstractImageReconstructionParameter` and caches the result of a processing step.
13+
# The caching mechanism is based on the `ProcessResultCache` type. This type wraps around a different `AbstractImageReconstructionParameter` and caches the result of a processing step.
1414
# Such a `process`ing step which offer functionality to other `process` steps is a `AbstractUtilityReconstructionParameter`. These utility steps should return the same result as if the inner step was called directly.
1515

1616
# The cache itself is connected to a `RecoPlan` and any instances build from the same plan instance share this cache and can reuse the result of the processing step.

src/AlgorithmInterface.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export AbstractUtilityReconstructionParameters
2020
2121
Abstract type that offer utility functions for a given reconstruction parameter and its associated `process` steps. Utility `process` steps should return the same result as `T` for the same inputs.
2222
"""
23-
abstract type AbstractUtilityReconstructionParameters{T <: AbstractImageReconstructionParameters} end
23+
abstract type AbstractUtilityReconstructionParameters{T <: AbstractImageReconstructionParameters} <: AbstractImageReconstructionParameters end
2424

2525
export put!, take!
2626
"""
@@ -122,4 +122,10 @@ export parameter
122122
123123
Return the parameters of the algorithm `algo`.
124124
"""
125-
parameter(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement parameter")
125+
parameter(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement `parameter`")
126+
"""
127+
parameter(param::AbstractUtilityReconstructionParameters)
128+
129+
Return the wrapped parameter. Can themselves be utility parameters again
130+
"""
131+
parameter(param::AbstractUtilityReconstructionParameters) = error("$(typeof(param)) must implement `parameter`")

src/RecoPlans/Cache.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ export ProcessResultCache
55
Cache of size `maxsize` for the result of `process` methods. The cache is based on the `hash` of the inputs of the `process` function. Cache is shared between all algorithms constructed from the same plan.
66
The cache is transparent for properties of the underlying parameter. Cache can be invalidated by calling `empty!` on the cache.
77
"""
8-
Base.@kwdef mutable struct ProcessResultCache{P} <: AbstractUtilityReconstructionParameters{P}
8+
mutable struct ProcessResultCache{P} <: AbstractUtilityReconstructionParameters{P}
99
param::P
10-
const maxsize::Int64 = 1
11-
cache::LRU{UInt64, Any} = LRU{UInt64, Any}(maxsize = maxsize)
10+
const maxsize::Int64
11+
cache::LRU{UInt64, Any}
12+
function ProcessResultCache(; param::Union{P, AbstractUtilityReconstructionParameters{P}}, maxsize::Int64 = 1, cache::LRU{UInt64, Any} = LRU{UInt64, Any}(maxsize = maxsize)) where P
13+
return new{P}(param, maxsize, cache)
14+
end
1215
end
1316
ProcessResultCache(param::AbstractImageReconstructionParameters; kwargs...) = ProcessResultCache(;param, kwargs...)
1417
process(algo::A, param::ProcessResultCache, inputs...) where {A <: AbstractImageReconstructionAlgorithm} = hashed_process(algo, param, inputs...)
1518
process(algoT::Type{<:A}, param::ProcessResultCache, inputs...) where {A <: AbstractImageReconstructionAlgorithm} = hashed_process(algoT, param, inputs...)
19+
parameter(param::ProcessResultCache) = param.param
1620

1721
function hashed_process(algo, param::ProcessResultCache, inputs...)
1822
id = hash(param.param, hash(inputs, hash(algo)))

0 commit comments

Comments
 (0)