Skip to content

Commit 0c72079

Browse files
timholysglyon
authored andcommitted
Count gradient dimensions more accurately (fixes #156) (#189)
1 parent ba4b34d commit 0c72079

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/extrapolation/extrapolation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Finally, you can specify different extrapolation behavior in different direction
3030
extrapolate(itp::AbstractInterpolation{T,N,IT,GT}, ::ET) where {T,N,IT,GT,ET<:ExtrapDimSpec} =
3131
Extrapolation{T,N,typeof(itp),IT,GT,ET}(itp)
3232

33+
count_interp_dims(::Type{<:Extrapolation{T,N,ITPT}}, n) where {T,N,ITPT} = count_interp_dims(ITPT, n)
34+
3335
include("throw.jl")
3436
include("flat.jl")
3537
include("linear.jl")

src/scaling/scaling.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ end
1515
end
1616

1717
Base.parent(A::ScaledInterpolation) = A.itp
18+
count_interp_dims(::Type{<:ScaledInterpolation{T,N,ITPT}}, n) where {T,N,ITPT} = count_interp_dims(ITPT, n)
1819

1920
"""
2021
`scale(itp, xs, ys, ...)` scales an existing interpolation object to allow for indexing using other coordinate axes than unit ranges, by wrapping the interpolation object and transforming the indices from the provided axes onto unit ranges upon indexing.

test/extrapolation/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ for E in [0,Flat(),Linear(),Periodic(),Reflect()]
9191
@test (@inferred(getindex(extrapolate(interpolate([0,0],BSpline(Linear()),OnGrid()),E),[1.2, 1.8, 3.1]))) == [0,0,0]
9292
end
9393

94+
# Issue #156
95+
F = *(collect(1.:10.), collect(1:4)')
96+
itp = interpolate(F, (BSpline(Linear()), NoInterp()), OnGrid());
97+
itps = scale(itp, 1:10, 1:4)
98+
itpe = extrapolate(itps, (Linear(), Interpolations.Throw()))
99+
@test itpe[10.1, 1] 10.1
100+
@test_throws BoundsError itpe[9.9, 0]
101+
94102
end
95103

96104
include("type-stability.jl")

0 commit comments

Comments
 (0)