I’m writing a package that needs to generically interpolate a matrix from a time-series of matrices.
For example, maybe it’s a series of spatial matrices of monthly mean values, that I would like to interpolate to a single matrix of values for a particular day somewhere in the series.
Is there an options in an interpolations package that would handle this kind of thing, giving the options of various splines or linear interpolation?
I also want to run it on a GPU (greedy…), so broadcast operations are good here, including ways I can roll my own. But hopefully without having to define all the spline etc. methods myself.
Ah, interesting. Depending on the size of your array, you could use SMatrix from StaticArrays, which does have a zero defined:
julia> data = [@SMatrix[1.0 2; 3 4], @SMatrix[3.0 4; 5 6]]
2-element Array{SArray{Tuple{2,2},Float64,2,4},1}:
[1.0 2.0; 3.0 4.0]
[3.0 4.0; 5.0 6.0]
julia> itp = interpolate(data, BSpline(Cubic(Line(OnGrid()))))
2-element interpolate(OffsetArray(::Array{SArray{Tuple{2,2},Float64,2,4},1}, 0:3), BSpline(Cubic(Line(OnGrid())))) with element type SArray{Tuple{2,2},Float64,2,4}:
[0.9999999999999999 2.0; 3.0 4.0]
[3.0 4.0; 5.0 6.0]
julia> itp[1.1]
2×2 SArray{Tuple{2,2},Float64,2,4} with indices SOneTo(2)×SOneTo(2):
1.2 2.2
3.2 4.2
Alternatively, if you know the particular sizes of your data but don’t want to use StaticArrays, you could create a wrapper struct around a Matrix{T} and define the relevant methods (probably just zero and basic arithmetic). I did that in the past when I needed to interpolate Vector{Float64}s and it worked fine.
Array doesn’t have zero because there isn’t a way to know how big the zeroed array should be (since zero gets passed the type, not the value). I think SizedArray from StaticArrays should work though, and without the compile time issues for large matrices.
edit: to be more clear, there’s a method for zero that takes a type, and a method that takes a value, so zero(rand(2,2)) works, but zero(typeof(rand(2,2))) does not, and it seems like Interpolations uses the latter one.