Skip to content

Commit 15a7f7f

Browse files
authored
Use == for Integer in spacescompatible (#218)
* Use == for Integer in Jacobi spacescompatible * consistent spacescompatible between Ultraspherical and Jacobi * compare_orders in Laguerre
1 parent fdc8fe0 commit 15a7f7f

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/ApproxFunOrthogonalPolynomials.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ convert_vector_or_svector(t::Tuple) = SVector(t)
121121

122122
const TupleOrVector{T} = Union{Tuple{T,Vararg{T}},AbstractVector{<:T}}
123123

124+
# If any of the orders is an Integer, use == for an exact comparison, else fall back to isapprox
125+
# We assume that Integer orders are deliberately chosen to be exact
126+
compare_op(::Integer, args...) = ==
127+
compare_op() =
128+
compare_op(::Any, args...) = compare_op(args...)
129+
compare_orders(a::Number, b::Number) = compare_op(a, b)(a, b)
130+
124131
include("bary.jl")
125132

126133

src/Spaces/Jacobi/Jacobi.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Base.promote_rule(::Type{Jacobi{D,R1,T1}},::Type{Jacobi{D,R2,T2}}) where {D,R1,R
4141
convert(::Type{Jacobi{D,R1,T1}},J::Jacobi{D,R2,T2}) where {D,R1,R2,T1,T2} =
4242
Jacobi{D,R1}(T1(J.b)::T1, T1(J.a)::T1, J.domain)::Jacobi{D,R1,T1}
4343

44-
45-
spacescompatible(a::Jacobi,b::Jacobi) = a.a b.a && a.b b.b && domainscompatible(a,b)
44+
compare_orders((Aa, Ba)::NTuple{2,Number}, (Ab, Bb)::NTuple{2,Number}) = compare_orders(Aa, Ba) && compare_orders(Ab, Bb)
45+
spacescompatible(a::Jacobi, b::Jacobi) = compare_orders((a.a, b.a), (a.b, b.b)) && domainscompatible(a,b)
4646

4747
isapproxinteger_addhalf(a) = !isapproxinteger(a) && isapproxinteger(a+0.5)
4848
isapproxinteger_addhalf(::Integer) = false

src/Spaces/Laguerre/Laguerre.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const NormalizedLaguerre{T<:Real,D<:Ray} = NormalizedPolynomialSpace{Laguerre{T,
3535
NormalizedLaguerre(α) = NormalizedPolynomialSpace(Laguerre(α))
3636
NormalizedLaguerre() = NormalizedLaguerre(0)
3737

38-
spacescompatible(A::Laguerre,B::Laguerre) = A.α B.α && B.domain == A.domain
38+
spacescompatible(A::Laguerre,B::Laguerre) = compare_orders(A.α, B.α) && B.domain == A.domain
3939

4040
canonicaldomain(::Laguerre) = Ray()
4141
domain(d::Laguerre) = d.domain

src/Spaces/Ultraspherical/Ultraspherical.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ end
128128

129129

130130
spacescompatible(a::Ultraspherical,b::Ultraspherical) =
131-
order(a) == order(b) && domainscompatible(a,b)
131+
compare_orders(order(a), order(b)) && domainscompatible(a,b)
132132
hasfasttransform(::Ultraspherical) = true
133133

134134

test/JacobiTest.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ using Static
4242
@test ncoefficients(g) == 1
4343
@test coefficients(g)[1] == f(x)
4444
end
45+
46+
@testset "spacescompatible" begin
47+
x = 1.0
48+
y = 1.0 + eps(1.0)
49+
Jx = Jacobi(x,x)
50+
Jy = Jacobi(y,y)
51+
@test ApproxFunBase.spacescompatible(Jx, Jy)
52+
@test ApproxFunBase.spacescompatible(Ultraspherical(Jx), Ultraspherical(Jy))
53+
end
4554
end
4655

4756
@testset "Conversion" begin

0 commit comments

Comments
 (0)