Skip to content

Commit b5dfbc0

Browse files
authored
Add LanczosLayout (#32)
* Add LanczosLayout * ambiguity * increase coverage * v0.3.6
1 parent e44c578 commit b5dfbc0

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
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.3.5"
4+
version = "0.3.6"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -29,7 +29,7 @@ ArrayLayouts = "0.6.2"
2929
BandedMatrices = "0.16.5"
3030
BlockArrays = "0.15"
3131
BlockBandedMatrices = "0.10"
32-
ContinuumArrays = "0.7"
32+
ContinuumArrays = "0.7.1"
3333
DomainSets = "0.4, 0.5"
3434
FFTW = "1.1"
3535
FastGaussQuadrature = "0.4.3"

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import InfiniteArrays: OneToInf, InfAxes, Infinity, AbstractInfUnitRange, Infini
3030
import ContinuumArrays: Basis, Weight, basis, @simplify, Identity, AbstractAffineQuasiVector, ProjectionFactorization,
3131
inbounds_getindex, grid, transform, transform_ldiv, TransformFactorization, QInfAxes, broadcastbasis, Expansion,
3232
AffineQuasiVector, AffineMap, WeightLayout, WeightedBasisLayout, WeightedBasisLayouts, demap, AbstractBasisLayout, BasisLayout,
33-
checkpoints, weight, unweightedbasis
33+
checkpoints, weight, unweightedbasis, MappedBasisLayouts
3434
import FastTransforms: Λ, forwardrecurrence, forwardrecurrence!, _forwardrecurrence!, clenshaw, clenshaw!,
3535
_forwardrecurrence_next, _clenshaw_next, check_clenshaw_recurrences, ChebyshevGrid, chebyshevpoints
3636

src/classical/jacobi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ end
121121
Jacobi(a::V, b::T) where {T,V} = Jacobi{float(promote_type(T,V))}(a, b)
122122

123123
jacobi(a,b) = Jacobi(a,b)
124-
jacobi(a,b, d::AbstractInterval{T}) where T = Jacobi(a,b)[affine(d,ChebyshevInterval{T}()), :]
124+
jacobi(a,b, d::AbstractInterval{T}) where T = Jacobi{float(promote_type(eltype(a),eltype(b),T))}(a,b)[affine(d,ChebyshevInterval{T}()), :]
125125

126126
Jacobi(P::Legendre{T}) where T = Jacobi(zero(T), zero(T))
127127

src/lanczos.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ end
7070
size(::LanczosConversion) = (∞,∞)
7171
copy(R::LanczosConversion) = R
7272

73+
Base.permutedims(R::LanczosConversion{<:Number}) = transpose(R)
74+
7375
bandwidths(::LanczosConversion) = (0,∞)
7476
colsupport(L::LanczosConversion, j) = 1:maximum(j)
7577
rowsupport(L::LanczosConversion, j) = minimum(j):
@@ -178,6 +180,8 @@ end
178180

179181
LanczosPolynomial(w::AbstractQuasiVector) = LanczosPolynomial(w, orthonormalpolynomial(singularities(w)))
180182

183+
184+
181185
orthogonalityweight(Q::LanczosPolynomial) = Q.w
182186

183187
axes(Q::LanczosPolynomial) = (axes(Q.w,1),OneToInf())
@@ -221,8 +225,18 @@ function ldiv(Qn::SubQuasiArray{<:Any,2,<:LanczosPolynomial,<:Tuple{<:Inclusion,
221225
Q = parent(Qn)
222226
LanczosConversion(Q.data)[jr,jr] \ (Q.P[:,jr] \ C)
223227
end
228+
229+
struct LanczosLayout <: AbstractBasisLayout end
230+
231+
MemoryLayout(::Type{<:LanczosPolynomial}) = LanczosLayout()
224232
arguments(::ApplyLayout{typeof(*)}, Q::LanczosPolynomial) = Q.P, LanczosConversion(Q.data)
233+
copy(L::Ldiv{LanczosLayout,Lay}) where Lay<:AbstractLazyLayout = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A,L.B))
234+
copy(L::Ldiv{LanczosLayout,ApplyLayout{typeof(*)}}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
235+
copy(L::Ldiv{LanczosLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = copy(Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}(L.A,L.B))
225236
LazyArrays._mul_arguments(Q::LanczosPolynomial) = arguments(ApplyLayout{typeof(*)}(), Q)
226237
LazyArrays._mul_arguments(Q::QuasiAdjoint{<:Any,<:LanczosPolynomial}) = arguments(ApplyLayout{typeof(*)}(), Q)
227238

228-
\(A::LanczosPolynomial, x::AbstractQuasiVector) = ApplyQuasiArray(A) \ x
239+
240+
broadcastbasis(::typeof(+), P::Union{Normalized,LanczosPolynomial}, Q::Union{Normalized,LanczosPolynomial}) = broadcastbasis(+, P.P, Q.P)
241+
broadcastbasis(::typeof(+), P::Union{Normalized,LanczosPolynomial}, Q) = broadcastbasis(+, P.P, Q)
242+
broadcastbasis(::typeof(+), P, Q::Union{Normalized,LanczosPolynomial}) = broadcastbasis(+, P, Q.P)

src/normalized.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ for Lay in (:(ApplyLayout{typeof(*)}),:(BroadcastLayout{typeof(+)}),:(BroadcastL
123123
end
124124
end
125125

126+
copy(L::Ldiv{Lay,<:NormalizedBasisLayout}) where Lay<:MappedBasisLayouts = copy(Ldiv{Lay,ApplyLayout{typeof(*)}}(L.A,L.B))
127+
126128
# want to use special re-expansion routines without expanding Normalized basis
127129
@inline copy(L::Ldiv{<:NormalizedBasisLayout,BroadcastLayout{typeof(*)}}) = copy(Ldiv{BasisLayout,BroadcastLayout{typeof(*)}}(L.A, L.B))
128130
@inline copy(L::Ldiv{<:NormalizedBasisLayout,BroadcastLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = copy(Ldiv{BasisLayout,BroadcastLayout{typeof(*)}}(L.A, L.B))
@@ -196,4 +198,4 @@ broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::Weighted) =
196198
@simplify *(Ac::QuasiAdjoint{<:Any,<:Weighted}, wB::Weighted) =
197199
convert(WeightedOrthogonalPolynomial, parent(Ac))' * convert(WeightedOrthogonalPolynomial, wB)
198200

199-
summary(io::IO, Q::Weighted) = print(io, "Weighted($(Q.P))")
201+
summary(io::IO, Q::Weighted) = print(io, "Weighted($(Q.P))")

test/test_jacobi.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
163163
= @.(sqrt(1 - x̃) * exp(x̃))
164164
@test wP̃[0.1,1:100]'*(wP̃[:,1:100] \ f̃) sqrt(1-0.1) * exp(0.1)
165165
@test (wP̃ * (wP̃ \ f̃))[0.1] sqrt(1-0.1) * exp(0.1)
166+
167+
@testset "bug" begin
168+
P = jacobi(0,-1/2,0..1)
169+
x = axes(P,1)
170+
u = P * (P \ exp.(x))
171+
@test u[0.1] exp(0.1)
172+
end
166173
end
167174

168175
@testset "trivial weight" begin

test/test_lanczos.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ClassicalOrthogonalPolynomials, BandedMatrices, ArrayLayouts, Test
2-
import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout
2+
import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout, orthogonalityweight
33

44
@testset "Lanczos" begin
55
@testset "Legendre" begin
@@ -84,9 +84,19 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedLayout
8484
w = P * [1; zeros(∞)];
8585
Q = LanczosPolynomial(w);
8686
R = Normalized(P) \ Q
87+
@test bandwidths(R) == (0,∞)
88+
@test orthogonalityweight(Q) == w
89+
@test permutedims(R) === transpose(R)
8790
@test R * [1; 2; 3; zeros(∞)] [R[1:3,1:3] * [1,2,3]; zeros(∞)]
8891
@test R \ [1; 2; 3; zeros(∞)] [1; 2; 3; zeros(∞)]
8992
@test (Q * (Q \ (1 .- x.^2)))[0.1] (1-0.1^2)
93+
94+
= Normalized(P)*[1; 2; 3; zeros(∞)]
95+
u = Q*[1; 2; 3; zeros(∞)]
96+
= P * (P\u)
97+
@test (u + u)[0.1] (ũ + u)[0.1] (u + ũ)[0.1] (ũ + ũ)[0.1] (ū + u)[0.1] (u + ū)[0.1] (ū + ū)[0.1] 2u[0.1]
98+
99+
@test Q \ u Q \ Q \
90100
end
91101

92102
@testset "Jacobi via Lanczos" begin

0 commit comments

Comments
 (0)