Skip to content

Commit

Permalink
Merge pull request #143 from marius311/MM/vecindex
Browse files Browse the repository at this point in the history
make vector indexing work with all extrapolations
  • Loading branch information
sglyon authored Apr 6, 2017
2 parents 6301e01 + ce431a1 commit 380b80c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: julia
sudo: false
julia:
- 0.4
- 0.5
- nightly
matrix:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.4
julia 0.5

WoodburyMatrices 0.1.5
Ratios
Expand Down
2 changes: 1 addition & 1 deletion src/Interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export
using Compat
using WoodburyMatrices, Ratios, AxisAlgorithms

import Base: convert, size, getindex, gradient, promote_rule, ndims, eltype
import Base: convert, size, getindex, gradient, promote_rule, ndims, eltype, checkbounds

# Julia v0.5 compatibility
if isdefined(:scaling) import Base.scaling end
Expand Down
4 changes: 3 additions & 1 deletion src/extrapolation/extrapolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ function getindex_impl{T,N,ITPT,IT,GT,ET}(etp::Type{Extrapolation{T,N,ITPT,IT,GT
end
end

@generated function getindex{T,N,ITPT,IT,GT,ET}(etp::Extrapolation{T,N,ITPT,IT,GT,ET}, xs...)
@generated function getindex{T,N,ITPT,IT,GT,ET}(etp::Extrapolation{T,N,ITPT,IT,GT,ET}, xs::Number...)
getindex_impl(etp, xs...)
end

checkbounds(::AbstractExtrapolation,I...) = nothing


function gradient!_impl{T,N,ITPT,IT,GT,ET}(g, etp::Type{Extrapolation{T,N,ITPT,IT,GT,ET}}, xs...)
coords = [Symbol("xs_", d) for d in 1:N]
Expand Down
7 changes: 7 additions & 0 deletions test/extrapolation/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ etp100g = extrapolate(interpolate(([10;20],),[100;110], Gridded(Linear())), Flat
@test @inferred(getindex(etp100g, 5)) == 100
@test @inferred(getindex(etp100g, 15)) == 105
@test @inferred(getindex(etp100g, 25)) == 110


# check all extrapolations work with vectorized indexing
for E in [0,Flat(),Linear(),Periodic(),Reflect()]
@test (@inferred(getindex(extrapolate(interpolate([0,0],BSpline(Linear()),OnGrid()),E),[1.2, 1.8, 3.1]))) == [0,0,0]
end

end

include("type-stability.jl")

0 comments on commit 380b80c

Please sign in to comment.