You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
We have a depwarn but it is only triggered for non-integer indexes:
julia> li =LinearInterpolation((a, ), W[:,1])
10-element extrapolate(scale(interpolate(::Array{Float64,1}, BSpline(Linear())), (2.0:0.5555555555555556:7.0,)), Throw()) with element type Float64:3.03.5555555555555554.1111111111111114.6666666666666665.2222222222222225.7777777777777786.3333333333333336.8888888888888897.4444444444444458.0
julia> li.itp.itp[4.1]
┌ Warning:`getindex(itp::AbstractInterpolation{T, N}, i::Vararg{Number, N}) where {T, N}` is deprecated, use `itp(i...)` instead.
│ caller = top-level scope at none:0
└ @ Core none:04.722222222222221
Maybe it's time to turn it on for integers too. #242
I don't have time to tackle this in the foreseeable future, though.
With the MWE
it is easy to run into something like a
The root cause seems to be that using
getindex
with interpolated calculation is not consistent with egaxes
:Suggestion: don't use
getindex
for this purpose.The text was updated successfully, but these errors were encountered: