Skip to content

Commit 4939ca2

Browse files
authored
Don't hardcode zero in LeftIntegral (#860)
* don't hardcode zero in LeftIntegral * Verbose testsets
1 parent 953ab10 commit 4939ca2

File tree

7 files changed

+111
-98
lines changed

7 files changed

+111
-98
lines changed

src/Extras/fractional.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function LeftIntegral(S::Jacobi,k)
2020
if S.b==0
2121
ConcreteLeftIntegral(S,k)
2222
else
23-
J=Jacobi(0.,S.a,domain(S))
23+
J=Jacobi(zero(S.a),S.a,domain(S))
2424
LeftIntegralWrapper(LeftIntegral(J,k)*Conversion(S,J),k)
2525
end
2626
end

test/ExtrasTest.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ using LinearAlgebra
77
using SpecialFunctions
88
using Test
99

10-
@testset "Extras" begin
10+
include(joinpath(@__DIR__, "testutils.jl"))
11+
12+
@verbose @testset "Extras" begin
1113
@testset "Dual numbers" begin
1214
@test dual(1.5,1) Segment(dual(1.0,1),dual(2.0))
1315

test/FractionalTest.jl

Lines changed: 89 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ using Test
55
using LinearAlgebra
66
using SpecialFunctions
77
using ApproxFunBaseTest: testfunctional, testbandedoperator
8+
include(joinpath(@__DIR__, "testutils.jl"))
89

9-
@testset "Fractional" begin
10+
@verbose @testset "Fractional" begin
1011
@testset "Jupyter example" begin
1112
S = Legendre() JacobiWeight(0.5,0.,Ultraspherical(1))
1213
@time= LeftIntegral(S,0.5)
@@ -25,122 +26,116 @@ using ApproxFunBaseTest: testfunctional, testbandedoperator
2526

2627
## Avazzadev et al
2728

