Skip to content

Commit 1f54fce

Browse files
authored
Improve type inference in JacobiWeight derivative (#84)
* Improve type inference in JacobiWeight derivative * Add test * test for inference on recent versions * Pass domainspace in Derivative for k>1 * integer exponents in Jacobi-space Multiplication
1 parent f581987 commit 1f54fce

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunSingularities"
22
uuid = "f8fcb915-6b99-5be2-b79a-d6dbef8e6e7e"
3-
version = "0.3.15"
3+
version = "0.3.16"
44

55
[deps]
66
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"

src/JacobiWeight.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@ function Multiplication(f::Fun{<:JacobiWeight{<:ConstantSpace,<:IntervalOrSegmen
421421
ConcreteMultiplication(f,S)
422422
elseif isapproxinteger(Sf.β) && Sf.β 1 && S.b >0
423423
# decrement β and multiply again
424-
M1 = ConcreteMultiplication(f.coefficients[1]*jacobiweight(1.,0.,d),S)
424+
M1 = ConcreteMultiplication(f.coefficients[1]*jacobiweight(1,0,d),S)
425425
M1_out = Multiplication(jacobiweight(Sf.β-1,Sf.α,d), rangespace(M1)) * M1
426426
MultiplicationWrapper(f, M1_out)
427427
elseif isapproxinteger(Sf.α) && Sf.α 1 && S.a >0
428428
# decrement α and multiply again
429-
M2 = ConcreteMultiplication(f.coefficients[1]*jacobiweight(0.,1.,d),S)
429+
M2 = ConcreteMultiplication(f.coefficients[1]*jacobiweight(0,1,d),S)
430430
M2_out = Multiplication(jacobiweight(Sf.β,Sf.α-1,d), rangespace(M2)) * M2
431431
MultiplicationWrapper(f, M2_out)
432432
else

src/JacobiWeightOperators.jl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,22 @@ function differentiate(f::Fun{<:JacobiWeight{<:Any,<:IntervalOrSegment}})
4949
S=f.space
5050
d=domain(f)
5151
ff=Fun(S.space,f.coefficients)
52+
zeroT = zero(S.α-1)
5253
if S.β==S.α==0
5354
u=differentiate(ff)
54-
Fun(JacobiWeight(0,0,space(u)),u.coefficients)
55+
Fun(JacobiWeight(zeroT,zeroT,space(u)),u.coefficients)
5556
elseif S.β==0
5657
x=Fun(identity,d)
5758
M=tocanonical(d,x)
5859
Mp=tocanonicalD(d,leftendpoint(d))
5960
u=-Mp*S.α*ff +(1-M).*differentiate(ff)
60-
Fun(JacobiWeight(0,S.α-1,space(u)),u.coefficients)
61+
Fun(JacobiWeight(zeroT,S.α-1,space(u)),u.coefficients)
6162
elseif S.α==0
6263
x=Fun(identity,d)
6364
M=tocanonical(d,x)
6465
Mp=tocanonicalD(d,leftendpoint(d))
6566
u=Mp*S.β*ff +(1+M).*differentiate(ff)
66-
Fun(JacobiWeight(S.β-1,0,space(u)),u.coefficients)
67+
Fun(JacobiWeight(S.β-1,zeroT,space(u)),u.coefficients)
6768
else
6869
x=Fun(identity,d)
6970
M=tocanonical(d,x)
@@ -158,27 +159,31 @@ end
158159
function jacobiweightDerivative(S::JacobiWeight{<:Any,<:ChebyshevInterval})
159160
d=domain(S)
160161

161-
if S.β==S.α==0
162-
DerivativeWrapper(SpaceOperator(Derivative(S.space),S,
163-
JacobiWeight(0,0,rangespace(Derivative(S.space)))),1)
164-
elseif S.β==0
165-
w=Fun(JacobiWeight(0,1,ConstantSpace(d)),[1.])
162+
zeroT = zero(S.α-1)
163+
oneT = oneunit(zeroT)
164+
DSsp = Derivative(S.space)
166165

167-
DDβ0=-S.α + w*Derivative(S.space)
168-
rsβ0=S.α==1 ? rangespace(DDβ0) : JacobiWeight(0.,S.α-1,rangespace(DDβ0))
166+
if S.β == S.α == 0
167+
DerivativeWrapper(SpaceOperator(DSsp,S,
168+
JacobiWeight(zeroT,zeroT,rangespace(DSsp))),1)
169+
elseif S.β == 0
170+
w = Fun(JacobiWeight(zeroT,oneT,ConstantSpace(d)),[1.0])
171+
172+
DDβ0 = -S.α + w*DSsp
173+
rsβ0 = JacobiWeight(zeroT,S.α-1,rangespace(DDβ0))
169174
DerivativeWrapper(SpaceOperator(DDβ0,S,rsβ0),1)
170-
elseif S.α==0
171-
w=Fun(JacobiWeight(1,0,ConstantSpace(d)),[1.])
175+
elseif S.α == 0
176+
w = Fun(JacobiWeight(oneT,zeroT,ConstantSpace(d)),[1.0])
172177

173-
DDα0=S.β + w*Derivative(S.space)
174-
rsα0=S.β==1 ? rangespace(DDα0) : JacobiWeight(S.β-1,0.,rangespace(DDα0))
178+
DDα0 = S.β + w*DSsp
179+
rsα0 = JacobiWeight(S.β-1,zeroT,rangespace(DDα0))
175180
DerivativeWrapper(SpaceOperator(DDα0,S,rsα0),1)
176181
else
177-
w=Fun(JacobiWeight(1,1,ConstantSpace(d)),[1.])
182+
w = Fun(JacobiWeight(oneT,oneT,ConstantSpace(d)),[1.0])
178183
x=Fun()
179184

180-
DD=S.β*(1-x) - S.α*(1+x) + w*Derivative(S.space)
181-
rs=S.β==1 && S.α==1 ? rangespace(DD) : JacobiWeight(S.β-1,S.α-1,rangespace(DD))
185+
DD = S.β*(1-x) - S.α*(1+x) + w*DSsp
186+
rs = JacobiWeight(S.β-1,S.α-1,rangespace(DD))
182187
DerivativeWrapper(SpaceOperator(DD,S,rs),1)
183188
end
184189
end
@@ -192,7 +197,7 @@ function Derivative(S::JacobiWeight{<:Any,<:IntervalOrSegment}, k::Number)
192197
else
193198
D=Derivative(S)
194199
Dk = TimesOperator(Derivative(rangespace(D),k-1), D)
195-
DerivativeWrapper(Dk, k)
200+
DerivativeWrapper(Dk, k, S)
196201
end
197202
end
198203

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ end
132132
@test (D*f)(x) exp(x)*(x-1)/(2x^2)
133133
end
134134

135+
@testset "differentiate" begin
136+
f = Fun(x -> (1-x^2) * x^2, JacobiWeight(0.5, 0.5, Chebyshev()))
137+
df(f) =
138+
ApproxFunSingularities.differentiate(f)
139+
g = if VERSION >= v"1.9"
140+
@inferred df(f)
141+
else
142+
df(f)
143+
end
144+
145+
@test g Fun(x -> -x^3/√(1-x^2) + (1-x^2) * 2x, JacobiWeight(-0.5, -0.5, Chebyshev()))
146+
end
147+
135148
@testset "Jacobi singularity" begin
136149
x = Fun(identity)
137150
f = exp(x)/(1-x.^2)

0 commit comments

Comments
 (0)