Skip to content

Commit 06d0ef6

Browse files
committed
add OP syntax
1 parent 24d73c0 commit 06d0ef6

10 files changed

+68
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2424

2525
[compat]
2626
ArrayLayouts = "0.5.3"
27-
BandedMatrices = "0.16.1"
27+
BandedMatrices = "0.16.2"
2828
BlockArrays = "0.14.1"
2929
BlockBandedMatrices = "0.10"
3030
ContinuumArrays = "0.5"

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@ A Julia package for classical orthogonal polynomials and expansions
55
[![codecov](https://codecov.io/gh/JuliaApproximation/ClassicalOrthogonalPolynomials.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/ClassicalOrthogonalPolynomials.jl)
66

77

8-
This package implements classical orthogonal polynomials as quasi-arrays where one one axes is continuous and the other axis is discrete (countably infinite), as implemented in [QuasiArrays.jl](https://github.com/JuliaApproximation/QuasiArrays.jl) and [ContinuumArrays.jl](https://github.com/JuliaApproximation/ContinuumArrays.jl).
8+
This package implements classical orthogonal polynomials.
99
```julia
1010
julia> using ClassicalOrthogonalPolynomials, ContinuumArrays
1111

12+
julia> chebyshevt.(0:5,0.1)
13+
6-element Array{Float64,1}:
14+
1.0
15+
0.1
16+
-0.98
17+
-0.296
18+
0.9208
19+
0.48016
20+
```
21+
Other examples include `chebyshevu`, `legendrep`, `jacobip`, and `ultrasphericalp`.
22+
23+
For expansion, it supports usafe as quasi-arrays where one one axes is continuous and the other axis is discrete (countably infinite), as implemented in [QuasiArrays.jl](https://github.com/JuliaApproximation/QuasiArrays.jl) and [ContinuumArrays.jl](https://github.com/JuliaApproximation/ContinuumArrays.jl).
24+
```julia
1225
julia> P = Legendre(); # Legendre polynomials
1326

1427
julia> size(P) # uncountable ∞ x countable ∞

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import BandedMatrices: bandwidths
3838
export OrthogonalPolynomial, Normalized, orthonormalpolynomial, LanczosPolynomial, Hermite, Jacobi, Legendre, Chebyshev, ChebyshevT, ChebyshevU, ChebyshevInterval, Ultraspherical, Fourier,
3939
HermiteWeight, JacobiWeight, ChebyshevWeight, ChebyshevGrid, ChebyshevTWeight, ChebyshevUWeight, UltrasphericalWeight, LegendreWeight,
4040
WeightedUltraspherical, WeightedChebyshev, WeightedChebyshevT, WeightedChebyshevU, WeightedJacobi,
41-
∞, Derivative, .., Inclusion, chebyshevt, chebyshevu, legendre, jacobi, jacobimatrix, jacobiweight, legendreweight, chebyshevtweight, chebyshevuweight
41+
∞, Derivative, .., Inclusion, chebyshevt, chebyshevu, legendre, jacobi, legendrep, jacobip, jacobimatrix, jacobiweight, legendreweight, chebyshevtweight, chebyshevuweight
4242

4343

4444
include("interlace.jl")

src/chebyshev.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ chebyshevt(d::AbstractInterval{T}) where T = ChebyshevT{float(T)}()[affine(d, Ch
4444
chebyshevu() = ChebyshevU()
4545
chebyshevu(d::AbstractInterval{T}) where T = ChebyshevU{float(T)}()[affine(d, ChebyshevInterval{T}()), :]
4646

47+
"""
48+
chebyshevt(n, z)
49+
50+
computes the `n`-th Chebyshev polynomial of the first kind at `z`.
51+
"""
52+
chebyshevt(n::Integer, z::Number) = Base.unsafe_getindex(ChebyshevT{typeof(z)}(), z, n+1)
53+
"""
54+
chebyshevt(n, z)
55+
56+
computes the `n`-th Chebyshev polynomial of the second kind at `z`.
57+
"""
58+
chebyshevu(n::Integer, z::Number) = Base.unsafe_getindex(ChebyshevU{typeof(z)}(), z, n+1)
59+
4760
chebysevtweight(d::AbstractInterval{T}) where T = ChebyshevTWeight{float(T)}[affine(d,ChebyshevInterval{T}())]
4861
chebysevuweight(d::AbstractInterval{T}) where T = ChebyshevUWeight{float(T)}[affine(d,ChebyshevInterval{T}())]
4962

src/jacobi.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ Legendre() = Legendre{Float64}()
9393
legendre() = Legendre()
9494
legendre(d::AbstractInterval{T}) where T = Legendre{float(T)}()[affine(d,ChebyshevInterval{T}()), :]
9595

96+
"""
97+
legendrep(n, z)
98+
99+
computes the `n`-th Legendre polynomial at `z`.
100+
"""
101+
legendrep(n::Integer, z::Number) = Base.unsafe_getindex(Legendre{typeof(z)}(), z, n+1)
102+
103+
96104
==(::Legendre, ::Legendre) = true
97105

98106
OrthogonalPolynomial(w::LegendreWeight{T}) where {T} = Legendre{T}()
@@ -116,6 +124,14 @@ jacobi(a,b, d::AbstractInterval{T}) where T = Jacobi(a,b)[affine(d,ChebyshevInte
116124

117125
Jacobi(P::Legendre{T}) where T = Jacobi(zero(T), zero(T))
118126

127+
"""
128+
jacobip(n, a, b, z)
129+
130+
computes the `n`-th Jacobi polynomial, orthogonal with
131+
respec to `(1-x)^a*(1+x)^b`, at `z`.
132+
"""
133+
jacobip(n::Integer, a, b, z::Number) = Base.unsafe_getindex(Jacobi{promote_type(typeof(a), typeof(b), typeof(z))}(a,b), z, n+1)
134+
119135
OrthogonalPolynomial(w::JacobiWeight) = Jacobi(w.a, w.b)
120136
orthogonalityweight(P::Jacobi) = JacobiWeight(P.a, P.b)
121137

src/ultraspherical.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ WeightedUltraspherical(λ) = UltrasphericalWeight(λ) .* Ultraspherical(λ)
4040
WeightedUltraspherical{T}(λ) where T = UltrasphericalWeight{T}(λ) .* Ultraspherical{T}(λ)
4141

4242

43+
ultrasphericalp(n::Integer, λ, z::Number) = Base.unsafe_getindex(Ultraspherical{promote_type(typeof(λ),typeof(z))}(λ), z, n+1
44+
4345
==(a::Ultraspherical, b::Ultraspherical) = a.λ == b.λ
4446
==(::Ultraspherical, ::ChebyshevT) = false
4547
==(::ChebyshevT, ::Ultraspherical) = false

test/test_chebyshev.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map
319319
@test Base.BroadcastStyle(typeof(v)) isa LazyArrays.LazyArrayStyle{1}
320320
@test (v./v)[1:10] == ones(10)
321321
end
322+
323+
@testset "special syntax" begin
324+
@test chebyshevt.(0:5, 0.1) == ChebyshevT()[0.1, 1:6]
325+
@test chebyshevt.(0:5, BigFloat(1)/10) == ChebyshevT{BigFloat}()[BigFloat(1)/10, 1:6]
326+
@test chebyshevt.(0:5, 2) == Base.unsafe_getindex(ChebyshevT(), 2, 1:6)
327+
328+
@test chebyshevu.(0:5, 0.1) == ChebyshevU()[0.1, 1:6]
329+
@test chebyshevu.(0:5, BigFloat(1)/10) == ChebyshevU{BigFloat}()[BigFloat(1)/10, 1:6]
330+
@test chebyshevu.(0:5, 2) == Base.unsafe_getindex(ChebyshevU(), 2, 1:6)
331+
end
322332
end
323333

324334
struct QuadraticMap{T} <: Map{T} end

test/test_jacobi.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,8 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
338338
@test (x-y) * P[x,1:n]'Mi[1:n,1:n]*Base.unsafe_getindex(P,y,1:n) P[x,n:n+1]' * [0 -β; β 0] * Base.unsafe_getindex(P,y,n:n+1)
339339
end
340340
end
341+
342+
@testset "special syntax" begin
343+
@test jacobip.(0:5, 0.1, 0.2, 0.3) == Jacobi(0.1, 0.2)[0.3, 1:6]
344+
end
341345
end

test/test_legendre.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,8 @@ import QuasiArrays: MulQuasiArray
129129
β = X[n,n+1]*Mi[n+1,n+1]
130130
@test (x-y) * P[x,1:n]'Mi[1:n,1:n]*P[y,1:n] P[x,n:n+1]' * [0 -β; β 0] * P[y,n:n+1]
131131
end
132+
133+
@testset "special syntax" begin
134+
@test legendrep.(0:5, 0.3) == Legendre()[0.3, 1:6]
135+
end
132136
end

test/test_ultraspherical.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ using ClassicalOrthogonalPolynomials, BandedMatrices, LazyArrays, Test
8282
@test @inferred(C[0.1,Base.OneTo(3)]) == [1.0,0.4,-1.88]
8383
end
8484

85+
@testset "special syntax" begin
86+
@test ultrasphericalp.(0:5, 2, 0.3) == Ultraspherical(2)[0.3, 1:6]
87+
end
8588
end

0 commit comments

Comments
 (0)