Out of convenience I’m wrapping a scaled interpolation from Interpolations.jl
:
grid_x = 0:0.1:100.0
grid_y = 0:0.1:100.0
f(x, y) = (x + y)^2
farr = [f(x, y) for x in grid_x, y in grid_y]
using Interpolations
function interp1(grid_x, grid_y, farr)
itp = interpolate(farr, BSpline(Cubic(Line())), OnGrid())
sitp = scale(itp, grid_x, grid_y)
return sitp
end
interp(grid_x, grid_y, xy) = interp1(grid_x, grid_y, farr)[xy...]
xy = [0.01, 0.02]
@code_warntype interp(grid_x, grid_y, xy)
Variables:
#self# <optimized out>
grid_x::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
grid_y::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
xy::Array{Float64,1}
itp::Interpolations.BSplineInterpolation{_,_,_,Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,_} where _ where _ where _ where _
sitp::Any
Body:
begin
SSAValue(0) = Main.farr
$(Expr(:inbounds, false))
# meta: location In[4] interp1 3
itp::Interpolations.BSplineInterpolation{_,_,_,Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,_} where _ where _ where _ where _ = (Main.interpolate)(SSAValue(0), $(QuoteNode(Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}}())), $(QuoteNode(Interpolations.OnGrid())))::Interpolations.BSplineInterpolation{_,_,_,Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,_} where _ where _ where _ where _ # line 4:
sitp::Any = (Main.scale)(itp::Interpolations.BSplineInterpolation{_,_,_,Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,_} where _ where _ where _ where _, grid_x::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, grid_y::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}})::Any
# meta: pop location
$(Expr(:inbounds, :pop))
return (Core._apply)(Main.getindex, (Core.tuple)(sitp::Any)::Tuple{Any}, xy::Array{Float64,1})::Any
end::Any
How can I improve inference to get rid of the Any
s? I tried annotating the output and arguments of interp1
and interp
but I still get some Any
s in the body.