Hi everyone, I'm wondering what the most Julian way to handle the following situation is. I know it can't be complicated, but am not quite sure how to go about it.
I'm doing some simple interpolation using Dierckx.jl <https://github.com/kbarbary/Dierckx.jl>, getting densities of materials from a pressure-temperature pair. I have a type which holds pressure and temperature axes, and density values on the (logarithmic) grid that these define: type LogPTGridEOS logP::LinSpace{Float64} logT::LinSpace{Float64} densities::Matrix{Float64} end I want to be able to easily store and load instances of this type, and am using JLD.jl <https://github.com/JuliaLang/JLD.jl> for this. This lets me save and load from HDF5 ".jld" files, which preserve the type information (nice). To interpolate on the grid, I first need to make an interpolating function, then evaluate it: function call(eos::LogPTGridEOS, P, T) interp_func = Dierckx.Spline2D(collect(eos.logP), collect(eos.logT), eos .densities) # collect because Dierckx needs arrays interpolated_density = Dierckx.evaluate(interp_func, log10(P), log10(T)) # remember this is a log-log grid end But the interpolating function made in that first line could just be called over and over again, avoiding any overhead from reconstructing it (the slow bit). How can I best cache this function for re-use? I considered storing it in the type itself by adding an "interp_func" field, but this messes up saving it via JLD since JLD can't save a pointer. Am I right in thinking I should make a wrapper type which holds the original type plus a reference to the interpolation function, or is there a nicer way to do this? Cheers, Scott
