Skip to content

Commit ee3cdbc

Browse files
committed
make vector indexing work with all extrapolations
1 parent 11e6c72 commit ee3cdbc

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Interpolations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export
3737
using Compat
3838
using WoodburyMatrices, Ratios, AxisAlgorithms
3939

40-
import Base: convert, size, getindex, gradient, promote_rule, ndims, eltype
40+
import Base: convert, size, getindex, gradient, promote_rule, ndims, eltype, checkbounds
4141

4242
# Julia v0.5 compatibility
4343
if isdefined(:scaling) import Base.scaling end

src/extrapolation/extrapolation.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ function getindex_impl{T,N,ITPT,IT,GT,ET}(etp::Type{Extrapolation{T,N,ITPT,IT,GT
5454
end
5555
end
5656

57-
@generated function getindex{T,N,ITPT,IT,GT,ET}(etp::Extrapolation{T,N,ITPT,IT,GT,ET}, xs...)
57+
@generated function getindex{T,N,ITPT,IT,GT,ET}(etp::Extrapolation{T,N,ITPT,IT,GT,ET}, xs::Number...)
5858
getindex_impl(etp, xs...)
5959
end
6060

61+
checkbounds(::AbstractExtrapolation,I...) = nothing
62+
6163

6264
function gradient!_impl{T,N,ITPT,IT,GT,ET}(g, etp::Type{Extrapolation{T,N,ITPT,IT,GT,ET}}, xs...)
6365
coords = [Symbol("xs_", d) for d in 1:N]

test/extrapolation/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ etp100g = extrapolate(interpolate(([10;20],),[100;110], Gridded(Linear())), Flat
7979
@test @inferred(getindex(etp100g, 5)) == 100
8080
@test @inferred(getindex(etp100g, 15)) == 105
8181
@test @inferred(getindex(etp100g, 25)) == 110
82+
83+
84+
# check all extrapolations work with vectorized indexing
85+
for E in [0,Flat(),Linear(),Periodic(),Reflect()]
86+
@test (@inferred extrapolate(interpolate([0,0],BSpline(Linear()),OnGrid()),E)[[3]]) == [0]
87+
end
88+
8289
end
8390

8491
include("type-stability.jl")

0 commit comments

Comments
 (0)