Skip to content

Commit ecac5b3

Browse files
authored
Fixes for other packages (#82)
* Fixes for other packages * More Weighted Ldivs * Update normalized.jl * fixes * Update test_chebyshev.jl * fix tests * increase coverage
1 parent 5cf5252 commit ecac5b3

11 files changed

+63
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.5.0"
4+
version = "0.5.1"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ _equals(::AbstractWeightedBasisLayout, ::AbstractOPLayout, _, _) = false # Weigh
109109
_equals(::WeightedOPLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ)
110110
_equals(::WeightedOPLayout, ::WeightedBasisLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
111111
_equals(::WeightedBasisLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
112-
_equals(::WeightedBasisLayout{<:AbstractOPLayout}, ::WeightedBasisLayout{<:AbstractOPLayout}, A, B) = A.f == B.f && all(A.args .== B.args)
112+
_equals(::WeightedBasisLayout{<:AbstractOPLayout}, ::WeightedBasisLayout{<:AbstractOPLayout}, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
113113

114114

115115
copy(L::Ldiv{MappedOPLayout,Lay}) where Lay<:MappedBasisLayouts = copy(Ldiv{MappedBasisLayout,Lay}(L.A,L.B))

src/adaptivetransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function adaptivetransform_ldiv(A::AbstractQuasiArray{U}, f::AbstractQuasiVector
3131
return pad(similar(cfs,0), ax)
3232
end
3333

34-
if maximum(abs,@views(cfs[end-2:end])) < 10tol*maxabsc
34+
m = length(cfs)
35+
if maximum(abs,@views(cfs[max(1,m-2):m])) < 10tol*maxabsc
3536
n = length(cfs)
3637
c = padchop!(cfs, tol, ax)
3738
un = A * c

src/classical/chebyshev.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ end
255255
# sum
256256
####
257257

258-
function _sum(A::WeightedBasis{T,<:ChebyshevUWeight,<:ChebyshevU}, dims) where T
259-
w, U = A.args
258+
function _sum(::Weighted{T,<:ChebyshevU}, dims) where T
260259
@assert dims == 1
261260
Hcat(convert(T, π)/2, Zeros{T}(1,∞))
262261
end
263262

264-
function _sum(A::WeightedBasis{T,<:ChebyshevWeight,<:Chebyshev}, dims) where T
263+
# Same normalization for T,V,W
264+
function _sum(::Weighted{T,<:Chebyshev}, dims) where T
265265
@assert dims == 1
266266
Hcat(convert(T, π), Zeros{T}(1,∞))
267267
end

src/classical/legendre.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Legendre() = Legendre{Float64}()
4444

4545
weighted(P::Legendre) = P
4646
weighted(P::Normalized{<:Any,<:Legendre}) = P
47+
weighted(P::SubQuasiArray{<:Any,2,<:Legendre}) = P
48+
weighted(P::SubQuasiArray{<:Any,2,<:Normalized{<:Any,<:Legendre}}) = P
4749

4850
legendre() = Legendre()
4951
legendre(d::AbstractInterval{T}) where T = Legendre{float(T)}()[affine(d,ChebyshevInterval{T}()), :]

src/lanczos.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ MemoryLayout(::Type{<:LanczosPolynomial}) = LanczosLayout()
233233
arguments(::ApplyLayout{typeof(*)}, Q::LanczosPolynomial) = Q.P, LanczosConversion(Q.data)
234234
copy(L::Ldiv{LanczosLayout,Lay}) where Lay<:AbstractLazyLayout = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A,L.B))
235235
copy(L::Ldiv{LanczosLayout,Lay}) where Lay<:BroadcastLayout = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A,L.B))
236+
copy(L::Ldiv{LanczosLayout,BroadcastLayout{typeof(*)}}) = copy(Ldiv{ApplyLayout{typeof(*)},BroadcastLayout{typeof(*)}}(L.A,L.B))
237+
copy(L::Ldiv{LanczosLayout,BroadcastLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = copy(Ldiv{ApplyLayout{typeof(*)},BroadcastLayout{typeof(*)}}(L.A,L.B))
236238
copy(L::Ldiv{LanczosLayout,ApplyLayout{typeof(*)}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
237239
copy(L::Ldiv{LanczosLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
238240
copy(L::Ldiv{LanczosLayout,<:ExpansionLayout}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A, L.B))

src/normalized.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ ContinuumArrays.unweighted(wP::AbstractWeighted) = wP.P
176176
# copy(L::Ldiv{WeightedOPLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = copy(Ldiv{UnknownLayout,ApplyLayout{typeof(*)}}(L.A, L.B))
177177

178178
copy(L::Ldiv{<:WeightedOPLayout{<:NormalizedOPLayout},Lay}) where Lay<:AbstractBasisLayout = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A,L.B))
179+
copy(L::Ldiv{Lay,<:WeightedOPLayout{<:NormalizedOPLayout}}) where Lay<:AbstractBasisLayout = copy(Ldiv{Lay,ApplyLayout{typeof(*)}}(L.A,L.B))
180+
copy(L::Ldiv{<:WeightedOPLayout{<:NormalizedOPLayout},<:WeightedOPLayout{<:NormalizedOPLayout}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
181+
copy(L::Ldiv{<:WeightedBasisLayout{<:NormalizedOPLayout},Lay}) where Lay<:AbstractBasisLayout = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A,L.B))
182+
copy(L::Ldiv{Lay,<:WeightedBasisLayout{<:NormalizedOPLayout}}) where Lay<:AbstractBasisLayout = copy(Ldiv{Lay,ApplyLayout{typeof(*)}}(L.A,L.B))
183+
copy(L::Ldiv{<:WeightedBasisLayout{<:NormalizedOPLayout},<:WeightedBasisLayout{<:NormalizedOPLayout}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
184+
copy(L::Ldiv{<:WeightedOPLayout{<:NormalizedOPLayout},<:WeightedBasisLayout{<:NormalizedOPLayout}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
185+
copy(L::Ldiv{<:WeightedBasisLayout{<:NormalizedOPLayout},<:WeightedOPLayout{<:NormalizedOPLayout}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
186+
179187

180188
# function layout_broadcasted(::ExpansionLayout{WeightedOPLayout}, ::OPLayout, ::typeof(*), a, P)
181189
# axes(a,1) == axes(P,1) || throw(DimensionMismatch())
@@ -226,8 +234,15 @@ copy(Q::Weighted) = Q
226234

227235
weight(wP::Weighted) = orthogonalityweight(wP.P)
228236

229-
MemoryLayout(::Type{<:Weighted{<:Any,PP}}) where PP = WeightedOPLayout{typeof(MemoryLayout(PP))}()
237+
_weightedmemorylayout(::PP) where PP<:AbstractOPLayout = WeightedOPLayout{PP}()
238+
_weightedmemorylayout(::PP) where PP = WeightedBasisLayout{PP}()
239+
MemoryLayout(::Type{<:Weighted{<:Any,PP}}) where PP = _weightedmemorylayout(MemoryLayout(PP))
230240

241+
function arguments(::ApplyLayout{typeof(*)}, Q::BroadcastQuasiMatrix{<:Any,typeof(*),<:Tuple{Weight,Normalized}})
242+
w,Q = Q.args
243+
P,D = arguments(*,Q)
244+
(w .* P),D
245+
end
231246
function arguments(::ApplyLayout{typeof(*)}, Q::Weighted{<:Any,<:Normalized})
232247
P,D = arguments(*, Q.P)
233248
Weighted(P),D

test/test_chebyshev.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map, WeightedBasisLayout
209209

210210
WU2 = Weighted(chebyshevu(0..1))
211211
@test (Derivative(x) * WU2)[0.1,1:10] 2(Derivative(axes(T,1))*Weighted(ChebyshevU()))[2*0.1-1,1:10]
212+
213+
@testset "Derivative" begin
214+
y = affine(0..1,-1..1)
215+
D = Derivative(Inclusion(0..1))
216+
@test isbanded(wT[y,:] \ D * wU[y,:])
217+
@test isbanded((wU[y,:]' * D').args[1])
218+
end
212219
end
213220
end
214221

test/test_jacobi.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,5 +466,28 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
466466
@test HalfWeighted{:b}(Jacobi(2,0)) == Jacobi(2,0)
467467
@test Jacobi(2,0) == HalfWeighted{:b}(Jacobi(2,0))
468468
end
469+
470+
@testset "Weighted(Normalized)" begin
471+
w = JacobiWeight(1,1)
472+
P = Jacobi(1,1)
473+
Q = Normalized(P)
474+
475+
@test w .* Q == w .* Q
476+
477+
@test Weighted(Q) \ Weighted(P) isa Diagonal
478+
@test Weighted(P) \ Weighted(Q) isa Diagonal
479+
@test Weighted(Q) \ Weighted(Q) isa Diagonal
480+
481+
@test (w .* Q) \ (w .* P) isa Diagonal
482+
@test (w .* P) \ (w .* Q) isa Diagonal
483+
@test (w .* Q) \ (w .* Q) isa Diagonal
484+
485+
@test (w .* Q) \ Weighted(P) isa Diagonal
486+
@test (w .* P) \ Weighted(Q) isa Diagonal
487+
@test (w .* Q) \ Weighted(Q) isa Diagonal
488+
@test Weighted(P) \ (w .* Q) isa Diagonal
489+
@test Weighted(Q) \ (w .* P) isa Diagonal
490+
@test Weighted(Q) \ (w .* Q) isa Diagonal
491+
end
469492
end
470493
end

test/test_lanczos.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout, ort
9090
@test R \ [1; 2; 3; zeros(∞)] [1; 2; 3; zeros(∞)]
9191
@test (Q * (Q \ (1 .- x.^2)))[0.1] (1-0.1^2)
9292

93+
@test Q \ (x .* x) Q \ x.^2
94+
9395
= Normalized(P)*[1; 2; 3; zeros(∞)]
9496
u = Q*[1; 2; 3; zeros(∞)]
9597
= P * (P\u)
@@ -150,6 +152,8 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout, ort
150152
Q = LanczosPolynomial(w, P)
151153
@test Q[0.1,1:10] Normalized(P)[0.1,1:10]
152154

155+
@test (Q \ (exp.(x) .* P)) * [1; zeros(∞)] Q \ exp.(x)
156+
153157
w = @. exp(x) * sqrt(1-x)
154158
Q = LanczosPolynomial(w, P)
155159
# emperical from Julia

0 commit comments

Comments
 (0)