Skip to content

Commit a0c2082

Browse files
committed
improve inference of Dirichlet
1 parent 0a38225 commit a0c2082

File tree

4 files changed

+35
-51
lines changed

4 files changed

+35
-51
lines changed

src/Spaces/PolynomialSpace.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
export PolynomialSpace, NormalizedPolynomialSpace
42

53
## Orthogonal polynomials

src/Spaces/Ultraspherical/ContinuousSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ end
228228
const TensorChebyshevDirichlet = TensorSpace{<:Tuple{<:ChebyshevDirichlet{1,1,<:IntervalOrSegment},
229229
<:ChebyshevDirichlet{1,1,<:IntervalOrSegment}}}
230230

231-
Dirichlet(S::TensorChebyshevDirichlet,k) = k == 0 ? ConcreteDirichlet(S,0) : tensor_Dirichlet(S,k)
231+
@inline Dirichlet(S::TensorChebyshevDirichlet,k) = k == 0 ? ConcreteDirichlet(S,0) : tensor_Dirichlet(S,k)
232232

233233
Dirichlet(d::RectDomain) =
234234
Dirichlet(ChebyshevDirichlet{1,1}(factor(d,1))*ChebyshevDirichlet{1,1}(factor(d,2)))

test/ChebyshevTest.jl

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,85 +8,72 @@ import ApproxFunOrthogonalPolynomials: forwardrecurrence
88
end
99

1010
@testset "ChebyshevInterval" begin
11-
@test Fun(x->2,10)(.1) 2
12-
@test Fun(x->2)(.1) 2
13-
@test Fun(Chebyshev,Float64[]).([0.,1.]) [0.,0.]
14-
@test Fun(Chebyshev,[])(0.) 0.
15-
@test Fun(x->4,Chebyshev(),1).coefficients == [4.0]
16-
@test Fun(x->4).coefficients == [4.0]
17-
@test Fun(4).coefficients == [4.0]
11+
@test @inferred Fun(x->2,10)(.1) 2
12+
@test @inferred Fun(x->2)(.1) 2
13+
@test @inferred Fun(Chebyshev,Float64[]).([0.,1.]) [0.,0.]
14+
@test @inferred Fun(Chebyshev,[])(0.) 0.
15+
@test @inferred Fun(x->4,Chebyshev(),1).coefficients == [4.0]
16+
@test @inferred Fun(x->4).coefficients == [4.0]
17+
@test @inferred Fun(4).coefficients == [4.0]
1818

1919

20-
@test Fun(x->4).coefficients == [4.0]
21-
@test Fun(4).coefficients == [4.0]
20+
@test @inferred Fun(x->4).coefficients == [4.0]
21+
@test @inferred Fun(4).coefficients == [4.0]
2222

23-
f = Fun(ChebyshevInterval(), [1])
23+
f = @inferred Fun(ChebyshevInterval(), [1])
2424
@test f(0.1) == 1
2525

26-
ef = Fun(exp)
27-
@test ef(0.1) exp(0.1)
26+
ef = @inferred Fun(exp)
27+
@test @inferred ef(0.1) exp(0.1)
28+
@test @inferred ef(.5) exp(.5)
2829

2930
for d in (ChebyshevInterval(),Interval(1.,2.),Segment(1.0+im,2.0+2im))
3031
testspace(Chebyshev(d))
3132
end
3233

33-
ef = Fun(exp,ChebyshevInterval())
34-
35-
@test ef == -(-ef)
36-
@test ef == (ef-1) + 1
37-
38-
ef = Fun(exp)
39-
40-
cf = Fun(cos)
41-
42-
ecf = Fun(x->cos(x).*exp(x))
43-
eocf = Fun(x->cos(x)./exp(x))
44-
45-
@test ef(.5) exp(.5)
46-
@test ecf(.123456) cos(.123456).*exp(.123456)
34+
y = @inferred Fun() + Fun(ChebyshevInterval{BigFloat}())
35+
@test y == 2Fun()
4736
end
4837

