diff --git a/Project.toml b/Project.toml index 49e94291..6b1c9edf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FastTransforms" uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c" -version = "0.17.2" +version = "0.17.3" [deps] diff --git a/src/toeplitzhankel.jl b/src/toeplitzhankel.jl index 49d44a70..82851112 100644 --- a/src/toeplitzhankel.jl +++ b/src/toeplitzhankel.jl @@ -447,13 +447,20 @@ function alternatesign!(v) v end +# (2k+λ)*Λ(k,λ,μ), using λ*Γ(λ) = Γ(λ+1) for k = 0 to avoid 0*Inf when λ = 0, e.g. when converting to Chebyshev +function _jac2jac_DL(jk, λ, μ) + DL = (2jk .+ λ).*Λ.(jk,λ,μ) + isempty(DL) || (DL[1] = Λ(0,λ+1,μ)) + DL +end + function _jac2jacTH_TLC(::Type{S}, mn, α, β, γ, δ, d) where {S} n = mn[d] @assert α+β > -1 if β == δ @assert abs(α-γ) < 1 jk = 0:n-1 - DL = (2jk .+ γ .+ β .+ 1).*Λ.(jk,γ+β+1,β+1) + DL = _jac2jac_DL(jk,γ+β+1,β+1) t = convert(AbstractVector{S}, Λ.(jk, α-γ,1)) h = Λ.(0:2n-2,α+β+1,γ+β+2) DR = Λ.(jk,β+1,α+β+1)./gamma(α-γ) @@ -462,7 +469,7 @@ function _jac2jacTH_TLC(::Type{S}, mn, α, β, γ, δ, d) where {S} elseif α == γ @assert abs(β-δ) < 1 jk = 0:n-1 - DL = (2jk .+ δ .+ α .+ 1).*Λ.(jk,δ+α+1,α+1) + DL = _jac2jac_DL(jk,δ+α+1,α+1) h = Λ.(0:2n-2,α+β+1,δ+α+2) DR = Λ.(jk,α+1,α+β+1)./gamma(β-δ) t = alternatesign!(convert(AbstractVector{S}, Λ.(jk,β-δ,1))) diff --git a/test/toeplitzhankeltests.jl b/test/toeplitzhankeltests.jl index f9a9029c..5e4589af 100644 --- a/test/toeplitzhankeltests.jl +++ b/test/toeplitzhankeltests.jl @@ -39,6 +39,10 @@ Random.seed!(0) @test th_jac2cheb(x, 0.2, 0.3) ≈ jac2cheb(x, 0.2, 0.3) @test th_cheb2jac(x, 1, 1) ≈ cheb2jac(x, 1, 1) @test th_jac2cheb(x, 1, 1) ≈ jac2cheb(x, 1, 1) + # intermediate conversions hit γ+β+1 == 0 + @test th_jac2cheb(x, -0.25, -0.25) ≈ jac2cheb(x, -0.25, -0.25) + @test th_jac2cheb(x, -0.4, -0.1) ≈ jac2cheb(x, -0.4, -0.1) + @test th_jac2jac(x, -0.25, -0.25, 0.5, 0.5) ≈ lib_jac2jac(x, -0.25, -0.25, 0.5, 0.5) @test th_cheb2leg(th_leg2cheb(x)) ≈ x @test th_leg2cheb(th_cheb2leg(x)) ≈ x