Gridded Interpolation using Interpolation.jl not working in VSCode (but working in regular Julia repl)

Hi, I’d like to interpolate data from a 2d array in which the spacing is nonuniform. A is an 11x13 array that is imported from a .csv file, so below I just made it a random array of values (should be good enough while I’m debugging).

using Interpolations

alpha = [-20;-15;-10;-4;-1;0;1;4;10;15;20] #11x1 array nonuniform spacing
mach = [0.1;0.3;0.7;0.8;0.9;1.2;1.5;2.0;3.0;5.0;7.0;8.0;9.0] #13x1 array nonuniform spacing
A = rand(11, 13) #e.g. A[6, 1] should correspond to value with alpha = 0 and mach = 0.1

nodes = ([alpha], [mach])
interp = interpolate(nodes, A, Gridded(Linear()))
display(interp(0.25, 1.4))

This seems to me to follow the Gridded Interpolation example from Interpolation algorithms · Interpolations.jl
however outputs the following error:

ERROR: MethodError: no method matching interpolate(::Tuple{Vector{Matrix{Int64}}, Vector{Matrix{Float64}}}, ::Matrix{Float64}, ::Gridded{Linear{Throw{OnGrid}}})
Closest candidates are:
  interpolate(::Any, ::Any, ::Any, ::Any, ::Any) at c:\Git\sep_dynamics_julia\scripts\relative_motion.jl:37
  interpolate(::Any, ::Any) at c:\Git\sep_dynamics_julia\scripts\relative_motion.jl:36

The first “closest candidate” seems to me to suggest that it is expecting a 5th input, so I changed interp to interp = interpolate(nodes, A, Gridded(Linear()), Gridded(Linear())) but that simply produces the same output.

I’m not sure where to go from here, any help would be much appreciated. Thanks in advance!

You’re passing your knots as a tuple of vectors of vectors instead of a tuple of vectors.

julia> typeof(nodes)
Tuple{Vector{Vector{Int64}}, Vector{Vector{Float64}}}

julia> interp = interpolate((alpha, mach), A, Gridded(Linear()))
11×13 interpolate((::Vector{Int64},::Vector{Float64}), ::Matrix{Float64}, Gridded(Linear())) with element type Float64:
 0.279071   0.332534    0.287125    0.0237718  0.0798587  …  0.449468   0.662033   0.172981   0.93074   0.561894
 0.0788037  0.335184    0.0122311   0.27252    0.0515833     0.451489   0.102317   0.431503   0.113232  0.781979
 0.583828   0.617984    0.609332    0.149146   0.121515      0.769664   0.925578   0.538336   0.943607  0.84304
[...]

Thanks for your reply. I see what you’re saying, so I changed my code to

using Interpolations

alpha = [-20;-15;-10;-4;-1;0;1;4;10;15;20] #11x1 array nonuniform spacing
mach = [0.1;0.3;0.7;0.8;0.9;1.2;1.5;2.0;3.0;5.0;7.0;8.0;9.0] #13x1 array nonuniform spacing
A = rand(11, 13) #e.g. A[6, 1] should correspond to value with alpha = 0 and mach = 0.1

nodes = (alpha, mach)
interp = interpolate(nodes, A, Gridded(Linear()))
display(interp(0.25, 1.4))

however, I’m still getting an error for a tuple of matrices.

ERROR: MethodError: no method matching interpolate(::Tuple{Matrix{Int64}, Matrix{Float64}}, ::Matrix{Float64}, ::Gridded{Linear{Throw{OnGrid}}})
Closest candidates are:
  interpolate(::Any, ::Any, ::Any, ::Any, ::Any) at c:\Git\sep_dynamics_julia\scripts\relative_motion.jl:37

and equivalently for a tuple of vectors if I instead do
interp = interpolate((alpha[:], mach[:]), A, Gridded(Linear()))

ERROR: MethodError: no method matching interpolate(::Tuple{Vector{Int64}, Vector{Float64}}, ::Matrix{Float64}, ::Gridded{Linear{Throw{OnGrid}}})
Closest candidates are:
  interpolate(::Any, ::Any, ::Any, ::Any, ::Any) at c:\Git\sep_dynamics_julia\scripts\relative_motion.jl:37

Edit: it works completely fine when I execute this in the Julia REPL. However, when I implement in VSCode I receive the errors.

It seems like this could be a bigger issue with my setup in VSCode. Any ideas as to the discrepancy are welcomed.

Seems similar to this issue: MethodError occur running under viscode-REPL but not under normal REPL · Issue #1404 · julia-vscode/julia-vscode · GitHub

which seems to suggest I could be dealing with a Julia bug instead?

It’s possible that you’re dealing with a VSCode plugin bug, but that particular issue was fixed two years ago, so before troubleshooting further, you’ll want to first make sure that your VSCode plugins are up to date and try restarting the editor.

Can’t repro that issue. Are you on the latest version of the Julia extension?

Well restarting the editor worked! Thanks for all your input.