Skip to content

Commit bc9344c

Browse files
dlfivefiftyclaude
andcommitted
Fix NaN in th_jac2jac when an intermediate γ+β+1 == 0
e.g. th_jac2cheb(x, -0.25, -0.25) returned NaN in the first entry: the second Toeplitz-dot-Hankel step converts to (-1/2,-1/2) from β = -1/2 so the left diagonal is (2k+λ)Λ(k,λ,μ) with λ = 0, which is 0*Inf at k = 0. Use λΓ(λ) = Γ(λ+1) for that entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5126667 commit bc9344c

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FastTransforms"
22
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
3-
version = "0.17.2"
3+
version = "0.17.3"
44

55

66
[deps]

‎src/toeplitzhankel.jl‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,20 @@ function alternatesign!(v)
447447
v
448448
end
449449

450+
# (2k+λ)*Λ(k,λ,μ), using λ*Γ(λ) = Γ(λ+1) for k = 0 to avoid 0*Inf when λ = 0, e.g. when converting to Chebyshev
451+
function _jac2jac_DL(jk, λ, μ)
452+
DL = (2jk .+ λ).*Λ.(jk,λ,μ)
453+
isempty(DL) || (DL[1] = Λ(0,λ+1,μ))
454+
DL
455+
end
456+
450457
function _jac2jacTH_TLC(::Type{S}, mn, α, β, γ, δ, d) where {S}
451458
n = mn[d]
452459
@assert α+β > -1
453460
if β == δ
454461
@assert abs(α-γ) < 1
455462
jk = 0:n-1
456-
DL = (2jk .+ γ .+ β .+ 1).*Λ.(jk,γ+β+1,β+1)
463+
DL = _jac2jac_DL(jk,γ+β+1,β+1)
457464
t = convert(AbstractVector{S}, Λ.(jk, α-γ,1))
458465
h = Λ.(0:2n-2,α+β+1,γ+β+2)
459466
DR = Λ.(jk,β+1,α+β+1)./gamma(α-γ)
@@ -462,7 +469,7 @@ function _jac2jacTH_TLC(::Type{S}, mn, α, β, γ, δ, d) where {S}
462469
elseif α == γ
463470
@assert abs(β-δ) < 1
464471
jk = 0:n-1
465-
DL = (2jk .+ δ .+ α .+ 1).*Λ.(jk,δ+α+1,α+1)
472+
DL = _jac2jac_DL(jk,δ+α+1,α+1)
466473
h = Λ.(0:2n-2,α+β+1,δ+α+2)
467474
DR = Λ.(jk,α+1,α+β+1)./gamma(β-δ)
468475
t = alternatesign!(convert(AbstractVector{S}, Λ.(jk,β-δ,1)))

‎test/toeplitzhankeltests.jl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Random.seed!(0)
3939
@test th_jac2cheb(x, 0.2, 0.3) ≈ jac2cheb(x, 0.2, 0.3)
4040
@test th_cheb2jac(x, 1, 1) ≈ cheb2jac(x, 1, 1)
4141
@test th_jac2cheb(x, 1, 1) ≈ jac2cheb(x, 1, 1)
42+
# intermediate conversions hit γ+β+1 == 0
43+
@test th_jac2cheb(x, -0.25, -0.25) ≈ jac2cheb(x, -0.25, -0.25)
44+
@test th_jac2cheb(x, -0.4, -0.1) ≈ jac2cheb(x, -0.4, -0.1)
45+
@test th_jac2jac(x, -0.25, -0.25, 0.5, 0.5) ≈ lib_jac2jac(x, -0.25, -0.25, 0.5, 0.5)
4246

4347
@test th_cheb2leg(th_leg2cheb(x)) ≈ x
4448
@test th_leg2cheb(th_cheb2leg(x)) ≈ x

0 commit comments

Comments
 (0)