Skip to content

Commit 5256e8e

Browse files
authored
Fix cholesky interface with singularities (#168)
* Fix cholesky interface with singularities * Update test_choleskyQR.jl * v0.12.3
1 parent fb28b6f commit 5256e8e

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
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.12.2"
4+
version = "0.12.3"
55

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

examples/marchenkopasturops.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ using ClassicalOrthogonalPolynomials, Plots
44
r = 0.5
55
lmin, lmax = (1-sqrt(r))^2, (1+sqrt(r))^2
66
U = chebyshevu(lmin..lmax)
7-
x = axes(U,1)
8-
w = @. 1/(2π) * sqrt((lmax-x)*(x-lmin))/(x*r)
97

108
# Q is a quasimatrix such that Q[x,k+1] is equivalent to
119
# qₖ(x), the k-th orthogonal polynomial wrt to w
12-
Q = LanczosPolynomial(w, U)
10+
Q = OrthogonalPolynomial(x -> 1/(2π) * sqrt((lmax-x)*(x-lmin))/(x*r), U)
1311

1412
# The Jacobi matrix associated with Q, as an ∞×∞ SymTridiagonal
1513
J = jacobimatrix(Q)
@@ -22,7 +20,5 @@ a,b = 5,10
2220
c,d = sqrt(a/(a+b) * (1-1/(a+b))), sqrt(1/(a+b) * (1-a/(a+b)))
2321
lmin,lmax = (c-d)^2,(c+d)^2
2422
U = chebyshevu(lmin..lmax)
25-
x = axes(U,1)
26-
w = @. (a+b) * sqrt((x-lmin)*(lmax-x))/(2π*x*(1-x))
27-
Q = LanczosPolynomial(w, U)
23+
Q = OrthogonalPolynomial(x -> (a+b) * sqrt((x-lmin)*(lmax-x))/(2π*x*(1-x)), U)
2824
plot(Q[:,1:7])

src/choleskyQR.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ function OrthogonalPolynomial(w::AbstractQuasiVector, P::AbstractQuasiMatrix)
2626
ConvertedOrthogonalPolynomial(w, X, parent(X.dv).U, Q)
2727
end
2828

29-
orthogonalpolynomial(w::AbstractQuasiVector) = OrthogonalPolynomial(w)
29+
orthogonalpolynomial(wP...) = OrthogonalPolynomial(wP...)
3030
orthogonalpolynomial(w::SubQuasiArray) = orthogonalpolynomial(parent(w))[parentindices(w)[1],:]
3131

32+
OrthogonalPolynomial(w::Function, P::AbstractQuasiMatrix) = OrthogonalPolynomial(w.(axes(P,1)), P)
33+
orthogonalpolynomial(w::Function, P::AbstractQuasiMatrix) = orthogonalpolynomial(w.(axes(P,1)), P)
3234

3335

3436
"""
@@ -43,7 +45,8 @@ cholesky_jacobimatrix(w::Function, P) = cholesky_jacobimatrix(w.(axes(P,1)), P)
4345

4446
function cholesky_jacobimatrix(w::AbstractQuasiVector, P)
4547
Q = normalized(P)
46-
W = Symmetric(Q \ (w .* Q)) # Compute weight multiplication via Clenshaw
48+
w_P = orthogonalityweight(P)
49+
W = Symmetric(Q \ ((w ./ w_P) .* Q)) # Compute weight multiplication via Clenshaw
4750
return cholesky_jacobimatrix(W, Q)
4851
end
4952
function cholesky_jacobimatrix(W::AbstractMatrix, Q)

test/test_choleskyQR.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test, ClassicalOrthogonalPolynomials, BandedMatrices, LinearAlgebra, LazyArrays, ContinuumArrays, LazyBandedMatrices, InfiniteLinearAlgebra
2-
import ClassicalOrthogonalPolynomials: cholesky_jacobimatrix, qr_jacobimatrix
2+
import ClassicalOrthogonalPolynomials: cholesky_jacobimatrix, qr_jacobimatrix, orthogonalpolynomial
33
import LazyArrays: AbstractCachedMatrix, resizedata!
44

55

@@ -10,7 +10,7 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
1010
P = Normalized(legendre(0..1))
1111
x = axes(P,1)
1212
J = jacobimatrix(P)
13-
wf(x) = x^2*(1-x)
13+
wf = x -> x^2*(1-x)
1414
# compute Jacobi matrix via cholesky
1515
Jchol = cholesky_jacobimatrix(wf, P)
1616
# compute Jacobi matrix via classical recurrence
@@ -224,7 +224,7 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
224224

225225
@test Q == Q
226226
@test P Q
227-
@test Q  P
227+
@test Q P
228228
@test Q ==
229229
@test== Q
230230

@@ -243,4 +243,13 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
243243
# need to fix InfiniteLinearAlgebra to add AdaptiveBandedLayout
244244
@test_broken R[1:10,1:10] isa BandedMatrix
245245
end
246+
247+
@testset "Chebyshev" begin
248+
U = ChebyshevU()
249+
Q = orthogonalpolynomial(x -> (1+x^2)*sqrt(1-x^2), U)
250+
@test bandwidths(Q\U) == (0,2)
251+
252+
= OrthogonalPolynomial(x -> (1+x^2)*sqrt(1-x^2), U)
253+
@test jacobimatrix(Q)[1:10,1:10] == jacobimatrix(Q̃)[1:10,1:10]
254+
end
246255
end

0 commit comments

Comments
 (0)