Skip to content

Improve type-inference in normalized space conversion #295

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 4 commits into from
Aug 6, 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
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.43"
version = "0.6.44"

[deps]
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
Expand Down
2 changes: 1 addition & 1 deletion src/Spaces/Jacobi/JacobiOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function _conversion_shiftordersbyone(L::Jacobi, M::Jacobi)
CLJ = [ConcreteConversion(Jacobi(b-1,L.a,dm), Jacobi(b, L.a, dm)) for b in M.b:-1:L.b+1]
CJM = [ConcreteConversion(Jacobi(M.b,a-1,dm), Jacobi(M.b, a, dm)) for a in M.a:-1:L.a+1]
C = [CJM; CLJ]
return ConversionWrapper(TimesOperator(C))
return ConversionWrapper(TimesOperator(C), L, M)
end

## Conversion
Expand Down
18 changes: 12 additions & 6 deletions src/Spaces/PolynomialSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,27 @@ normalizedspace(S::NormalizedPolynomialSpace) = S

supportsinplacetransform(N::NormalizedPolynomialSpace) = supportsinplacetransform(N.space)

function Conversion(L::NormalizedPolynomialSpace{S}, M::S) where S<:PolynomialSpace
function Conversion(L::NormalizedPolynomialSpace, M::PolynomialSpace)
if L.space == M
ConcreteConversion(L, M)
else
sp = L.space
ConversionWrapper(TimesOperator(Conversion(sp, M), ConcreteConversion(L, sp)))
ConversionWrapper(
TimesOperator(Conversion(sp, M), ConcreteConversion(L, sp)),
L, M,
)
end
end

function Conversion(L::S, M::NormalizedPolynomialSpace{S}) where S<:PolynomialSpace
function Conversion(L::PolynomialSpace, M::NormalizedPolynomialSpace)
if M.space == L
ConcreteConversion(L, M)
else
sp = M.space
ConversionWrapper(TimesOperator(ConcreteConversion(sp, M), Conversion(L, sp)))
ConversionWrapper(
TimesOperator(ConcreteConversion(sp, M), Conversion(L, sp)),
L, M,
)
end
end

Expand All @@ -490,11 +496,11 @@ function Fun(::typeof(identity), S::NormalizedPolynomialSpace)
Fun(S, coeffs)
end

function conversion_rule(a::NormalizedPolynomialSpace{S}, b::S) where S<:PolynomialSpace
function conversion_rule(a::NormalizedPolynomialSpace, b::PolynomialSpace)
conversion_type(a.space, b)
end

function maxspace_rule(a::NormalizedPolynomialSpace{S}, b::S) where S<:PolynomialSpace
function maxspace_rule(a::NormalizedPolynomialSpace, b::PolynomialSpace)
maxspace(a.space, b)
end

Expand Down
11 changes: 10 additions & 1 deletion test/JacobiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,16 @@ include("testutils.jl")
end
@testset "Normalized and Unnormalized" begin
C = Conversion(NormalizedUltraspherical(0.5), Legendre())
@test C * Fun(x->x^4, NormalizedUltraspherical(0.5)) ≈ Fun(x->x^4, Legendre())
@test isdiag(C)
g = C * Fun(x->x^4, NormalizedUltraspherical(0.5))
@test space(g) == Legendre()
@test g ≈ Fun(x->x^4, Legendre())

C = Conversion(Ultraspherical(0.5), NormalizedLegendre())
@test isdiag(C)
g = C * Fun(x->x^4, Ultraspherical(0.5))
@test space(g) == NormalizedLegendre()
@test g ≈ Fun(x->x^4, NormalizedLegendre())

C = Conversion(Legendre(), NormalizedChebyshev())
@test C * Fun(x->x^4, Legendre()) ≈ Fun(x->x^4, NormalizedChebyshev())
Expand Down
23 changes: 23 additions & 0 deletions test/UltrasphericalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ include("testutils.jl")
end
end

@testset "Normalized" begin
Tallowed = Union{
typeof(Conversion(Ultraspherical(1), NormalizedUltraspherical(1))),
typeof(Conversion(Ultraspherical(1), NormalizedUltraspherical(2)))
}
C = @inferred Tallowed Conversion(Ultraspherical(1), NormalizedUltraspherical(1))
@test C * Fun(Ultraspherical(1)) ≈ Fun(NormalizedUltraspherical(1))

Tallowed = Union{
typeof(Conversion(NormalizedUltraspherical(1), Ultraspherical(1))),
typeof(Conversion(NormalizedUltraspherical(1), Ultraspherical(2)))
}
C = @inferred Tallowed Conversion(NormalizedUltraspherical(1), Ultraspherical(1))
@test C * Fun(NormalizedUltraspherical(1)) ≈ Fun(Ultraspherical(1))

Tallowed = Union{
typeof(Conversion(NormalizedUltraspherical(1), NormalizedUltraspherical(1))),
typeof(Conversion(NormalizedUltraspherical(1), NormalizedUltraspherical(2)))
}
C = @inferred Tallowed Conversion(NormalizedUltraspherical(1), NormalizedUltraspherical(1))
@test C * Fun(NormalizedUltraspherical(1)) ≈ Fun(NormalizedUltraspherical(1))
end

@testset "complex normalization" begin
C = Conversion(NormalizedUltraspherical(NormalizedLegendre()), Ultraspherical(Legendre()))
CC = convert(Operator{ComplexF64}, C)
Expand Down