Interpolations.jl: Saving the object

Hi,

I’m using the Interpolations.jl package to approximate a dynamic programming value function and intend to save the interpolated approximation automatically upon completion of the algorithm with the JLD2 package.

I realized however that there are some errors or issues loading the saved Interpolation object be it through packages JLD2 or JLD. For example,

A_x1 = 1:.1:10
A_x2 = 1:.5:20
f(x1, x2) = log(x1+x2)
A = [f(x1,x2) for x1 in A_x1, x2 in A_x2]
itp = interpolate(A, BSpline(Cubic(Line(OnGrid()))))
sitp = Interpolations.scale(itp, A_x1, A_x2)
lala = 0.0

@save "./data_proc/data_proc_structural/test.jld2" sitp
@load "./data_proc/data_proc_structural/test.jld2" sitp

save("./data_proc/data_proc_structural/test2.jld", "stip", sitp)
tmp = load("./data_proc/data_proc_structural/test2.jld", "sitp")

Calling saved JLD2 object through the command sitp returns the following error

Error showing value of type ScaledInterpolation{Float64,2,getfield(JLD2.ReconstructedTypes, Symbol("##Interpolations.BSplineInterpolation{Float64,2,getfield(JLD2.ReconstructedTypes, Symbol("##OffsetArrays.OffsetArray{Float64,2,Array{Float64,2}}#474")),BSpline{Cubic{Line{OnGrid}}},Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}#475")),BSpline{Cubic{Line{OnGrid}}},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}:
ERROR: MethodError: no method matching size(::getfield(JLD2.ReconstructedTypes, Symbol("##Interpolations.BSplineInterpolation{Float64,2,getfield(JLD2.ReconstructedTypes, Symbol("##OffsetArrays.OffsetArray{Float64,2,Array{Float64,2}}#474")),BSpline{Cubic{Line{OnGrid}}},Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}#475")))
Closest candidates are:
  size(::BitArray{1}) at bitarray.jl:70
  size(::BitArray{1}, ::Any) at bitarray.jl:74
  size(::Core.Compiler.StmtRange) at show.jl:1561

Calling saved JLD object through the command tmp["sitp"] returns me this

ERROR: MethodError: no method matching getindex(::getfield(JLD, Symbol("##Interpolations.ScaledInterpolation{Core.Float64,2,Interpolations.BSplineInterpolation{Core.Float64,2,OffsetArrays.OffsetArray{Core.Float64,2,Core.Array{Core.Float64,2}},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line{Interpolations.OnGrid}}},Core.Tuple{Base.OneTo{Core.Int64},Base.OneTo{Core.Int64}}},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line{Interpolations.OnGrid}}},Core.Tuple{Base.StepRangeLen{Core.Float64,Base.TwicePrecision{Core.Float64},Base.TwicePrecision{Core.Float64}},Base.StepRangeLen{Core.Float64,Base.TwicePrecision{Core.Float64},Base.TwicePrecision{Core.Float64}}}}#464")), ::String)
Stacktrace:
 [1] top-level scope at none:0
1 Like