Skip to content

Commit 1e7d782

Browse files
authored
Fix JacobiWeight constructor for PiecewiseSpace (#66)
* don't branch in maxspace_rule * fix sumspace hasconversion, PiecewiseSpace Fix the constructor for PiecewiseSpace. Also revert the branch removal
1 parent 5e540b0 commit 1e7d782

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

src/JacobiWeight.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ JacobiWeight(a::Number, b::Number, d::IntervalOrSegment) = JacobiWeight(a,b,Spac
3434
JacobiWeight(a::Number, b::Number, d) = JacobiWeight(a,b,Space(d))
3535
JacobiWeight(a::Number, b::Number) = JacobiWeight(a,b,Chebyshev())
3636

37-
JacobiWeight(a::Number, b::Number,s::PiecewiseSpace) = PiecewiseSpace(JacobiWeight(a,b,components(s)))
37+
JacobiWeight(a::Number, b::Number,s::PiecewiseSpace) = PiecewiseSpace(JacobiWeight.(a,b,components(s)))
3838

3939
"""
4040
WeightedJacobi(β, α, d::Domain = ChebyshevInterval())

src/JacobiWeightOperators.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,22 @@ end
245245
# MultiplicationWrapper(f,SpaceOperator(M,dsp,S))
246246
# end
247247

248+
function _maxspace_rule(A::JacobiWeight, B::JacobiWeight, f)
249+
if domainscompatible(A,B) && isapproxinteger(A.β-B.β) && isapproxinteger(A.α-B.α)
250+
ms = f(A.space,B.space)
251+
if min(A.β,B.β) == 0 && min(A.α,B.α) == 0
252+
return ms
253+
else
254+
return JacobiWeight(min(A.β,B.β),min(A.α,B.α),ms)
255+
end
256+
end
257+
NoSpace()
258+
end
259+
248260
## Conversion
249261
for (OPrule,OP) in ((:maxspace_rule,:maxspace),(:union_rule,:union))
250262
@eval begin
251-
function $OPrule(A::JacobiWeight, B::JacobiWeight)
252-
if domainscompatible(A,B) && isapproxinteger(A.β-B.β) && isapproxinteger(A.α-B.α)
253-
ms=$OP(A.space,B.space)
254-
if min(A.β,B.β) == 0 && min(A.α,B.α) == 0
255-
return ms
256-
else
257-
return JacobiWeight(min(A.β,B.β),min(A.α,B.α),ms)
258-
end
259-
end
260-
NoSpace()
261-
end
263+
$OPrule(A::JacobiWeight, B::JacobiWeight) = _maxspace_rule(A, B, $OP)
262264
$OPrule(A::JacobiWeight, B::Space{<:IntervalOrSegmentDomain}) = $OPrule(A,JacobiWeight(0,0,B))
263265
end
264266
end
@@ -274,6 +276,8 @@ for FUNC in (:hasconversion,:isconvertible)
274276
$FUNC(A,JacobiWeight(0,0,B))
275277
$FUNC(B::Space{D},A::JacobiWeight{<:Any,D}) where {D<:IntervalOrSegmentDomain} =
276278
$FUNC(JacobiWeight(0,0,B),A)
279+
$FUNC(A::SumSpace{<:Any,D},B::JacobiWeight{<:Any,D}) where {D<:IntervalOrSegmentDomain} =
280+
all(s -> $FUNC(s, B), A.spaces)
277281
end
278282
end
279283

test/runtests.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module AFSTests
33
using ApproxFunBase
44
using ApproxFunBase: HeavisideSpace, PointSpace, ArraySpace, DiracSpace, PiecewiseSegment,
55
UnionDomain, resizedata!, CachedOperator, RaggedMatrix,
6-
Block, ∞, BandedBlockBandedMatrix
6+
Block, ∞, BandedBlockBandedMatrix, NoSpace
77
using ApproxFunBaseTest: testbandedoperator, testtransforms, testfunctional,
88
testbandedblockbandedoperator
99
using ApproxFunOrthogonalPolynomials
@@ -194,11 +194,23 @@ end
194194
@test order(s) == order(us)
195195
end
196196

197+
@testset "PiecewiseSpace" begin
198+
ps = PiecewiseSpace((Chebyshev(0..1),Chebyshev(1..2)))
199+
jps = JacobiWeight(0,0,ps)
200+
@test domain(jps) == domain(ps)
201+
end
202+
197203
@testset "inference in maxspace" begin
198204
sp = JacobiWeight(half(Odd(1)), half(Odd(1)), Legendre())
199205
@test (@inferred maxspace(sp, sp)) == sp
200206

201-
@test (@inferred maxspace(sp, Legendre())) == ApproxFunBase.NoSpace()
207+
sp2 = JacobiWeight(half(Odd(1)), half(Odd(1)), Legendre(0..1))
208+
@test maxspace(sp, sp2) == NoSpace()
209+
210+
@test (@inferred maxspace(sp, Legendre())) == NoSpace()
211+
212+
sp = JacobiWeight(0.5,1,Legendre())
213+
@test (@inferred Union{typeof(sp),NoSpace} ApproxFunBase.maxspace_rule(sp, sp)) == sp
202214
end
203215
end
204216

@@ -415,6 +427,10 @@ end
415427
@test w(0.2im) 2/(sqrt(1-0.2im)*sqrt(1+im*(0.2im)))
416428
@test w(0.2) 2/(sqrt(1-0.2)*sqrt(1+im*(0.2)))
417429
end
430+
431+
@testset "hasconversion" begin
432+
@test ApproxFunBase.hasconversion(Legendre() + Legendre(), JacobiWeight(0,0,Legendre()))
433+
end
418434
end
419435

420436
@testset "WeightedJacobi" begin

0 commit comments

Comments
 (0)