Skip to content

Commit d0eb7cf

Browse files
committed
MemoryLayout(Weighted) isa WeightedLayout
1 parent e0af376 commit d0eb7cf

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export OrthogonalPolynomial, Normalized, orthonormalpolynomial, LanczosPolynomia
4545
WeightedUltraspherical, WeightedChebyshev, WeightedChebyshevT, WeightedChebyshevU, WeightedJacobi,
4646
∞, Derivative, .., Inclusion,
4747
chebyshevt, chebyshevu, legendre, jacobi,
48-
legendrep, jacobip, ultrasphericalc, laguerrel,hermiteh,
48+
legendrep, jacobip, ultrasphericalc, laguerrel,hermiteh, normalizedjacobip,
4949
jacobimatrix, jacobiweight, legendreweight, chebyshevtweight, chebyshevuweight
5050

5151
if VERSION < v"1.6-"

src/jacobi.jl

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ computes the `n`-th Jacobi polynomial, orthogonal with
132132
respec to `(1-x)^a*(1+x)^b`, at `z`.
133133
"""
134134
jacobip(n::Integer, a, b, z::Number) = Base.unsafe_getindex(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b), z, n+1)
135+
normalizedjacobip(n::Integer, a, b, z::Number) = Base.unsafe_getindex(Normalized(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b)), z, n+1)
135136

136137
OrthogonalPolynomial(w::JacobiWeight) = Jacobi(w.a, w.b)
137138
orthogonalityweight(P::Jacobi) = JacobiWeight(P.a, P.b)
@@ -148,7 +149,7 @@ WeightedJacobi{T}(a,b) where T = JacobiWeight{T}(a,b) .* Jacobi{T}(a,b)
148149
is equivalent to `JacobiWeight(a,0) .* Jacobi(a,b)` (`lr = :a`) or
149150
`JacobiWeight(0,b) .* Jacobi(a,b)` (`lr = :b`)
150151
"""
151-
struct HalfWeighted{lr, T, PP<:AbstractQuasiMatrix{T}} <: Basis{T}
152+
struct HalfWeighted{lr, T, PP<:AbstractQuasiMatrix{T}} <: AbstractWeighted{T}
152153
P::PP
153154
end
154155

@@ -159,16 +160,18 @@ copy(Q::HalfWeighted) = Q
159160

160161
==(A::HalfWeighted, B::HalfWeighted) = A.P == B.P
161162

162-
convert(::Type{WeightedJacobi}, Q::HalfWeighted{:a,T}) where T = JacobiWeight(Q.P.a,zero(T)) .* Q.P
163-
convert(::Type{WeightedJacobi}, Q::HalfWeighted{:b,T}) where T = JacobiWeight(zero(T),Q.P.b) .* Q.P
163+
convert(::Type{WeightedOrthogonalPolynomial}, Q::HalfWeighted{:a,T,<:Jacobi}) where T = JacobiWeight(Q.P.a,zero(T)) .* Q.P
164+
convert(::Type{WeightedOrthogonalPolynomial}, Q::HalfWeighted{:b,T,<:Jacobi}) where T = JacobiWeight(zero(T),Q.P.b) .* Q.P
165+
convert(::Type{WeightedOrthogonalPolynomial}, Q::HalfWeighted{:a,T,<:Normalized}) where T = JacobiWeight(Q.P.P.a,zero(T)) .* Q.P
166+
convert(::Type{WeightedOrthogonalPolynomial}, Q::HalfWeighted{:b,T,<:Normalized}) where T = JacobiWeight(zero(T),Q.P.P.b) .* Q.P
164167

165-
getindex(Q::HalfWeighted, x::Union{Number,AbstractVector}, jr::Union{Number,AbstractVector}) = convert(WeightedJacobi, Q)[x,jr]
168+
getindex(Q::HalfWeighted, x::Union{Number,AbstractVector}, jr::Union{Number,AbstractVector}) = convert(WeightedOrthogonalPolynomial, Q)[x,jr]
166169

167170
broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::HalfWeighted) = Q * (Q.P \ (x .* Q.P))
168171

169-
\(w_A::HalfWeighted, w_B::HalfWeighted) = convert(WeightedJacobi, w_A) \ convert(WeightedJacobi, w_B)
170-
\(w_A::HalfWeighted, B::AbstractQuasiArray) = convert(WeightedJacobi, w_A) \ B
171-
\(A::AbstractQuasiArray, w_B::HalfWeighted) = A \ convert(WeightedJacobi, w_B)
172+
\(w_A::HalfWeighted, w_B::HalfWeighted) = convert(WeightedOrthogonalPolynomial, w_A) \ convert(WeightedOrthogonalPolynomial, w_B)
173+
\(w_A::HalfWeighted, B::AbstractQuasiArray) = convert(WeightedOrthogonalPolynomial, w_A) \ B
174+
\(A::AbstractQuasiArray, w_B::HalfWeighted) = A \ convert(WeightedOrthogonalPolynomial, w_B)
172175

