Skip to content

Commit 77b39e0

Browse files
authored
Type inference in LeftIntegral/RightIntegral (#877)
* Type inference in LeftIntegral/RightIntegral * interlace diagonal in fractional derivative * test for inference only on v1.8+ * Fix test
1 parent bef98ce commit 77b39e0

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFun"
22
uuid = "28f2ccd6-bb30-5033-b560-165f7b14dc2f"
3-
version = "0.13.17"
3+
version = "0.13.18"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -22,7 +22,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2222

2323
[compat]
2424
AbstractFFTs = "1.0"
25-
ApproxFunBase = "0.8.4"
25+
ApproxFunBase = "0.8.6"
2626
ApproxFunBaseTest = "0.1"
2727
ApproxFunFourier = "0.3"
2828
ApproxFunOrthogonalPolynomials = "0.5, 0.6"

src/ApproxFun.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import ApproxFunBase: Fun, UnsetSpace, VFun, UnivariateSpace, SumSpace, Space,
2222
SpaceOperator, InterlaceOperator, cfstype, pad!,
2323
isapproxinteger, components, promotedomainspace, choosedomainspace,
2424
AbstractProductSpace, MultivariateFun, BivariateSpace,
25-
@calculus_operator, slnorm, sample, chop!, 𝒟, ∫, ⨜, ⨍
25+
@calculus_operator, slnorm, sample, chop!, 𝒟, ∫, ⨜, ⨍,
26+
InterlaceOperator_Diagonal
2627

2728
export ∫, ⨜, ⨍, 𝒟
2829

src/Extras/fractional.jl

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ function LeftIntegral(S::Jacobi,k)
2121
ConcreteLeftIntegral(S,k)
2222
else
2323
J=Jacobi(zero(S.a),S.a,domain(S))
24-
LeftIntegralWrapper(LeftIntegral(J,k)*Conversion(S,J),k)
24+
CLI = ConcreteLeftIntegral(J,k)
25+
LeftIntegralWrapper(CLI*Conversion(S,J),k,S,rangespace(CLI))
2526
end
2627
end
2728

2829
function LeftIntegral(S::Ultraspherical,k)
2930
J = Jacobi(S)
30-
LeftIntegralWrapper(LeftIntegral(J,k)*Conversion(S,J),0.5)
31+
LI = LeftIntegral(J,k)
32+
LeftIntegralWrapper(LI*Conversion(S,J),0.5,S,rangespace(LI))
3133
end
3234

33-
LeftIntegral(S::Chebyshev,k) = LeftIntegralWrapper(
34-
LeftIntegral(Ultraspherical(1//2,domain(S)),k)*Conversion(S,Ultraspherical(1//2,domain(S))),
35-
0.5)
35+
function LeftIntegral(S::Chebyshev,k)
36+
LI = LeftIntegral(Ultraspherical(1//2,domain(S)),k)
37+
LeftIntegralWrapper(
38+
LI*Conversion(S,Ultraspherical(1//2,domain(S))),
39+
0.5,S,rangespace(LI))
40+
end
3641

3742

3843
function rangespace(Q::ConcreteLeftIntegral{<:Jacobi{<:IntervalOrSegment}})
@@ -47,7 +52,8 @@ function RightIntegral(S::Jacobi,k)
4752
ConcreteRightIntegral(S,k)
4853
else
4954
J=Jacobi(S.b,zero(S.b),domain(S))
50-
RightIntegralWrapper(RightIntegral(J,k)*Conversion(S,J),k)
55+
CRI = ConcreteRightIntegral(J,k)
56+
RightIntegralWrapper(CRI*Conversion(S,J),k,S,rangespace(CRI))
5157
end
5258
end
5359

@@ -111,21 +117,22 @@ end
111117
function LeftIntegral(S::JacobiWeight{<:Chebyshev},k)
112118
# convert to Jacobi
113119
Q=LeftIntegral(JacobiWeight(S.β,S.α,Jacobi(S.space)),k)
114-
LeftIntegralWrapper(Q*Conversion(S,domainspace(Q)),k)
120+
LeftIntegralWrapper(Q*Conversion(S,domainspace(Q)),k,S,rangespace(Q))
115121
end
116122

117123
function RightIntegral(S::JacobiWeight{<:Chebyshev},k)
118124
# convert to Jacobi
119125
Q=RightIntegral(JacobiWeight(S.β,S.α,Jacobi(S.space)),k)
120-
RightIntegralWrapper(Q*Conversion(S,domainspace(Q)),k)
126+
RightIntegralWrapper(Q*Conversion(S,domainspace(Q)),k,S,rangespace(Q))
121127
end
122128

123129
for (TYP,WRAP) in ((:LeftIntegral,:LeftIntegralWrapper),
124130
(:RightIntegral,:RightIntegralWrapper))
125131

126132
@eval function $TYP(S::JacobiWeight{<:PolynomialSpace}, k)
127133
JS = JacobiWeight(S.β,S.α,Jacobi(S.space))
128-
$WRAP($TYP(JS,k)*Conversion(S,JS),k)
134+
IOP = $TYP(JS,k)
135+
$WRAP(IOP*Conversion(S,JS),k,S,rangespace(IOP))
129136
end
130137
end
131138

@@ -202,8 +209,12 @@ for (DTYP,QTYP,DWRAP,QWRAP) in ((:LeftDerivative,:LeftIntegral,:LeftDerivativeWr
202209
function $DTYP(S::Space,k::Real)
203210
i=ceil(Int,k)
204211
r=i-k
205-
$DWRAP(i<0 ? $QTYP(S,-k) : Derivative(i)*$QTYP(S,r),k)
212+
$DWRAP(i<0 ? $QTYP(S,-k) : Derivative(i)*$QTYP(S,r),k,S)
213+
end
214+
function $QTYP(S::SumSpace,k)
215+
t = map(s->$QTYP(s,k),components(S))
216+
IOP = InterlaceOperator_Diagonal(t,S)
217+
$QWRAP(IOP,k)
206218
end
207-
$QTYP(S::SumSpace,k) = $QWRAP(InterlaceOperator(Diagonal([map(s->$QTYP(s,k),S.spaces)...]),SumSpace),k)
208219
end
209220
end

test/FractionalTest.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ include(joinpath(@__DIR__, "testutils.jl"))
136136

137137
@test norm(y-exp((1+x)/2)*erfc(sqrt(1+x))) < 100eps()
138138
end
139+
140+
@testset "type inference" begin
141+
if VERSION >= v"1.8"
142+
@inferred (() -> LeftIntegral(Jacobi(-1,0)))()
143+
@inferred (() -> LeftIntegral(Legendre()))()
144+
@inferred (() -> LeftIntegral(Chebyshev()))()
145+
@inferred (() -> LeftIntegral(Ultraspherical(0.5)))()
146+
@inferred (() -> LeftIntegral(JacobiWeight(0,0,Legendre())))()
147+
@inferred (() -> LeftIntegral(JacobiWeight(-0.5,0,Chebyshev())))()
148+
@inferred (() -> RightIntegral(Jacobi(-1,0)))()
149+
@inferred (() -> RightIntegral(Legendre()))()
150+
@inferred (() -> RightIntegral(JacobiWeight(0,0,Legendre())))()
151+
@inferred (() -> RightIntegral(JacobiWeight(0,-0.5,Chebyshev())))()
152+
@inferred (() -> LeftIntegral(Legendre() JacobiWeight(0.5,0.,Ultraspherical(1)),0.5))()
153+
end
154+
end
139155
end
140156

141157
end # module

0 commit comments

Comments
 (0)