28-
# Example 1
29-
30-
x=Fun(0..1)
31-
Q=gamma(0.5)*LeftIntegral(0.5)
32-
@time f=(2/105*sqrt(x)*(105-56x^2+48x^3))
33-
u=Q\f
34-
@test norm(u-(x^3-x^2+1))<100eps()
35-
36-
37-
# Example 2
38-
39-
x=Fun(0..1)
40-
Q=gamma(0.5)*LeftIntegral(0.5)
41-
u=Q\(exp(x)-1)
42-
@time @test norm(u-exp(x)*erf(sqrt(x))/sqrt(π)) < 100eps() # 5.0036177384681187e-14
43-
44-
45-
# Example 3
46-
x=Fun(0..1)
47-
Q=gamma(1/5)*LeftIntegral(1/5)
48-
u=Q\(x+1)
49-
@test norm(u-(1+1.25x)*sin(0.8π)/*x^(1/5))) < 10eps()
50-
51-
# Example 4
52-
x=Fun(0..1)
53-
Q=gamma(1-1/3)*LeftIntegral(1-1/3)
54-
u=Q\x^(7/6)
55-
@test norm(u-7*gamma(1/6)/(18*sqrt(π)*gamma(2/3))*sqrt(x)) < 100eps()
56-
57-
58-
# Example 5
59-
60-
d=Interval(0,1)
61-
x=Fun(d)
62-
f=x+4/3*x^(3/2)
63-
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
64-
Q=gamma(.5)*LeftIntegral(S,.5)
65-
66-
67-
@time @test sum(f/sqrt(1-x)) last(Q*f)
68-
69-
L=I+Q
70-
@test last(L.ops[2]*f) last(Q*f)
71-
@test last(L*f) last(f)+last(Q*f)
72-
73-
@time u=L\f
74-
@test norm(u-x) < 10eps()
75-
76-
77-
# Example 6
29+
@testset "Example 1" begin
30+
x=Fun(0..1)
31+
Q=gamma(0.5)*LeftIntegral(0.5)
32+
@time f=(2/105*sqrt(x)*(105-56x^2+48x^3))
33+
u=Q\f
34+
@test norm(u-(x^3-x^2+1))<100eps()
35+
end
7836

79-
d=Interval(0,1)
80-
x=Fun(d)
81-
@time f=x^2+16/15*x^(5/2)
82-
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
83-
Q=gamma(.5)*LeftIntegral(S,.5)
84-
L=I+Q
85-
@time u=L\f
86-
@test norm(u-x^2) < 10eps()
8737

88-
# Example 7
38+
@testset "Example 2" begin
39+
x=Fun(0..1)
40+
Q=gamma(0.5)*LeftIntegral(0.5)
41+
u=Q\(exp(x)-1)
42+
@time @test norm(u-exp(x)*erf(sqrt(x))/sqrt(π)) < 100eps() # 5.0036177384681187e-14
43+
end
8944

90-
d=Interval(0.,1.)
91-
x=Fun(d)
92-
f=2sqrt(x)
93-
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
94-
Q=gamma(.5)*LeftIntegral(S,.5)
95-
@time L=I+Q
96-
u=L\f
9745

98-
@time @test norm(1-exp*x)*erfc(sqrt*x))-u) < 100eps()
46+
@testset "Example 3" begin
47+
x=Fun(0..1)
48+
Q=gamma(1/5)*LeftIntegral(1/5)
49+
u=Q\(x+1)
50+
@test norm(u-(1+1.25x)*sin(0.8π)/*x^(1/5))) < 10eps()
51+
end
9952

53+
@testset "Example 4" begin
54+
x=Fun(0..1)
55+
Q=gamma(1-1/3)*LeftIntegral(1-1/3)
56+
u=Q\x^(7/6)
57+
@test norm(u-7*gamma(1/6)/(18*sqrt(π)*gamma(2/3))*sqrt(x)) < 100eps()
58+
end
10059

101-
# Example 8
60+
@testset "Example 5" begin
61+
d=Interval(0,1)
62+
x=Fun(d)
63+
f=x+4/3*x^(3/2)
64+
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
65+
Q=gamma(.5)*LeftIntegral(S,.5)
66+
@time @test sum(f/sqrt(1-x)) last(Q*f)
10267

103-
d=Interval(0.,1.)
104-
x=Fun(d)
105-
@time f=1/(x+1)+2*Fun(x->asinh(sqrt(x))/sqrt(1+x),JacobiWeight(.5,0.,d))
106-
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
107-
Q=gamma(.5)*LeftIntegral(S,.5)
108-
L=I+Q
109-
u=L\f
110-
@test norm((u-1/(x+1)).coefficients) < 1000eps() # 1.2011889731154679e-14
68+
L=I+Q
69+
@test last(L.ops[2]*f) last(Q*f)
70+
@test last(L*f) last(f)+last(Q*f)
11171

72+
@time u=L\f
73+
@test norm(u-x) < 10eps()
74+
end
11275

76+
@testset "Example 6" begin
77+
d=Interval(0,1)
78+
x=Fun(d)
79+
@time f=x^2+16/15*x^(5/2)
80+
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
81+
Q=gamma(.5)*LeftIntegral(S,.5)
82+
L=I+Q
83+
@time u=L\f
84+
@test norm(u-x^2) < 10eps()
85+
end
11386

87+
@testset "Example 7" begin
88+
d=Interval(0.,1.)
89+
x=Fun(d)
90+
f=2sqrt(x)
91+
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
92+
Q=gamma(.5)*LeftIntegral(S,.5)
93+
@time L=I+Q
94+
u=L\f
11495

115-
## Test for bug
96+
@time @test norm(1-exp*x)*erfc(sqrt*x))-u) < 100eps()
97+
end
11698

117-
QL = LeftIntegral(0.5) : Legendre() JacobiWeight(0.5,0.,Ultraspherical(1))
118-
QU = LeftIntegral(0.5) : JacobiWeight(0.5,0.,Ultraspherical(1)) Legendre()
11999

100+
@testset "Example 8" begin
101+
d=Interval(0.,1.)
102+
x=Fun(d)
103+
@time f=1/(x+1)+2*Fun(x->asinh(sqrt(x))/sqrt(1+x),JacobiWeight(.5,0.,d))
104+
S=Legendre(d)JacobiWeight(.5,0.,Jacobi(.5,.5,d))
105+
Q=gamma(.5)*LeftIntegral(S,.5)
106+
L=I+Q
107+
u=L\f
108+
@test norm((u-1/(x+1)).coefficients) < 1000eps() # 1.2011889731154679e-14
109+
end
120110

121-
λ=0.25
122-
@time L=*I QU; QL λ*I]
123-
@test L[2,5] 0.
124111

125112

113+
@testset "Test for bug" begin
114+
QL = LeftIntegral(0.5) : Legendre() JacobiWeight(0.5,0.,Ultraspherical(1))
115+
QU = LeftIntegral(0.5) : JacobiWeight(0.5,0.,Ultraspherical(1)) Legendre()
126116

127-
## Paper examples
117+
λ=0.25
118+
@time L=*I QU; QL λ*I]
119+
@test L[2,5] 0.
120+
end
128121

129-
S=Legendre()JacobiWeight(0.5,0.,Ultraspherical(1))
130-
=LeftIntegral(S,0.5)
122+
@testset "paper examples" begin
123+
S=Legendre()JacobiWeight(0.5,0.,Ultraspherical(1))
124+
=LeftIntegral(S,0.5)
131125

132-
y=(I+Q½)\1
126+
y=(I+Q½)\1
133127

134-
x=Fun()
135-
@time @test norm(exp(1+x)*erfc(sqrt(1+x))-y) < 100eps()
128+
x=Fun()
129+
@time @test norm(exp(1+x)*erfc(sqrt(1+x))-y) < 100eps()
136130

137-
S=Legendre()JacobiWeight(0.5,0.,Ultraspherical(1))
138-
x=Fun()
139-
=LeftIntegral(S,0.5)
131+
S=Legendre()JacobiWeight(0.5,0.,Ultraspherical(1))
132+
x=Fun()
133+
=LeftIntegral(S,0.5)
140134

141-
@time y=(I+exp(-(1+x)/2)*Q½[exp((1+x)/2)])\exp(-(1+x)/2)
135+
@time y=(I+exp(-(1+x)/2)*Q½[exp((1+x)/2)])\exp(-(1+x)/2)
142136

143-
@test norm(y-exp((1+x)/2)*erfc(sqrt(1+x))) < 100eps()
137+
@test norm(y-exp((1+x)/2)*erfc(sqrt(1+x))) < 100eps()
138+
end
144139
end
145140

146141
end # module

test/NumberTypeTest.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ using Test
66
using FFTW
77
using LinearAlgebra
88

9-
@testset "BigFloat" begin
9+
include(joinpath(@__DIR__, "testutils.jl"))
10+
11+
@verbose @testset "BigFloat" begin
1012
@testset "BigFloat constructor" begin
1113
single_sin = Fun(sin,Interval(0.f0,1.f0))
1214
double_sin = Fun(sin,Interval(0.,1.))

test/ReadmeTest.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ using Test
77

88
const EXAMPLES_DIR = joinpath(dirname(dirname(pathof(ApproxFun))), "examples")
99

10-
@testset "Readme" begin
10+
include(joinpath(@__DIR__, "testutils.jl"))
11+
12+
@verbose @testset "Readme" begin
1113
@testset "Calculus and algebra" begin
1214
x = Fun(identity,0..10)
1315
f = sin(x^2)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ DocMeta.setdocmeta!(ApproxFun, :DocTestSetup, :(using ApproxFun); recursive=true
2424
doctest(ApproxFunBase, manual=false)
2525
end
2626

27+
include(joinpath(@__DIR__, "testutils.jl"))
28+
2729
include("ReadmeTest.jl")
2830
include("ExtrasTest.jl")
2931
include("NumberTypeTest.jl")

test/testutils.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro verbose(ex)
2+
head = ex.head
3+
args = ex.args
4+
@assert args[1] == Symbol("@testset")
5+
name = args[3] isa String ? args[3] : nothing
6+
if VERSION >= v"1.8"
7+
insert!(args, 3, Expr(:(=), :verbose, true))
8+
end
9+
Expr(head, args...)
10+
end

0 commit comments

Comments
 (0)