Skip to content

Commit f3c2c8b

Browse files
committed
JacobiWeight template
1 parent fd57a2b commit f3c2c8b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclu
3434

3535
import InfiniteArrays: OneToInf, InfAxes, Infinity, AbstractInfUnitRange, InfiniteCardinal, InfRanges
3636
import InfiniteLinearAlgebra: chop!, chop, pad, choplength, compatible_resize!, partialcholesky!
37-
import ContinuumArrays: Basis, Weight, basis_axes, @simplify, Identity, AbstractAffineQuasiVector, ProjectionFactorization,
37+
import ContinuumArrays: Basis, Weight, basis_axes, @simplify, AbstractAffineQuasiVector, ProjectionFactorization,
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,
@@ -90,6 +90,8 @@ represents an OP multiplied by its orthogonality weight.
9090
"""
9191
struct WeightedOPLayout{Lay<:AbstractOPLayout} <: AbstractWeightedBasisLayout end
9292

93+
grid_layout(::WeightedOPLayout, P, n) = grid(unweighted(P), n)
94+
9395
isorthogonalityweighted(::WeightedOPLayout, _) = true
9496
function isorthogonalityweighted(::AbstractWeightedBasisLayout, wS)
9597
w,S = arguments(wS)
@@ -246,7 +248,7 @@ grammatrix_layout(::WeightedOPLayout{MappedOPLayout}, P) = grammatrix_layout(Map
246248

247249
OrthogonalPolynomial(w::Weight) =error("Override for $(typeof(w))")
248250

249-
@simplify *(B::Identity, C::OrthogonalPolynomial) = ApplyQuasiMatrix(*, C, jacobimatrix(C))
251+
@simplify *(B::QuasiDiagonal{<:Any,<:Inclusion}, C::OrthogonalPolynomial) = ApplyQuasiMatrix(*, C, jacobimatrix(C))
250252

251253
function layout_broadcasted(::Tuple{PolynomialLayout,AbstractOPLayout}, ::typeof(*), x::Inclusion, C)
252254
x == axes(C,1) || throw(DimensionMismatch())

src/classical/jacobi.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ julia> axes(J)
3838
(Inclusion(-1.0 .. 1.0 (Chebyshev)),)
3939
```
4040
"""
41-
struct JacobiWeight{T} <: AbstractJacobiWeight{T}
42-
a::T
43-
b::T
44-
JacobiWeight{T}(a, b) where T = new{T}(convert(T,a), convert(T,b))
41+
struct JacobiWeight{T,V} <: AbstractJacobiWeight{T}
42+
a::V
43+
b::V
44+
JacobiWeight{T,V}(a, b) where {T,V} = new{T,V}(convert(V,a), convert(V,b))
4545
end
4646

47-
JacobiWeight(a::V, b::T) where {T,V} = JacobiWeight{promote_type(T,V)}(a,b)
47+
JacobiWeight{T}(a::V, b::V) where {T,V} = JacobiWeight{T,V}(a, b)
48+
JacobiWeight{T}(a, b) where T = JacobiWeight{T}(promote(a,b)...)
49+
JacobiWeight(a::V, b::T) where {T,V} = JacobiWeight{float(promote_type(T,V))}(a, b)
50+
4851

4952
"""
5053
jacobiweight(a,b, d::AbstractInterval)
@@ -71,9 +74,9 @@ AbstractQuasiVector{T}(w::JacobiWeight) where T = JacobiWeight{T}(w.a, w.b)
7174

7275
==(A::JacobiWeight, B::JacobiWeight) = A.b == B.b && A.a == B.a
7376

74-
function getindex(w::JacobiWeight, x::Number)
77+
function getindex(w::JacobiWeight{T}, x::Number) where T
7578
x axes(w,1) || throw(BoundsError())
76-
(1-x)^w.a * (1+x)^w.b
79+
convert(T, (1-x)^w.a * (1+x)^w.b)
7780
end
7881

7982
show(io::IO, P::JacobiWeight) = summary(io, P)
@@ -479,6 +482,8 @@ end
479482
broadcastbasis(::typeof(+), w_A::Weighted{<:Any,<:Jacobi}, w_B::Weighted{<:Any,<:Jacobi}) = broadcastbasis(+, convert(WeightedBasis,w_A), convert(WeightedBasis,w_B))
480483
broadcastbasis(::typeof(+), w_A::Weighted{<:Any,<:Jacobi}, w_B::WeightedJacobi) = broadcastbasis(+, convert(WeightedBasis,w_A), w_B)
481484
broadcastbasis(::typeof(+), w_A::WeightedJacobi, w_B::Weighted{<:Any,<:Jacobi}) = broadcastbasis(+, w_A, convert(WeightedBasis,w_B))
485+
broadcastbasis(::typeof(+), A::Jacobi, B::Weighted{<:Any,<:Jacobi}) = A # assume B can be lowered to Legendre... for now
486+
broadcastbasis(::typeof(+), A::Weighted{<:Any,<:Jacobi}, B::Jacobi) = B # assume B can be lowered to Legendre... for now
482487

483488
function \(w_A::WeightedJacobi, w_B::WeightedJacobi)
484489
wA,A = w_A.args

0 commit comments

Comments
 (0)