Skip to content

Commit 968475f

Browse files
authored
Aggressive constprop in Dirichlet (#141)
1 parent bd975f5 commit 968475f

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunOrthogonalPolynomials"
22
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
3-
version = "0.5.13"
3+
version = "0.5.14"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Spaces/Chebyshev/ChebyshevOperators.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@ function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},M,OT,T},
125125
end
126126
end
127127

128-
function Dirichlet(S::Chebyshev,order)
128+
@inline function _Dirichlet_Chebyshev(S, order)
129129
order == 0 && return ConcreteDirichlet(S,ArraySpace([ConstantSpace.(Point.(endpoints(domain(S))))...]),0)
130130
default_Dirichlet(S,order)
131131
end
132-
132+
@static if VERSION >= v"1.8"
133+
Base.@constprop :aggressive function Dirichlet(S::Chebyshev, order)
134+
_Dirichlet_Chebyshev(S, order)
135+
end
136+
else
137+
function Dirichlet(S::Chebyshev, order)
138+
_Dirichlet_Chebyshev(S, order)
139+
end
140+
end
133141

134142
function getindex(op::ConcreteDirichlet{<:Chebyshev},
135143
k::Integer,j::Integer)

test/ChebyshevTest.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,19 @@ using ApproxFunOrthogonalPolynomials: forwardrecurrence
304304
nmin = min(length(a), length(b))
305305
@test a[1:nmin] b[1:nmin]
306306
end
307+
308+
@testset "constant propagation in Dirichlet" begin
309+
D = if VERSION >= v"1.8"
310+
@inferred (r -> Dirichlet(r))(Chebyshev(0..1))
311+
else
312+
Dirichlet(Chebyshev(0..1))
313+
end
314+
# Dirichlet constraints don't depend on the domain
315+
D2 = Dirichlet(Chebyshev())
316+
@test Matrix(D[:, 1:4]) == Matrix(D2[:, 1:4])
317+
318+
D = @inferred (() -> Dirichlet(Chebyshev(), 2))()
319+
D2 = @inferred (() -> Dirichlet(Chebyshev(-1..1), 2))()
320+
@test Matrix(D[:, 1:4]) == Matrix(D2[:, 1:4])
321+
end
307322
end

0 commit comments

Comments
 (0)