Open
Description
With the MWE
using Interpolations
a = range(2, 7; length = 10) # > 1
J = 1:5
W = a .+ permutedims(J)
mapslices(S -> LinearInterpolation((a, ), S), W; dims = (1, ))
it is easy to run into something like a
julia> mapslices(S -> LinearInterpolation((a, ), S), W; dims = (1, ))
ERROR: BoundsError: attempt to access 10-element extrapolate(scale(interpolate(::Array{Float64,1}, BSpline(Linear())), (2.0:0.5555555555555556:7.0,)), Throw()) with element type Float64 at index [1]
Stacktrace:
[1] throw_boundserror(::Interpolations.Extrapolation{Float64,1,ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},BSpline{Linear},Tuple{Base.OneTo{Int64}}},BSpline{Linear},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}},BSpline{Linear},Throw{Nothing}}, ::Tuple{Int64}) at ./abstractarray.jl:493
The root cause seems to be that using getindex
with interpolated calculation is not consistent with eg axes
:
julia> slice1 = LinearInterpolation((a, ), W[:, 1]);
julia> slice1 isa AbstractArray
true
julia> axes(slice1)
(Base.OneTo(10),)
julia> slice1[1] # ouch
ERROR: BoundsError: attempt to access 10-element extrapolate(scale(interpolate(::Array{Float64,1}, BSpline(Linear())), (2.0:0.5555555555555556:7.0,)), Throw()) with element type Float64 at index [1]
Stacktrace:
[1] throw_boundserror(::Interpolations.Extrapolation{Float64,1,ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},BSpline{Linear},Tuple{Base.OneTo{Int64}}},BSpline{Linear},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}},BSpline{Linear},Throw{Nothing}}, ::Tuple{Int64}) at ./abstractarray.jl:493
[2] inbounds_index at /home/tamas/.julia/dev/Interpolations/src/extrapolation/extrapolation.jl:102 [inlined]
[3] inbounds_position at /home/tamas/.julia/dev/Interpolations/src/extrapolation/extrapolation.jl:93 [inlined]
[4] Extrapolation at /home/tamas/.julia/dev/Interpolations/src/extrapolation/extrapolation.jl:43 [inlined]
[5] getindex(::Interpolations.Extrapolation{Float64,1,ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},BSpline{Linear},Tuple{Base.OneTo{Int64}}},BSpline{Linear},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}},BSpline{Linear},Throw{Nothing}}, ::Int64) at /home/tamas/.julia/dev/Interpolations/src/Interpolations.jl:403
[6] top-level scope at REPL[30]:1
Suggestion: don't use getindex
for this purpose.
Metadata
Metadata
Assignees
Labels
No labels