Skip to content

Commit 50c9d08

Browse files
authored
expand support for broadcastbasis with Jacobi and Ultraspherical OPs (#271)
* expand support for broadcastbasis with Jacobi and Ultraspherical OPs * fix default broadcastbasis * Update legendre.jl * Update test_jacobi.jl
1 parent 0ab71e9 commit 50c9d08

8 files changed

Lines changed: 39 additions & 6 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 = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
3-
version = "0.15.17"
3+
version = "0.15.18"
44
authors = ["Sheehan Olver <solver@mac.com>"]
55

66
[deps]

src/classical/chebyshev.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,6 @@ end
327327
# algebra
328328
####
329329

330-
broadcastbasis(::typeof(+), ::ChebyshevT, U::ChebyshevU) = U
331-
broadcastbasis(::typeof(+), U::ChebyshevU, ::ChebyshevT) = U
330+
broadcastbasis(::typeof(+), ::Chebyshev{kind,T}, ::Chebyshev{kind,V}) where {kind,T,V} = Chebyshev{kind,promote_type(T,V)}()
331+
broadcastbasis(::typeof(+), ::ChebyshevT{T}, ::ChebyshevU{V}) where {T,V} = ChebyshevU{promote_type(T,V)}()
332+
broadcastbasis(::typeof(+), ::ChebyshevU{T}, ::ChebyshevT{V}) where {T,V} = ChebyshevU{promote_type(T,V)}()

src/classical/jacobi.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ Jacobi{T}(a::V, b::V) where {T,V} = Jacobi{T,V}(a, b)
159159
Jacobi{T}(a, b) where T = Jacobi{T}(promote(a,b)...)
160160
Jacobi(a::V, b::T) where {T,V} = Jacobi{float(promote_type(T,V))}(a, b)
161161

162+
Jacobi(P::Jacobi) = P
163+
Jacobi{T}(P::Jacobi) where T = Jacobi{T}(P.a, P.b)
164+
162165
AbstractQuasiArray{T}(w::Jacobi) where T = Jacobi{T}(w.a, w.b)
163166
AbstractQuasiMatrix{T}(w::Jacobi) where T = Jacobi{T}(w.a, w.b)
164167

@@ -464,6 +467,8 @@ function \(w_A::WeightedJacobi, B::AbstractJacobi)
464467
end
465468

466469

470+
broadcastbasis(::typeof(+), A::AbstractJacobi, B::AbstractJacobi) = Jacobi(max(Jacobi(A).a,Jacobi(B).a), max(Jacobi(A).b,Jacobi(B).b))
471+
467472
function broadcastbasis(::typeof(+), w_A::WeightedJacobi, w_B::WeightedJacobi)
468473
wA,A = w_A.args
469474
wB,B = w_B.args

src/classical/legendre.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,6 @@ function _sum(P::Legendre{T}, dims::Int) where T
263263
end
264264

265265
_sum(p::SubQuasiArray{T,1,Legendre{T},<:Tuple{Inclusion,Int}}, ::Colon) where T = parentindices(p)[2] == 1 ? convert(T, 2) : zero(T)
266+
267+
268+
broadcastbasis(::typeof(+), ::Legendre{T}, ::Legendre{V}) where {T,V} = Legendre{promote_type(T,V)}()

src/classical/ultraspherical.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ end
234234

235235

236236

237-
function \(U::Ultraspherical{<:Any,<:Integer}, C::ChebyshevT)
237+
function \(U::Ultraspherical, C::ChebyshevT)
238238
T = promote_type(eltype(U), eltype(C))
239239
(U\Ultraspherical{T}(1)) * (ChebyshevU{T}()\C)
240240
end
241241

242-
function \(U::Ultraspherical{<:Any,<:Integer}, C::ChebyshevU)
242+
function \(U::Ultraspherical, C::ChebyshevU)
243243
T = promote_type(eltype(U), eltype(C))
244244
U\Ultraspherical(C)
245245
end
@@ -326,3 +326,10 @@ end
326326
\(A::Ultraspherical, w_B::WeightedUltraspherical) = (UltrasphericalWeight(one(A.λ)/2) .* A) \ w_B
327327
\(A::Legendre, wB::WeightedUltraspherical) = Ultraspherical(A) \ wB
328328

329+
330+
331+
broadcastbasis(::typeof(+), A::Ultraspherical{T}, B::Ultraspherical{V}) where {T,V} = Ultraspherical{promote_type(T,V)}(max(A.λ,B.λ))
332+
broadcastbasis(::typeof(+), A::ChebyshevT, B::Ultraspherical) = Ultraspherical(max(zero(real(eltype(A))),B.λ)) # we assume B.λ > 0
333+
broadcastbasis(::typeof(+), A::Ultraspherical, B::ChebyshevT) = Ultraspherical(max(A.λ,zero(real(eltype(B))))) # we assume A.λ > 0
334+
broadcastbasis(::typeof(+), A::Legendre, B::Ultraspherical) = Ultraspherical(max(-one(real(eltype(A)))/2,B.λ))
335+
broadcastbasis(::typeof(+), A::Ultraspherical, B::Legendre) = Ultraspherical(max(A.λ,-one(real(eltype(B)))/2))

test/test_chebyshev.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ import BandedMatrices: isbanded
602602
@test W \ (a .* W) isa Clenshaw
603603
@test (a .* W)[0.1,1:5] a[0.1] * W[0.1,1:5]
604604
end
605+
606+
@testset "broadcastbasis" begin
607+
@test (expand(ChebyshevT(), exp) + expand(ChebyshevU(), cos))[0.1] exp(0.1)+cos(0.1)
608+
end
605609
end
606610

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

test/test_jacobi.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
2828
@test Jacobi(1,2) .* Legendre() == Jacobi(1,2) .* Jacobi(0,0)
2929

3030
J = Jacobi(1,2)
31-
@test AbstractQuasiArray{Float32}(J) AbstractQuasiMatrix{Float32}(J) Jacobi{Float32}(1,2)
31+
@test AbstractQuasiArray{Float32}(J) AbstractQuasiMatrix{Float32}(J) Jacobi{Float32}(1,2) Jacobi{Float32}(J)
3232
end
3333

3434
@testset "basis" begin
@@ -561,4 +561,11 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
561561
@testset "ChebyshevInterval constructior" begin
562562
@test jacobi(1,2,ChebyshevInterval()) Jacobi(1,2)
563563
end
564+
565+
@testset "broadcastbasis" begin
566+
@test (expand(Jacobi(1,2), exp) + expand(Jacobi(2,1),cos))[0.1] exp(0.1)+cos(0.1)
567+
@test (expand(Legendre(), exp) + expand(Jacobi(2,1),cos))[0.1] exp(0.1)+cos(0.1)
568+
@test (expand(ChebyshevT(), exp) + expand(Jacobi(3/2,1/2),cos))[0.1] exp(0.1)+cos(0.1)
569+
@test (expand(Ultraspherical(2), exp) + expand(Jacobi(3/2,1/2),cos))[0.1] exp(0.1)+cos(0.1)
570+
end
564571
end

test/test_ultraspherical.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,10 @@ using ClassicalOrthogonalPolynomials: grammatrix
227227
op = (s .+ im) .* T
228228
@test (C \ op)[1,1] 0.5 + im
229229
end
230+
231+
@testset "broadcastbasis" begin
232+
@test (expand(Ultraspherical(1), exp) + expand(Ultraspherical(2),cos))[0.1] exp(0.1)+cos(0.1)
233+
@test (expand(Legendre(), exp) + expand(Ultraspherical(3/2), cos))[0.1] (expand(Ultraspherical(3/2), exp) + expand(Legendre(), cos))[0.1] exp(0.1)+cos(0.1)
234+
@test (expand(ChebyshevT(), exp) + expand(Ultraspherical(2), cos))[0.1] (expand(Ultraspherical(2), exp) + expand(ChebyshevT(), cos))[0.1] exp(0.1)+cos(0.1)
235+
end
230236
end

0 commit comments

Comments
 (0)