Skip to content

Commit 5477fd0

Browse files
authored
conversion/maxspace/union rules for normalized spaces (#296)
* conversion/maxspace/union rules for normalized spaces * Bump version to v0.6.45
1 parent 9e1b1d4 commit 5477fd0

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunOrthogonalPolynomials"
22
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
3-
version = "0.6.44"
3+
version = "0.6.45"
44

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

src/Spaces/Jacobi/JacobiOperators.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,25 +511,21 @@ end
511511

512512
for (OPrule,OP) in ((:conversion_rule,:conversion_type), (:maxspace_rule,:maxspace))
513513
@eval begin
514-
function $OPrule(A::Chebyshev,B::Jacobi)
514+
function $OPrule(A::Chebyshev, B::Jacobi)
515515
if isapproxminhalf(B.a) && isapproxminhalf(B.b)
516516
# the spaces are the same
517-
A
518-
elseif isapproxhalfoddinteger(B.a) && isapproxhalfoddinteger(B.b)
519-
$OP(Jacobi(A),B)
517+
B # return the Jacobi for type-stability
520518
else
521-
NoSpace()
519+
$OP(Jacobi(A),B)
522520
end
523521
end
524-
function $OPrule(A::Ultraspherical,B::Jacobi)
522+
function $OPrule(A::Ultraspherical, B::Jacobi)
525523
m = order(A)
526524
if isapproxminhalf(B.a - m) && isapproxminhalf(B.b - m)
527525
# the spaces are the same
528-
A
529-
elseif isapproxhalfoddinteger(B.a) && isapproxhalfoddinteger(B.b)
530-
$OP(Jacobi(A),B)
526+
B # return the Jacobi for type-stability
531527
else
532-
NoSpace()
528+
$OP(Jacobi(A), B)
533529
end
534530
end
535531
end

src/Spaces/PolynomialSpace.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,6 @@ function BandedMatrix(S::SubOperator{T,ConcreteMultiplication{C,PS,T},
319319
BandedMatrix(view(Bk2,kr2,jr2))
320320
end
321321

322-
323-
324-
325-
## All polynomial spaces can be converted provided domains match
326-
327-
isconvertible(a::PolynomialSpace, b::PolynomialSpace) = domain(a) == domain(b)
328-
union_rule(a::PolynomialSpace{D}, b::PolynomialSpace{D}) where {D} =
329-
conversion_type(a, b)
330-
331-
332-
333322
## General clenshaw
334323
clenshaw(sp::PolynomialSpace,c::AbstractVector,x::AbstractArray) = clenshaw(c,x,
335324
ClenshawPlan(promote_type(eltype(c),eltype(x)),sp,length(c),length(x)))
@@ -504,6 +493,16 @@ function maxspace_rule(a::NormalizedPolynomialSpace, b::PolynomialSpace)
504493
maxspace(a.space, b)
505494
end
506495

496+
function conversion_rule(a::NormalizedPolynomialSpace, b::NormalizedPolynomialSpace)
497+
S = conversion_type(a.space, b.space)
498+
S isa NoSpace ? S : NormalizedPolynomialSpace(S)
499+
end
500+
501+
function maxspace_rule(a::NormalizedPolynomialSpace, b::NormalizedPolynomialSpace)
502+
S = maxspace(a.space, b.space)
503+
S isa NoSpace ? S : NormalizedPolynomialSpace(S)
504+
end
505+
507506
bandwidths(C::ConcreteConversion{NormalizedPolynomialSpace{S,D,R},S}) where {S,D,R} = (0, 0)
508507
bandwidths(C::ConcreteConversion{S,NormalizedPolynomialSpace{S,D,R}}) where {S,D,R} = (0, 0)
509508

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

585+
## All polynomial spaces can be converted provided domains match
586+
587+
isconvertible(a::MaybeNormalized, b::MaybeNormalized) = domain(a) == domain(b)
588+
union_rule(a::MaybeNormalized{<:PolynomialSpace{D}},
589+
b::MaybeNormalized{<:PolynomialSpace{D}}) where {D} =
590+
conversion_type(a, b)
586591

587592
function Multiplication(f::Fun{<:PolynomialSpace}, sp::NormalizedPolynomialSpace)
588593
unnorm_sp = canonicalspace(sp)

test/JacobiTest.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ include("testutils.jl")
221221

222222
@test (@inferred (() ->
223223
conversion_type(NormalizedLegendre(0..1), Legendre(0..1)))()) == Legendre(0..1)
224+
225+
@test @inferred(conversion_type(NormalizedLegendre(), NormalizedLegendre())) ==
226+
NormalizedLegendre()
227+
@test @inferred(conversion_type(NormalizedLegendre(), NormalizedJacobi(1,1))) ==
228+
NormalizedLegendre()
229+
@test @inferred(conversion_type(NormalizedLegendre(), NormalizedUltraspherical(Legendre()))) ==
230+
NormalizedLegendre()
231+
@test @inferred(conversion_type(NormalizedJacobi(Ultraspherical(1)), NormalizedChebyshev())) ==
232+
NormalizedJacobi(Chebyshev())
224233
end
225234

226235
@testset "NormalizedPolynomialSpace constructor" begin
@@ -692,6 +701,15 @@ include("testutils.jl")
692701
@testset "inference in maxspace/conversion_type" begin
693702
@inferred maxspace(NormalizedLegendre(), Legendre())
694703
@inferred (()->maxspace(NormalizedLegendre(0..1), Legendre(0..1)))()
704+
705+
S = @inferred(maxspace(NormalizedLegendre(), NormalizedUltraspherical(Legendre())))
706+
@test S == NormalizedLegendre()
707+
S = @inferred(maxspace(NormalizedLegendre(), NormalizedLegendre()))
708+
@test S == NormalizedLegendre()
709+
S = @inferred maxspace(NormalizedUltraspherical(1), NormalizedJacobi(Ultraspherical(2)))
710+
@test S == NormalizedJacobi(Ultraspherical(2))
711+
S = @inferred maxspace(NormalizedChebyshev(), NormalizedJacobi(Ultraspherical(2)))
712+
@test S == NormalizedJacobi(Ultraspherical(2))
695713
end
696714
end
697715

@@ -795,6 +813,14 @@ include("testutils.jl")
795813

796814
x = @inferred ApproxFunBase.conversion_rule(Jacobi(1,1), Jacobi(2,2))
797815
@test x == Jacobi(1,1)
816+
817+
sps = (Legendre(), Jacobi(1,1), Ultraspherical(1), Chebyshev())
818+
for S1 in sps, S1n in (S1, NormalizedPolynomialSpace(S1)),
819+
S2 in sps, S2n in (S2, NormalizedPolynomialSpace(S2)),
820+
821+
f = @inferred Fun(S1n) + Fun(S2n)
822+
@test f 2Fun()
823+
end
798824
end
799825

800826
@testset "Tensor space conversions" begin

0 commit comments

Comments
 (0)