Skip to content

Commit e409e9c

Browse files
Merge pull request #386 from SouthEndMusic/fix_extrapolation_typo
Fix integrating over interval that is fully outside data range
2 parents 1d10244 + 80403db commit e409e9c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/integrals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function integral(A::AbstractInterpolation, t1::Number, t2::Number)
2424
if t1 < first(A.t)
2525
if t2 < first(A.t)
2626
# If interval is entirely below data
27-
return _extrapolate_integral_left(A, t2) - extrapolate_integral_left(A.t1)
27+
return _extrapolate_integral_left(A, t1) - _extrapolate_integral_left(A, t2)
2828
end
2929

3030
idx1 -= 1 # Make sure lowest complete interval is included
@@ -37,7 +37,7 @@ function integral(A::AbstractInterpolation, t1::Number, t2::Number)
3737
if t2 > last(A.t)
3838
if t1 > last(A.t)
3939
# If interval is entirely above data
40-
return _extrapolate_integral_right(A, t2) - extrapolate_integral_right(A.t, t1)
40+
return _extrapolate_integral_right(A, t2) - _extrapolate_integral_right(A, t1)
4141
end
4242

4343
idx2 += 1 # Make sure highest complete interval is included

test/integral_tests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ function test_integral(method; args = [], kwargs = [], name::String)
4747
qint, err = quadgk(func, (t1 + t2) / 2, t2 + 5.0; atol = 1e-12, rtol = 1e-12)
4848
aint = integral(func, (t1 + t2) / 2, t2 + 5.0)
4949
@test isapprox(qint, aint, atol = 1e-6, rtol = 1e-8)
50+
51+
# Integrate intervals fully outside data
52+
qint, err = quadgk(func, t1 - 5.0, t1 - 2.5; atol = 1e-12, rtol = 1e-12)
53+
aint = integral(func, t1 - 5.0, t1 - 2.5)
54+
@test isapprox(qint, aint, atol = 1e-6, rtol = 1e-8)
55+
56+
qint, err = quadgk(func, t2 + 2.5, t2 + 5.0; atol = 1e-12, rtol = 1e-12)
57+
aint = integral(func, t2 + 2.5, t2 + 5.0)
58+
@test isapprox(qint, aint, atol = 1e-6, rtol = 1e-8)
5059
end
5160
func = method(args...; kwargs...)
5261
@test_throws DataInterpolations.LeftExtrapolationError integral(func, t[1] - 1.0)

test/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ end
5757
end
5858

5959
@testset "Output Type" begin
60-
# Test consistency between eltype(u) and type of the output
60+
# Test consistency between eltype(u) and type of the output
6161
u = Float32[-0.676367f0, 0.8449812f0, 1.2366607f0, -0.13347931f0, 1.9928657f0,
6262
-0.63596356f0, 0.76009744f0, -0.30632544f0, 0.34649512f0, -0.3846099f0]
6363
t = 0.1f0:0.1f0:1.0f0

0 commit comments

Comments
 (0)