Skip to content

Commit

Permalink
conversion/maxspace/union rules for normalized spaces (#296)
Browse files Browse the repository at this point in the history
* conversion/maxspace/union rules for normalized spaces

* Bump version to v0.6.45
  • Loading branch information
jishnub authored Aug 7, 2023
1 parent 9e1b1d4 commit 5477fd0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunOrthogonalPolynomials"
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
version = "0.6.44"
version = "0.6.45"

[deps]
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
Expand Down
16 changes: 6 additions & 10 deletions src/Spaces/Jacobi/JacobiOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -511,25 +511,21 @@ end

for (OPrule,OP) in ((:conversion_rule,:conversion_type), (:maxspace_rule,:maxspace))
@eval begin
function $OPrule(A::Chebyshev,B::Jacobi)
function $OPrule(A::Chebyshev, B::Jacobi)
if isapproxminhalf(B.a) && isapproxminhalf(B.b)
# the spaces are the same
A
elseif isapproxhalfoddinteger(B.a) && isapproxhalfoddinteger(B.b)
$OP(Jacobi(A),B)
B # return the Jacobi for type-stability
else
NoSpace()
$OP(Jacobi(A),B)
end
end
function $OPrule(A::Ultraspherical,B::Jacobi)
function $OPrule(A::Ultraspherical, B::Jacobi)
m = order(A)
if isapproxminhalf(B.a - m) && isapproxminhalf(B.b - m)
# the spaces are the same
A
elseif isapproxhalfoddinteger(B.a) && isapproxhalfoddinteger(B.b)
$OP(Jacobi(A),B)
B # return the Jacobi for type-stability
else
NoSpace()
$OP(Jacobi(A), B)
end
end
end
Expand Down
27 changes: 16 additions & 11 deletions src/Spaces/PolynomialSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,6 @@ function BandedMatrix(S::SubOperator{T,ConcreteMultiplication{C,PS,T},
BandedMatrix(view(Bk2,kr2,jr2))
end




## All polynomial spaces can be converted provided domains match

isconvertible(a::PolynomialSpace, b::PolynomialSpace) = domain(a) == domain(b)
union_rule(a::PolynomialSpace{D}, b::PolynomialSpace{D}) where {D} =
conversion_type(a, b)



## General clenshaw
clenshaw(sp::PolynomialSpace,c::AbstractVector,x::AbstractArray) = clenshaw(c,x,
ClenshawPlan(promote_type(eltype(c),eltype(x)),sp,length(c),length(x)))
Expand Down Expand Up @@ -504,6 +493,16 @@ function maxspace_rule(a::NormalizedPolynomialSpace, b::PolynomialSpace)
maxspace(a.space, b)
end

function conversion_rule(a::NormalizedPolynomialSpace, b::NormalizedPolynomialSpace)
S = conversion_type(a.space, b.space)
S isa NoSpace ? S : NormalizedPolynomialSpace(S)
end

function maxspace_rule(a::NormalizedPolynomialSpace, b::NormalizedPolynomialSpace)
S = maxspace(a.space, b.space)
S isa NoSpace ? S : NormalizedPolynomialSpace(S)
end

bandwidths(C::ConcreteConversion{NormalizedPolynomialSpace{S,D,R},S}) where {S,D,R} = (0, 0)
bandwidths(C::ConcreteConversion{S,NormalizedPolynomialSpace{S,D,R}}) where {S,D,R} = (0, 0)

Expand Down Expand Up @@ -583,6 +582,12 @@ function hasconversion(A::MaybeNormalizedTensorSpace{<:P1, <:P2},
_hasconversion_tensor(factors(A), factors(B))
end

## All polynomial spaces can be converted provided domains match

isconvertible(a::MaybeNormalized, b::MaybeNormalized) = domain(a) == domain(b)
union_rule(a::MaybeNormalized{<:PolynomialSpace{D}},
b::MaybeNormalized{<:PolynomialSpace{D}}) where {D} =
conversion_type(a, b)

function Multiplication(f::Fun{<:PolynomialSpace}, sp::NormalizedPolynomialSpace)
unnorm_sp = canonicalspace(sp)
Expand Down
26 changes: 26 additions & 0 deletions test/JacobiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ include("testutils.jl")

@test (@inferred (() ->
conversion_type(NormalizedLegendre(0..1), Legendre(0..1)))()) == Legendre(0..1)

@test @inferred(conversion_type(NormalizedLegendre(), NormalizedLegendre())) ==
NormalizedLegendre()
@test @inferred(conversion_type(NormalizedLegendre(), NormalizedJacobi(1,1))) ==
NormalizedLegendre()
@test @inferred(conversion_type(NormalizedLegendre(), NormalizedUltraspherical(Legendre()))) ==
NormalizedLegendre()
@test @inferred(conversion_type(NormalizedJacobi(Ultraspherical(1)), NormalizedChebyshev())) ==
NormalizedJacobi(Chebyshev())
end

@testset "NormalizedPolynomialSpace constructor" begin
Expand Down Expand Up @@ -692,6 +701,15 @@ include("testutils.jl")
@testset "inference in maxspace/conversion_type" begin
@inferred maxspace(NormalizedLegendre(), Legendre())
@inferred (()->maxspace(NormalizedLegendre(0..1), Legendre(0..1)))()

S = @inferred(maxspace(NormalizedLegendre(), NormalizedUltraspherical(Legendre())))
@test S == NormalizedLegendre()
S = @inferred(maxspace(NormalizedLegendre(), NormalizedLegendre()))
@test S == NormalizedLegendre()
S = @inferred maxspace(NormalizedUltraspherical(1), NormalizedJacobi(Ultraspherical(2)))
@test S == NormalizedJacobi(Ultraspherical(2))
S = @inferred maxspace(NormalizedChebyshev(), NormalizedJacobi(Ultraspherical(2)))
@test S == NormalizedJacobi(Ultraspherical(2))
end
end

Expand Down Expand Up @@ -795,6 +813,14 @@ include("testutils.jl")

x = @inferred ApproxFunBase.conversion_rule(Jacobi(1,1), Jacobi(2,2))
@test x == Jacobi(1,1)

sps = (Legendre(), Jacobi(1,1), Ultraspherical(1), Chebyshev())
for S1 in sps, S1n in (S1, NormalizedPolynomialSpace(S1)),
S2 in sps, S2n in (S2, NormalizedPolynomialSpace(S2)),

f = @inferred Fun(S1n) + Fun(S2n)
@test f 2Fun()
end
end

@testset "Tensor space conversions" begin
Expand Down

2 comments on commit 5477fd0

@jishnub
Copy link
Member Author

@jishnub jishnub commented on 5477fd0 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/89196

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.45 -m "<description of version>" 5477fd017df681be9be5cf1164b578e0c40df1d8
git push origin v0.6.45

Please sign in to comment.