JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia

Home Page:http://juliamath.github.io/Interpolations.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interpolation bug when calling without extrapolate

henry2004y opened this issue · comments

I am using Interpolations.jl v0.14.7 (because another low level package KernelDensity has not updated its compatibility).

julia> using Interpolations

julia> itp0 = interpolate([1, 2, 3, 4], BSpline(Linear()))
4-element interpolate(::Vector{Float64}, BSpline(Linear())) with element type Float64:
Error showing value of type Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}:
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
  [1] getindex(t::Tuple, i::Int64)
    @ Base .\tuple.jl:31
  [2] _checklubounds(tf::Bool, ls::Tuple{}, us::Tuple{}, xs::Tuple{Int64})
    @ Interpolations C:\Users\hyzho\.julia\packages\Interpolations\nDwIa\src\Interpolations.jl:420

However the following is fine:

etp = extrapolate(interpolate([1,2,3,4], BSpline(Linear())), Periodic())

I found this while reading the documentation on periodic extrapolation.

julia> using Pkg

julia> Pkg.status()
Status `/private/var/folders/5j/phv_vfc97m967ww98fbvtmfr0000gq/T/jl_NVMMuQ/Project.toml`
⌃ [a98d9a8b] Interpolations v0.14.7
Info Packages marked with ⌃ have new versions available and may be upgradable.

julia> itp0 = interpolate([1,2,3,4], BSpline(Linear()))
4-element interpolate(::Vector{Float64}, BSpline(Linear())) with element type Float64:
 1.0
 2.0
 3.0
 4.0

I cannot reproduce the problem on v0.14.7.

Hmm, that's strange. Maybe it's because I'm running on Julia v1.10.0-rc2?

⌅ [a98d9a8b] Interpolations v0.14.7
julia> versioninfo()
Julia Version 1.10.0-rc2
Commit dbb9c46795 (2023-12-03 15:25 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
  Threads: 1 on 12 virtual cores

julia> using Interpolations

julia> itp0 = interpolate([1, 2, 3, 4], BSpline(Linear()))
4-element interpolate(::Vector{Float64}, BSpline(Linear())) with element type Float64:
Error showing value of type Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}:
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
  [1] getindex(t::Tuple, i::Int64)
    @ Base .\tuple.jl:31
  [2] _checklubounds(tf::Bool, ls::Tuple{}, us::Tuple{}, xs::Tuple{Int64})
    @ Interpolations C:\Users\hyzho\.julia\packages\Interpolations\nDwIa\src\Interpolations.jl:420