Skip to content

Commit cf090e3

Browse files
Incorporating diagonal scaling into partial Cholesky fixes cheb2legTH
1 parent b6e4fdf commit cf090e3

File tree

2 files changed

+65
-35
lines changed

2 files changed

+65
-35
lines changed

docs/api/FastTransforms.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See also [`icjt`](#method__icjt.1) and [`jjt`](#method__jjt.1).
1313

1414

1515
*source:*
16-
[FastTransforms/src/cjt.jl:121](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/cjt.jl#L121)
16+
[FastTransforms/src/cjt.jl:121](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/cjt.jl#L121)
1717

1818
---
1919

@@ -23,7 +23,7 @@ Calculates the Gaunt coefficients in 64-bit floating-point arithmetic.
2323

2424

2525
*source:*
26-
[FastTransforms/src/gaunt.jl:24](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/gaunt.jl#L24)
26+
[FastTransforms/src/gaunt.jl:24](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/gaunt.jl#L24)
2727

2828
---
2929

@@ -43,7 +43,7 @@ This is a Julia implementation of the stable recurrence described in:
4343

4444

4545
*source:*
46-
[FastTransforms/src/gaunt.jl:14](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/gaunt.jl#L14)
46+
[FastTransforms/src/gaunt.jl:14](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/gaunt.jl#L14)
4747

4848
---
4949

@@ -56,7 +56,7 @@ See also [`cjt`](#method__cjt.1) and [`jjt`](#method__jjt.1).
5656

5757

5858
*source:*
59-
[FastTransforms/src/cjt.jl:129](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/cjt.jl#L129)
59+
[FastTransforms/src/cjt.jl:129](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/cjt.jl#L129)
6060

6161
---
6262

@@ -69,7 +69,7 @@ See also [`cjt`](#method__cjt.1) and [`icjt`](#method__icjt.1).
6969

7070

7171
*source:*
72-
[FastTransforms/src/cjt.jl:137](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/cjt.jl#L137)
72+
[FastTransforms/src/cjt.jl:137](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/cjt.jl#L137)
7373

7474
---
7575

@@ -88,7 +88,7 @@ Optionally:
8888

8989

9090
*source:*
91-
[FastTransforms/src/cjt.jl:158](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/cjt.jl#L158)
91+
[FastTransforms/src/cjt.jl:158](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/cjt.jl#L158)
9292

9393
---
9494

@@ -107,7 +107,7 @@ Optionally:
107107

108108

109109
*source:*
110-
[FastTransforms/src/cjt.jl:172](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/cjt.jl#L172)
110+
[FastTransforms/src/cjt.jl:172](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/cjt.jl#L172)
111111

112112
## Internal
113113

@@ -122,7 +122,7 @@ Modified Chebyshev moments of the first kind with respect to the Jacobi weight:
122122

123123

124124
*source:*
125-
[FastTransforms/src/specialfunctions.jl:399](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L399)
125+
[FastTransforms/src/specialfunctions.jl:399](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L399)
126126

127127
---
128128

@@ -135,7 +135,7 @@ Modified Chebyshev moments of the second kind with respect to the Jacobi weight:
135135

136136

137137
*source:*
138-
[FastTransforms/src/specialfunctions.jl:417](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L417)
138+
[FastTransforms/src/specialfunctions.jl:417](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L417)
139139

140140
---
141141

@@ -145,7 +145,7 @@ Compute weights of the Clenshaw—Curtis quadrature rule with a Jacobi weight.
145145

146146

147147
*source:*
148-
[FastTransforms/src/clenshawcurtis.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/clenshawcurtis.jl#L12)
148+
[FastTransforms/src/clenshawcurtis.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/clenshawcurtis.jl#L12)
149149

150150
---
151151

@@ -155,7 +155,7 @@ Compute nodes and weights of the Clenshaw—Curtis quadrature rule with a Jacobi
155155

156156

157157
*source:*
158-
[FastTransforms/src/clenshawcurtis.jl:6](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/clenshawcurtis.jl#L6)
158+
[FastTransforms/src/clenshawcurtis.jl:6](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/clenshawcurtis.jl#L6)
159159

160160
---
161161

@@ -165,7 +165,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α-1,β) given Jacobi expansion c
165165

166166

167167
*source:*
168-
[FastTransforms/src/specialfunctions.jl:467](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L467)
168+
[FastTransforms/src/specialfunctions.jl:467](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L467)
169169

170170
---
171171

@@ -175,7 +175,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α-1,α-1) given Jacobi expansion
175175

176176

177177
*source:*
178-
[FastTransforms/src/specialfunctions.jl:489](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L489)
178+
[FastTransforms/src/specialfunctions.jl:489](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L489)
179179

180180
---
181181

@@ -185,7 +185,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α,β-1) given Jacobi expansion c
185185

186186

187187
*source:*
188-
[FastTransforms/src/specialfunctions.jl:478](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L478)
188+
[FastTransforms/src/specialfunctions.jl:478](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L478)
189189

190190
---
191191

@@ -195,7 +195,7 @@ Compute nodes and weights of Fejer's first quadrature rule with a Jacobi weight.
195195

196196

197197
*source:*
198-
[FastTransforms/src/fejer.jl:7](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/fejer.jl#L7)
198+
[FastTransforms/src/fejer.jl:7](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/fejer.jl#L7)
199199

200200
---
201201

@@ -205,7 +205,7 @@ Compute nodes and weights of Fejer's second quadrature rule with a Jacobi weight
205205

206206

207207
*source:*
208-
[FastTransforms/src/fejer.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/fejer.jl#L12)
208+
[FastTransforms/src/fejer.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/fejer.jl#L12)
209209

210210
---
211211

@@ -215,7 +215,7 @@ Compute weights of Fejer's first quadrature rule with a Jacobi weight.
215215

216216

217217
*source:*
218-
[FastTransforms/src/fejer.jl:21](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/fejer.jl#L21)
218+
[FastTransforms/src/fejer.jl:21](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/fejer.jl#L21)
219219

220220
---
221221

@@ -225,7 +225,7 @@ Compute weights of Fejer's second quadrature rule with a Jacobi weight.
225225

226226

227227
*source:*
228-
[FastTransforms/src/fejer.jl:26](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/fejer.jl#L26)
228+
[FastTransforms/src/fejer.jl:26](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/fejer.jl#L26)
229229

230230
---
231231

@@ -235,7 +235,7 @@ Compute a typed 0.5.
235235

236236

237237
*source:*
238-
[FastTransforms/src/specialfunctions.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L12)
238+
[FastTransforms/src/specialfunctions.jl:12](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L12)
239239

240240
---
241241

@@ -245,7 +245,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α+1,β) given Jacobi expansion c
245245

246246

247247
*source:*
248-
[FastTransforms/src/specialfunctions.jl:432](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L432)
248+
[FastTransforms/src/specialfunctions.jl:432](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L432)
249249

250250
---
251251

@@ -255,7 +255,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α+1,α+1) given Jacobi expansion
255255

256256

257257
*source:*
258-
[FastTransforms/src/specialfunctions.jl:454](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L454)
258+
[FastTransforms/src/specialfunctions.jl:454](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L454)
259259

260260
---
261261

@@ -265,7 +265,7 @@ Compute Jacobi expansion coefficients in Pₙ^(α,β+1) given Jacobi expansion c
265265

266266

267267
*source:*
268-
[FastTransforms/src/specialfunctions.jl:443](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L443)
268+
[FastTransforms/src/specialfunctions.jl:443](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L443)
269269

270270
---
271271

@@ -275,7 +275,7 @@ Pochhammer symbol (x)_n = Γ(x+n)/Γ(x) for the rising factorial.
275275

276276

277277
*source:*
278-
[FastTransforms/src/specialfunctions.jl:32](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L32)
278+
[FastTransforms/src/specialfunctions.jl:32](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L32)
279279

280280
---
281281

@@ -285,7 +285,7 @@ Stirling series for Γ(z).
285285

286286

287287
*source:*
288-
[FastTransforms/src/specialfunctions.jl:63](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L63)
288+
[FastTransforms/src/specialfunctions.jl:63](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L63)
289289

290290
---
291291

@@ -295,7 +295,7 @@ Compute a typed 2.
295295

296296

297297
*source:*
298-
[FastTransforms/src/specialfunctions.jl:20](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L20)
298+
[FastTransforms/src/specialfunctions.jl:20](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L20)
299299

300300
---
301301

@@ -307,7 +307,7 @@ For 64-bit floating-point arithmetic, the Lambda function uses the asymptotic se
307307

308308

309309
*source:*
310-
[FastTransforms/src/specialfunctions.jl:147](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L147)
310+
[FastTransforms/src/specialfunctions.jl:147](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L147)
311311

312312
---
313313

@@ -317,7 +317,7 @@ The Lambda function Λ(z) = Γ(z+½)/Γ(z+1) for the ratio of gamma functions.
317317

318318

319319
*source:*
320-
[FastTransforms/src/specialfunctions.jl:141](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L141)
320+
[FastTransforms/src/specialfunctions.jl:141](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L141)
321321

322322
---
323323

@@ -327,7 +327,7 @@ The Lambda function Λ(z,λ₁,λ₂) = Γ(z+λ₁)/Γ(z+λ₂) for the ratio of
327327

328328

329329
*source:*
330-
[FastTransforms/src/specialfunctions.jl:160](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L160)
330+
[FastTransforms/src/specialfunctions.jl:160](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L160)
331331

332332
---
333333

@@ -337,7 +337,7 @@ The Kronecker δ function.
337337

338338

339339
*source:*
340-
[FastTransforms/src/specialfunctions.jl:26](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/specialfunctions.jl#L26)
340+
[FastTransforms/src/specialfunctions.jl:26](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/specialfunctions.jl#L26)
341341

342342
---
343343

@@ -351,5 +351,5 @@ where the Hankel matrix `H` is non-negative definite. This allows a Cholesky dec
351351

352352

353353
*source:*
354-
[FastTransforms/src/toeplitzhankel.jl:8](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/9a0fff4d389746d63718883170537e95ad849e76/src/toeplitzhankel.jl#L8)
354+
[FastTransforms/src/toeplitzhankel.jl:8](https://github.com/MikaelSlevinsky/FastTransforms.jl/tree/b6e4fdf35a2160f0d9948e6565fd69c2177f4d82/src/toeplitzhankel.jl#L8)
355355

src/toeplitzhankel.jl

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ function ToeplitzHankelPlan(T::TriangularToeplitz,C::Vector,DL::AbstractVector,D
1919
end
2020
ToeplitzHankelPlan(T::TriangularToeplitz,C::Matrix) =
2121
ToeplitzHankelPlan(T,C,ones(size(T,1)),ones(size(T,2)))
22-
ToeplitzHankelPlan(T::TriangularToeplitz,H::Hankel,D...) =
23-
ToeplitzHankelPlan(T,partialchol(H),D...)
22+
ToeplitzHankelPlan(T::TriangularToeplitz,H::Hankel,DL::AbstractVector,DR::AbstractVector) =
23+
ToeplitzHankelPlan(T,partialchol(H),DL,DR)
24+
ToeplitzHankelPlan(T::TriangularToeplitz,H::Hankel,D::AbstractVector,DL::AbstractVector,DR::AbstractVector) =
25+
ToeplitzHankelPlan(T,partialchol(H,D),DL,DR)
2426

2527
*(P::ToeplitzHankelPlan,v::AbstractVector)=P.DL.*toeplitzcholmult(P.T,P.C,P.DR.*v)
2628

@@ -50,6 +52,33 @@ function partialchol(H::Hankel)
5052
C
5153
end
5254

55+
function partialchol(H::Hankel,D::AbstractVector)
56+
# Assumes positive definite
57+
T = promote_type(eltype(H),eltype(D))
58+
σ=T[]
59+
n=size(H,1)
60+
C=Vector{T}[]
61+
v=[H[:,1];vec(H[end,2:end])]
62+
d=diag(H).*D.^2
63+
@assert length(v) 2n-1
64+
reltol=maxabs(d)*eps(T)*log(n)
65+
for k=1:n
66+
mx,idx=findmax(d)
67+
if mx reltol break end
68+
push!(σ,inv(mx))
69+
push!(C,v[idx:n+idx-1].*D.*D[idx])
70+
for j=1:k-1
71+
nCjidxσj = -C[j][idx]*σ[j]
72+
Base.axpy!(nCjidxσj, C[j], C[k])
73+
end
74+
@simd for p=1:n
75+
@inbounds d[p]-=C[k][p]^2/mx
76+
end
77+
end
78+
for k=1:length(σ) scale!(C[k],sqrt(σ[k])) end
79+
C
80+
end
81+
5382
function toeplitzcholmult(T,C,v)
5483
n,K = length(v),length(C)
5584
ret,temp1,temp2 = zero(v),zero(v),zero(v)
@@ -86,9 +115,10 @@ function cheb2legTH{S}(::Type{S},n)
86115
T = TriangularToeplitz(t,:U)
87116
h = Λ(1:half(S):n-1,zero(S),3half(S))
88117
H = Hankel(h[1:n-1],h[n-1:end])
89-
DL = 3half(S):n-half(S)
90-
DR = -(one(S):n-one(S))/4
91-
T,H,DL,DR
118+
D = 1:one(S):n-1
119+
DL = (3half(S):n-half(S))./D
120+
DR = -(one(S):n-one(S))./4D
121+
T,H,D,DL,DR
92122
end
93123

94124
function leg2chebuTH{S}(::Type{S},n)

0 commit comments

Comments
 (0)