Hi,
I have a loop where I need to create new interpolants each time. I would like to know if I can somehow pre allocate the interpolant in Interpolations.jl so I don’t have to create new memory allocation at each iteration of the loop. The loop is iterating through the same grid each time with only the values to interpolate that changes.
Here is a MWE taking the example in Interpolations.jl:
xs = 1:0.2:5
A = log.(xs)
# Create linear interpolation object without extrapolation
for _ in 1:5
interp_linear = linear_interpolation(xs, A)
end
I tried to use the type of inter_linear to pre allocate but it doesn’t seem to work:
interp_linear = Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Throw{Nothing}}
for _ in 1:5
interp_linear .= linear_interpolation(xs, A)
end
error with ERROR: CanonicalIndexError: setindex! not defined for Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Throw{Nothing}}