Skip to content

Commit b69d13f

Browse files
authored
cumsum for Weighted(ChebyshevT()) (#170)
1 parent d3d03ef commit b69d13f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import ContinuumArrays: Basis, Weight, basis_axes, @simplify, Identity, Abstract
3838
grid, plotgrid, plotgrid_layout, plotvalues_layout, grid_layout, transform_ldiv, TransformFactorization, QInfAxes, broadcastbasis, ExpansionLayout, basismap,
3939
AffineQuasiVector, AffineMap, AbstractWeightLayout, AbstractWeightedBasisLayout, WeightedBasisLayout, WeightedBasisLayouts, demap, AbstractBasisLayout, BasisLayout,
4040
checkpoints, weight, unweighted, MappedBasisLayouts, sum_layout, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, broadcastbasis_layout,
41-
plan_grid_transform, plan_transform, MAX_PLOT_POINTS, MulPlan, grammatrix, AdjointBasisLayout, grammatrix_layout, plan_transform_layout
41+
plan_grid_transform, plan_transform, MAX_PLOT_POINTS, MulPlan, grammatrix, AdjointBasisLayout, grammatrix_layout, plan_transform_layout, _cumsum
4242
import FastTransforms: Λ, forwardrecurrence, forwardrecurrence!, _forwardrecurrence!, clenshaw, clenshaw!,
4343
_forwardrecurrence_next, _clenshaw_next, check_clenshaw_recurrences, ChebyshevGrid, chebyshevpoints, Plan, ScaledPlan, th_cheb2leg
4444

src/classical/chebyshev.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ function getindex(w::ChebyshevUWeight, x::Number)
9696
sqrt(1-x^2)
9797
end
9898

99-
sum(::ChebyshevWeight{1,T}) where T = convert(T,π)
100-
sum(::ChebyshevWeight{2,T}) where T = convert(T,π)/2
99+
sum(::ChebyshevTWeight{T}) where T = convert(T,π)
100+
sum(::ChebyshevUWeight{T}) where T = convert(T,π)/2
101+
102+
function _cumsum(w::ChebyshevTWeight{V}, dims) where V
103+
@assert dims == 1
104+
x = axes(w,1)
105+
(V(π)/2 .+ asin.(x))
106+
end
101107

102108
normalizationconstant(::ChebyshevT{T}) where T = Vcat(sqrt(inv(convert(T,π))), Fill(sqrt(2/convert(T,π)),∞))
103109

@@ -298,12 +304,17 @@ function _sum(::Weighted{T,<:Chebyshev}, dims) where T
298304
Hcat(convert(T, π), Zeros{T}(1,∞))
299305
end
300306

301-
function cumsum(T::ChebyshevT{V}; dims::Integer) where V
307+
function _cumsum(T::ChebyshevT{V}, dims) where V
302308
@assert dims == 1
303309
Σ = _BandedMatrix(Vcat(-one(V) ./ (-2:2:∞)', Zeros{V}(1,∞), Hcat(one(V), one(V) ./ (4:2:∞)')), ℵ₀, 0, 2)
304310
ApplyQuasiArray(*, T, Vcat((-1).^(0:∞)'* Σ, Σ))
305311
end
306312

313+
function _cumsum(W::Weighted{V, ChebyshevT{V}}, dims) where V
314+
@assert dims == 1
315+
[cumsum(ChebyshevTWeight{V}()) Weighted(ChebyshevU{V}())] * Diagonal(Vcat(one(V), -inv.(one(V):∞)))
316+
end
317+
307318
####
308319
# algebra
309320
####

test/test_chebyshev.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ import BandedMatrices: isbanded
390390
@test (T \ cumsum(T; dims=1)) * (T \ exp.(x)) T \ (exp.(x) .- exp(-1))
391391
f = T * (T \ exp.(x))
392392
@test T \ cumsum(f) T \ (exp.(x) .- exp(-1))
393+
394+
f = expand(Weighted(T), x -> exp(x)/sqrt(1-x^2))
395+
@test cumsum(f)[0.1] 0.9784356617497387
393396
end
394397

395398
@testset "algebra" begin

0 commit comments

Comments
 (0)