How to initialize array of arrays with specific type?

What you are using to fill the array A is the DataType of the interpolation. To use A[1] = ... you need an array of instances of the interpolation. For example:

julia> b = interpolate( B, BSpline(Cubic(Line(OnGrid()))));

julia> A = fill(copy(b), 10);

julia> A[1] = interpolate( B, BSpline(Cubic(Line(OnGrid()))));

Otherwise you may just want an empty array of interpolations, such as:

julia> A = typeof(b)[]
Interpolations.BSplineInterpolation{Float64, 2, OffsetMatrix{Float64, Matrix{Float64}}, BSpline{Cubic{Line{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}[]

julia> push!(A, interpolate( B, BSpline(Cubic(Line(OnGrid())))))
1-element Vector{Interpolations.BSplineInterpolation{Float64, 2, OffsetMatrix{Float64, Matrix{Float64}}, BSpline{Cubic{Line{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}:
 [0.6382324838466641 0.15737452960821852 … 0.39607517204553827 0.15889649188608557; 0.13177398720760136 0.6391502891054832 … 0.9749632710156909 0.23570550771235294; … ; 0.26655297042787274 0.3298620168301782 … 0.09981476823205598 0.3372852663412892; 0.4963880643359818 0.10982508349889288 … 0.792355741208348 0.5513251663389037]

but then you need to push! to it.

(of if you really want an array of empty arrays of interpolations, A = fill(typeof(b)[], 10,20), in which case you need push!(A[1], interpolate(...)). )

1 Like