Skip to content

Use == for Integer in spacescompatible #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ApproxFunOrthogonalPolynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ convert_vector_or_svector(t::Tuple) = SVector(t)

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

# If any of the orders is an Integer, use == for an exact comparison, else fall back to isapprox
# We assume that Integer orders are deliberately chosen to be exact
compare_op(::Integer, args...) = ==
compare_op() = ≈
compare_op(::Any, args...) = compare_op(args...)
compare_orders(a::Number, b::Number) = compare_op(a, b)(a, b)

include("bary.jl")


Expand Down
4 changes: 2 additions & 2 deletions src/Spaces/Jacobi/Jacobi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Base.promote_rule(::Type{Jacobi{D,R1,T1}},::Type{Jacobi{D,R2,T2}}) where {D,R1,R
convert(::Type{Jacobi{D,R1,T1}},J::Jacobi{D,R2,T2}) where {D,R1,R2,T1,T2} =
Jacobi{D,R1}(T1(J.b)::T1, T1(J.a)::T1, J.domain)::Jacobi{D,R1,T1}


spacescompatible(a::Jacobi,b::Jacobi) = a.ab.a && a.bb.b && domainscompatible(a,b)
compare_orders((Aa, Ba)::NTuple{2,Number}, (Ab, Bb)::NTuple{2,Number}) = compare_orders(Aa, Ba) && compare_orders(Ab, Bb)
spacescompatible(a::Jacobi, b::Jacobi) = compare_orders((a.a, b.a), (a.b, b.b)) && domainscompatible(a,b)

isapproxinteger_addhalf(a) = !isapproxinteger(a) && isapproxinteger(a+0.5)
isapproxinteger_addhalf(::Integer) = false
Expand Down
2 changes: 1 addition & 1 deletion src/Spaces/Laguerre/Laguerre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NormalizedLaguerre{T<:Real,D<:Ray} = NormalizedPolynomialSpace{Laguerre{T,
NormalizedLaguerre(α) = NormalizedPolynomialSpace(Laguerre(α))
NormalizedLaguerre() = NormalizedLaguerre(0)

spacescompatible(A::Laguerre,B::Laguerre) = A.αB.α && B.domain == A.domain
spacescompatible(A::Laguerre,B::Laguerre) = compare_orders(A.α, B.α) && B.domain == A.domain

canonicaldomain(::Laguerre) = Ray()
domain(d::Laguerre) = d.domain
Expand Down
2 changes: 1 addition & 1 deletion src/Spaces/Ultraspherical/Ultraspherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ end


spacescompatible(a::Ultraspherical,b::Ultraspherical) =
order(a) == order(b) && domainscompatible(a,b)
compare_orders(order(a), order(b)) && domainscompatible(a,b)
hasfasttransform(::Ultraspherical) = true


Expand Down
9 changes: 9 additions & 0 deletions test/JacobiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ using Static
@test ncoefficients(g) == 1
@test coefficients(g)[1] == f(x)
end

@testset "spacescompatible" begin
x = 1.0
y = 1.0 + eps(1.0)
Jx = Jacobi(x,x)
Jy = Jacobi(y,y)
@test ApproxFunBase.spacescompatible(Jx, Jy)
@test ApproxFunBase.spacescompatible(Ultraspherical(Jx), Ultraspherical(Jy))
end
end

@testset "Conversion" begin
Expand Down