173176
axes(::AbstractJacobi{T}) where T = (Inclusion{T}(ChebyshevInterval{real(T)}()), oneto(∞))
174177
==(P::Jacobi, Q::Jacobi) = P.a == Q.a && P.b == Q.b
@@ -370,16 +373,6 @@ end
370373
# Jacobi(a+1,b+1)\(D*Jacobi(a,b))
371374
@simplify *(D::Derivative{<:Any,<:AbstractInterval}, S::Jacobi) = Jacobi(S.a+1,S.b+1) * _BandedMatrix((((1:∞) .+ (S.a + S.b))/2)', ℵ₀, -1,1)
372375

373-
@simplify function *(D::Derivative{<:Any,<:AbstractInterval}, WS::Weighted{<:Any,<:Jacobi})
374-
# L_1^t
375-
S = WS.P
376-
a,b = S.a, S.b
377-
if a == b == 0
378-
D*S
379-
else
380-
Weighted(Jacobi(a-1, b-1)) * _BandedMatrix((-2*(1:∞))', ℵ₀, 1,-1)
381-
end
382-
end
383376

384377
#L_6^t
385378
@simplify function *(D::Derivative{<:Any,<:AbstractInterval}, WS::HalfWeighted{:a,<:Any,<:Jacobi})
@@ -395,6 +388,29 @@ end
395388
HalfWeighted{:b}(Jacobi(a+1,b-1)) * Diagonal(b:∞)
396389
end
397390

391+
for ab in (:(:a), :(:b))
392+
@eval @simplify function *(D::Derivative{<:Any,<:AbstractInterval}, WS::HalfWeighted{$ab,<:Any,<:Normalized})
393+
P,M = arguments(ApplyLayout{typeof(*)}(), WS.P)
394+
D * HalfWeighted{$ab}(P) * M
395+
end
396+
end
397+
398+
399+
@simplify function *(D::Derivative{<:Any,<:AbstractInterval}, WS::Weighted{<:Any,<:Jacobi})
400+
# L_1^t
401+
S = WS.P
402+
a,b = S.a, S.b
403+
if a == b == 0
404+
D*S
405+
elseif iszero(a)
406+
D * HalfWeighted{:b}(S)
407+
elseif iszero(b)
408+
D * HalfWeighted{:a}(S)
409+
else
410+
Weighted(Jacobi(a-1, b-1)) * _BandedMatrix((-2*(1:∞))', ℵ₀, 1,-1)
411+
end
412+
end
413+
398414

399415
# Jacobi(a-1,b-1)\ (D*w*Jacobi(a,b))
400416
@simplify function *(D::Derivative{<:Any,<:AbstractInterval}, WS::WeightedJacobi)

src/normalized.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,17 @@ function getindex(Q::OrthonormalWeighted, x::Union{Number,AbstractVector}, jr::U
173173
end
174174
broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::OrthonormalWeighted) = Q * (Q.P \ (x .* Q.P))
175175

176+
177+
abstract type AbstractWeighted{T} <: Basis{T} end
178+
179+
MemoryLayout(::Type{<:AbstractWeighted}) = WeightedBasisLayout()
180+
176181
"""
177182
Weighted(P)
178183
179184
is equivalent to `orthogonalityweight(P) .* P`
180185
"""
181-
struct Weighted{T, PP<:AbstractQuasiMatrix{T}} <: Basis{T}
186+
struct Weighted{T, PP<:AbstractQuasiMatrix{T}} <: AbstractWeighted{T}
182187
P::PP
183188
end
184189

@@ -200,4 +205,6 @@ broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::Weighted) =
200205
\(A::AbstractQuasiArray, w_B::Weighted) = A \ convert(WeightedOrthogonalPolynomial, w_B)
201206

202207
@simplify *(Ac::QuasiAdjoint{<:Any,<:Weighted}, wB::Weighted) =
203-
convert(WeightedOrthogonalPolynomial, parent(Ac))' * convert(WeightedOrthogonalPolynomial, wB)
208+
convert(WeightedOrthogonalPolynomial, parent(Ac))' * convert(WeightedOrthogonalPolynomial, wB)
209+
210+
summary(io::IO, Q::Weighted) = print(io, "Weighted($(Q.P))")

test/test_chebyshev.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ClassicalOrthogonalPolynomials, QuasiArrays, ContinuumArrays, BandedMatrices, LazyArrays,
22
FastTransforms, ArrayLayouts, Test, FillArrays, Base64, BlockArrays, LazyBandedMatrices, ForwardDiff
3-
import ClassicalOrthogonalPolynomials: Clenshaw, recurrencecoefficients, clenshaw, paddeddata, jacobimatrix, oneto
3+
import ClassicalOrthogonalPolynomials: Clenshaw, recurrencecoefficients, clenshaw, paddeddata, jacobimatrix, oneto, Weighted
44
import LazyArrays: ApplyStyle
55
import QuasiArrays: MulQuasiMatrix
66
import Base: OneTo
@@ -128,6 +128,12 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map
128128
u = wT * (wT \ @.(exp(x)/sqrt(1-x^2)))
129129
@test u[0.1] exp(0.1)/sqrt(1-0.1^2)
130130

131+
@testset "Weighted" begin
132+
WT = Weighted(ChebyshevT())
133+
@test wT[0.1,1:10] WT[0.1,1:10]
134+
@test WT \ (exp.(x) ./ sqrt.(1 .- x.^2)) wT \ (exp.(x) ./ sqrt.(1 .- x.^2))
135+
end
136+
131137
@testset "mapped" begin
132138
x = Inclusion(0..1)
133139
wT̃ = wT[2x .- 1, :]

0 commit comments

Comments
 (0)