Memoization.jl
Memoization.jl copied to clipboard
make it possible to ignore parameters
This is probably either too much work or outside of the scope of the package altogether, but it would be very useful if there was a way to tell the macro which of the function parameters are expected to vary between function calls.
For example:
@memoize Dict function propActiveAgents(model, state, pars)
n = count(a -> a.state == state, model.pop)
n/length(model.pop)
end
In this case effectively only the parameter state will vary between function calls. model
(or model.pop
) could change as well, but in a realistic real-world scenario I will refresh the memoization cache manually, for example every time step, rather than letting @memoize
detect the change in model state as that would be vastly less efficient. The third parameter, pars
isn't used at all in this case but needs to be there for API consistency.
As it works now, a tuple of all three parameters will be used as a key in a Dict{Any, Any}
if I understand the implementation correctly. If there was a way to tell the macro that it should only use state
as an index, however, I could for example choose Array{Float64}
as a container type, which would be a lot more efficient.