JuliaMath / JuliaMath/Interpolations.jl
first/last behavior
- Dominant language
- Julia
- Stars
- 575
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
`first` and `last` do not behave as expected. It looks like what it happening is that the indexing is being done with `[1]` and `[length(etp)]`. See this example:
```julia
julia> kx = Float64[3, 5, 8, 16, 50];
julia> ky = Float64[1, 2, 1, 2, 1];
julia> etp = LinearInterpolation(kx, ky);
julia> last(etp) # should be 1.0, instead gives etp(5)
2.0
julia> first(etp) # should be 1.0 instead gives etp(1)
ERROR: BoundsError: attempt to access 5-element extrapolate(interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Linear())), Throw()) with element type Float64 at index [1]
Stacktrace:
[1] throw_boundserror(::Interpolations.Extrapolation{Float64,1,Interpolations.GriddedInterpolation{Float64,1,Float64,Gridded{Linear},Tuple{Array{Float64,1}}},Gridded{Linear},Throw{Nothing}}, ::Tuple{Int64}) at ./abstractarray.jl:484
[2] inbounds_index at /Users/tomer/.julia/packages/Interpolations/1CM1Q/src/extrapolation/extrapolation.jl:102 [inlined]
[3] inbounds_position at /Users/tomer/.julia/packages/Interpolations/1CM1Q/src/extrapolation/extrapolation.jl:93 [inlined]
[4] Extrapolation at /Users/tomer/.julia/packages/Interpolations/1CM1Q/src/extrapolation/extrapolation.jl:43 [inlined]
[5] getindex at /Users/tomer/.julia/packages/Interpolations/1CM1Q/src/Interpolations.jl:403 [inlined]
[6] first(::Interpolations.Extrapolation{Float64,1,Interpolations.GriddedInterpolation{Float64,1,Float64,Gridded{Linear},Tuple{Array{Float64,1}}},Gridded{Linear},Throw{Nothing}}) at ./abstractarray.jl:270
[7] top-level scope at none:0
```
In this one dimensional case, it should be `[first(etp.itp.knots[1])]` and `[last(etp.itp.knots[1])]`, but in general perhaps it becomes more complicated. It could also be that the underlying cause is a call to `axes` somewhere:
```julia
julia> axes(etp)
(Base.OneTo(5),)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.