Multi Dimension Interpolation with Unitful

I am trying to interpolate f : \mathbb{R_{units}} \to \mathbb{R_{units}}^3 where there are unitful units on both the grid and the data.

I found this example that showed me how to get f : \mathbb{R} \to \mathbb{R}^3 interpolation working without units, but when I add units it errors out.

This works fine:

f(a) = 2*a * u"A"
agrid = (0:0.5:5) * u"A"
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

And so does this:

f(a) = [1*a, 2*a, 3*a]
agrid = (0:0.5:5) 
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

But when I combine multi-dim and Units it doesn’t work:

f(a) = [2*a, 1*a, 3*a] * u"A"
agrid = (0:0.5:5) * u"A"
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

It throws:

MethodError: no method matching Interpolations.GriddedInterpolation(::Type{Unitful.Quantity{Float64, 𝐈^2, Unitful.FreeUnits{(A^2,), 𝐈^2, nothing}}}, ::Tuple{StepRangeLen{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}, Base.TwicePrecision{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}}, Base.TwicePrecision{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}}, Int64}}, ::Vector{Vector{Unitful.Quantity{Float64, 𝐈^2, Unitful.FreeUnits{(A^2,), 𝐈^2, nothing}}}}, ::Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}})

The type `Interpolations.GriddedInterpolation` exists, but no method is defined for this combination of argument types when trying to construct it.

Is there something I am doing wrong or is Unitful not yet fully supported in Interpolations? (I have run into that with other packages, most work surprisingly well with units but not always)

See if this solution helps, basically collecting the ranges to arrays.

Thanks, no I still get the same error when they are vectors.

But maybe I will just use a similar wrapper like they were using to strip and re-attatch units :frowning: