Skip to content

Commit ba5e437

Browse files
authored
Conversion_normalizedspace for a normalized space is a no-op (#502)
* Conversion_normalizedspace for a normalized space is a no-op * Move Val flip to else branch
1 parent 4f33475 commit ba5e437

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.41"
3+
version = "0.8.42"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Operators/banded/Conversion.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ Return `Conversion(S, normalizedspace(S))`. This may be concretely inferred for
9090
Return `Conversion(normalizedspace(S), S)`. This may be concretely inferred for orthogonal polynomial spaces.
9191
"""
9292
function Conversion_normalizedspace(S::Space, v::Union{Val{:forward}, Val{:backward}} = Val(:forward))
93-
vflip = v isa Val{:forward} ? Val(:backward) : Val(:forward)
94-
Conversion_maybeconcrete(normalizedspace(S), S, vflip)
93+
NS = normalizedspace(S)
94+
if S isa typeof(NS) # in case S is already normalized, in which case the conversion is a no-op
95+
Conversion(S)
96+
else
97+
vflip = v isa Val{:forward} ? Val(:backward) : Val(:forward)
98+
Conversion_maybeconcrete(NS, S, vflip)
99+
end
95100
end
96101

97102
"""

src/eigen.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ end
160160
function basis_recombination(SE::EigenSystem)
161161
L, QS = SE.L, SE.QS
162162
S = domainspace(L)
163+
C = Conversion(S, rangespace(L))
163164
D1 = Conversion_normalizedspace(S)
164165
D2 = Conversion_normalizedspace(S, Val(:backward))
165166
Q = Conversion(QS, S)
166-
R = D1*Q;
167-
C = Conversion(S, rangespace(L))
167+
R = D1*Q
168168
P = cache(PartialInverseOperator(C, (0, bandwidth(L, 1) + bandwidth(R, 1) + bandwidth(C, 2))));
169169
A = R'D1*P*L*D2*R
170-
BB = R'R;
170+
B = R'R
171171

172-
return A, BB
172+
return A, B
173173
end
174174

175175
"""

test/PolynomialSpacesTests.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Base.:(==)(a::UniqueInterval, b::UniqueInterval) = (@assert a.parentinterval ==
147147
end
148148
end
149149

150-
@testset "conversion" begin
150+
@testset "Conversion" begin
151151
C12 = Conversion(Chebyshev(), NormalizedLegendre())
152152
C21 = Conversion(NormalizedLegendre(), Chebyshev())
153153
@test Matrix((C12 * C21)[1:10, 1:10]) I
@@ -157,6 +157,21 @@ Base.:(==)(a::UniqueInterval, b::UniqueInterval) = (@assert a.parentinterval ==
157157
C1C2 = Conversion(Ultraspherical(1), NormalizedPolynomialSpace(Ultraspherical(1))) *
158158
Conversion(Chebyshev(), Ultraspherical(1))
159159
@test Matrix(C12[1:10, 1:10]) Matrix(C1C2[1:10, 1:10])
160+
161+
@testset "to normalized spaces" begin
162+
for S in (Legendre(), NormalizedLegendre())
163+
f = Fun(x->x^2, S)
164+
C = @inferred Conversion_normalizedspace(S, Val(:forward))
165+
g = C * f
166+
@test space(g) == normalizedspace(space(f))
167+
@test g f
168+
f = Fun(x->x^2, normalizedspace(S))
169+
C = @inferred Conversion_normalizedspace(S, Val(:backward))
170+
g = C * f
171+
@test normalizedspace(space(g)) == space(f)
172+
@test g f
173+
end
174+
end
160175
end
161176

162177
@testset "union" begin

0 commit comments

Comments
 (0)