4938
@testset "Algebra" begin
50-
ef = Fun(exp,ChebyshevInterval())
51-
52-
@test ef == -(-ef)
39+
ef = @inferred Fun(exp,ChebyshevInterval())
40+
@test ef == @inferred -(-ef)
5341
@test ef == (ef-1) + 1
5442

55-
@test ef / 3 == (3 \ ef)
56-
43+
@test (@inferred ef / 3) == @inferred (3 \ ef)
5744

5845
cf = Fun(cos)
5946

60-
ecf = Fun(x->cos(x).*exp(x))
61-
eocf = Fun(x->cos(x)./exp(x))
47+
ecf = @inferred Fun(x->cos(x).*exp(x))
48+
eocf = @inferred Fun(x->cos(x)./exp(x))
6249

6350
@test ef(.5) exp(.5)
6451
@test ecf(.123456) cos(.123456).*exp(.123456)
6552

6653
r=2 .* rand(100) .- 1
6754

68-
@test maximum(abs,ef.(r)-exp.(r))<200eps()
69-
@test maximum(abs,ecf.(r).-cos.(r).*exp.(r))<200eps()
55+
@test @inferred maximum(abs,ef.(r)-exp.(r))<200eps()
56+
@test @inferred maximum(abs,ecf.(r).-cos.(r).*exp.(r))<200eps()
7057

71-
@test (cf .* ef)(0.1) ecf(0.1) cos(0.1)*exp(0.1)
72-
@test domain(cf.*ef) domain(ecf)
73-
@test domain(cf.*ef) == domain(ecf)
58+
@test (@inferred (cf .* ef)(0.1)) ecf(0.1) cos(0.1)*exp(0.1)
59+
@test (@inferred domain(cf.*ef)) domain(ecf)
60+
@test (@inferred domain(cf.*ef)) == domain(ecf)
7461

75-
@test norm((ecf-cf.*ef).coefficients)<200eps()
76-
@test maximum(abs,(eocf-cf./ef).coefficients)<1000eps()
62+
@test norm(@inferred(ecf-cf.*ef).coefficients)<200eps()
63+
@test maximum(abs,@inferred((eocf-cf./ef)).coefficients)<1000eps()
7764
@test norm(((ef/3).*(3/ef)-1).coefficients)<1000eps()
7865
end
7966

8067
@testset "Diff and cumsum" begin
8168
ef = Fun(exp)
8269
cf = Fun(cos)
83-
@test norm((ef - ef').coefficients)<10E-11
70+
@test norm(@inferred(ef - ef').coefficients)<10E-11
8471

85-
@test norm((ef - cumsum(ef)').coefficients) < 20eps()
86-
@test norm((cf - cumsum(cf)').coefficients) < 20eps()
72+
@test norm(@inferred(ef - cumsum(ef)').coefficients) < 20eps()
73+
@test norm(@inferred(cf - cumsum(cf)').coefficients) < 20eps()
8774

88-
@test sum(ef) 2.3504023872876028
89-
@test norm(ef) 1.90443178083307
75+
@test @inferred(sum(ef)) 2.3504023872876028
76+
@test @inferred(norm(ef)) 1.90443178083307
9077
end
9178

9279
@testset "other domains" begin

test/MultivariateTest.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,9 @@ end
273273
@test g(0.1,1) 0
274274
end
275275

276-
277276
@testset "Dirichlet" begin
278-
testblockbandedoperator(Dirichlet((0..1)^2))
279-
testblockbandedoperator(Dirichlet((0..1) × (0.0 .. 1)))
277+
testblockbandedoperator(@inferred Dirichlet((0..1)^2))
278+
testblockbandedoperator(@inferred Dirichlet((0..1) × (0.0 .. 1)))
280279
testraggedbelowoperator(Dirichlet(Chebyshev()^2))
281280
testraggedbelowoperator(Dirichlet(Chebyshev(0..1) * Chebyshev(0.0..1)))
282281
end

0 commit comments

Comments
 (0)