Skip to content

Commit 40274ac

Browse files
mateuszbarantimholy
authored andcommitted
Support for Flat, Line and Throw extrapolations for monotonic interpolation (#250)
1 parent 07b386c commit 40274ac

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/monotonic/monotonic.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ end
122122
size(A::MonotonicInterpolation) = size(A.knots)
123123
axes(A::MonotonicInterpolation) = axes(A.knots)
124124

125+
itpflag(A::MonotonicInterpolation) = A.it
126+
125127
function MonotonicInterpolation(::Type{TWeights}, it::TInterpolationType, knots::TKnots, A::AbstractArray{TEl,1},
126128
m::Vector{TCoeffs}, c::Vector{TCoeffs}, d::Vector{TCoeffs}) where {TWeights, TCoeffs, TEl, TInterpolationType<:MonotonicInterpolationType, TKnots<:AbstractVector{<:Number}}
127129

test/monotonic/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ using Interpolations
3838
end
3939
end
4040
end
41+
extFlatItp = extrapolate(itp, Flat())
42+
@test extFlatItp(x[1]-1) itp(x[1])
43+
@test extFlatItp(x[end]+1) itp(x[end])
44+
extThrowItp = extrapolate(itp, Throw())
45+
@test_throws BoundsError extThrowItp(x[1]-1)
46+
@test_throws BoundsError extThrowItp(x[end]+1)
47+
extLineItp = extrapolate(itp, Line())
48+
@test extLineItp(x[1]-1) itp(x[1]) - Interpolations.gradient1(itp, x[1])
49+
@test extLineItp(x[end]+1) itp(x[end]) + Interpolations.gradient1(itp, x[end])
50+
extReflectItp = extrapolate(itp, Reflect())
51+
@test extReflectItp(x[1]-0.1) itp(x[1]+0.1)
52+
@test extReflectItp(x[end]+0.1) itp(x[end]-0.1)
53+
extPeriodicItp = extrapolate(itp, Periodic())
54+
@test extPeriodicItp(x[1]-0.1) itp(x[end]-0.1)
55+
@test extPeriodicItp(x[end]+0.1) itp(x[1]+0.1)
4156
end
4257
end
4358

0 commit comments

Comments
 (0)