Skip to content

PCHIPInterpolation for 2 data points is broken #446

@SouthEndMusic

Description

@SouthEndMusic

I understand that for a degree > 1 interpolation having only 2 data points doesn't make sense, but I feel like this edge case should be dealt with better than a vague index error:

julia> PCHIPInterpolation([1.0, 1.0], [1.0, 2.0])
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [2]
Stacktrace:
  [1] throw_boundserror(A::Vector{Float64}, I::Tuple{Int64})
    @ Base .\essentials.jl:14
  [2] getindex
    @ .\essentials.jl:916 [inlined]
  [3] (::DataInterpolations.var"#_du#55"{…})(k::Int64)
    @ DataInterpolations C:\ProgramData\DEVDrives\.julia\packages\DataInterpolations\TCMJ8\src\interpolation_utils.jl:284
  [4] _broadcast_getindex_evalf
    @ .\broadcast.jl:678 [inlined]
  [5] _broadcast_getindex
    @ .\broadcast.jl:651 [inlined]
  [6] getindex
    @ .\broadcast.jl:610 [inlined]
  [7] macro expansion
    @ .\broadcast.jl:973 [inlined]
  [8] macro expansion
    @ .\simdloop.jl:77 [inlined]
  [9] copyto!
    @ .\broadcast.jl:972 [inlined]
 [10] copyto!
    @ .\broadcast.jl:925 [inlined]
 [11] copy
    @ .\broadcast.jl:897 [inlined]
 [12] materialize
    @ .\broadcast.jl:872 [inlined]
 [13] du_PCHIP(u::Vector{Float64}, t::Vector{Float64})
    @ DataInterpolations C:\ProgramData\DEVDrives\.julia\packages\DataInterpolations\TCMJ8\src\interpolation_utils.jl:314
 [14] #PCHIPInterpolation#32
    @ C:\ProgramData\DEVDrives\.julia\packages\DataInterpolations\TCMJ8\src\interpolation_caches.jl:1343 [inlined]
 [15] PCHIPInterpolation(u::Vector{Float64}, t::Vector{Float64})
    @ DataInterpolations C:\ProgramData\DEVDrives\.julia\packages\DataInterpolations\TCMJ8\src\interpolation_caches.jl:1341
 [16] top-level scope
    @ REPL[14]:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions