Skip to content

Commit aaa182b

Browse files
authored
Derivative -> diff (#144)
* Derivative -> diff * Derivative -> diff * mapped Weighted diff * Use grammatrix * normalized diff * Update jacobi.jl * Lanczos mul * Update interlace.jl * Mapped weightedgrammatrix * Add test from SingularIntegrals.jl * fixes * Update ultraspherical.jl * Update ClassicalOrthogonalPolynomials.jl * increase coverage * Update test_legendre.jl * Update legendre.jl
1 parent 02fbe50 commit aaa182b

22 files changed

+245
-192
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.10.1"
4+
version = "0.11"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -29,7 +29,7 @@ ArrayLayouts = "1.0.1"
2929
BandedMatrices = "0.17.17"
3030
BlockArrays = "0.16.9"
3131
BlockBandedMatrices = "0.12"
32-
ContinuumArrays = "0.13"
32+
ContinuumArrays = "0.14"
3333
DomainSets = "0.6"
3434
FFTW = "1.1"
3535
FastGaussQuadrature = "0.5"
@@ -41,7 +41,7 @@ InfiniteLinearAlgebra = "0.6.16"
4141
IntervalSets = "0.7"
4242
LazyArrays = "1.0.1"
4343
LazyBandedMatrices = "0.8.5"
44-
QuasiArrays = "0.10"
44+
QuasiArrays = "0.11"
4545
SpecialFunctions = "1.0, 2"
4646
julia = "1.9"
4747

examples/idealfluidflow.jl

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Base: @_inline_meta, axes, getindex, unsafe_getindex, convert, prod, *, /
1111
IndexStyle, IndexLinear, ==, OneTo, tail, similar, copyto!, copy, setindex,
1212
first, last, Slice, size, length, axes, IdentityUnitRange, sum, _sum, cumsum,
1313
to_indices, tail, getproperty, inv, show, isapprox, summary,
14-
findall, searchsortedfirst
14+
findall, searchsortedfirst, diff
1515
import Base.Broadcast: materialize, BroadcastStyle, broadcasted, Broadcasted
1616
import LazyArrays: MemoryLayout, Applied, ApplyStyle, flatten, _flatten, adjointlayout,
1717
sub_materialize, arguments, sub_paddeddata, paddeddata, PaddedLayout, resizedata!, LazyVector, ApplyLayout, call,
@@ -30,15 +30,15 @@ import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclu
3030
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle,
3131
LazyQuasiArray, LazyQuasiVector, LazyQuasiMatrix, LazyLayout, LazyQuasiArrayStyle,
3232
_getindex, layout_getindex, _factorize, AbstractQuasiArray, AbstractQuasiMatrix, AbstractQuasiVector,
33-
AbstractQuasiFill, _dot, _equals, QuasiArrayLayout, PolynomialLayout
33+
AbstractQuasiFill, _equals, QuasiArrayLayout, PolynomialLayout, diff_layout
3434

3535
import InfiniteArrays: OneToInf, InfAxes, Infinity, AbstractInfUnitRange, InfiniteCardinal, InfRanges
3636
import InfiniteLinearAlgebra: chop!, chop, pad, choplength, compatible_resize!
3737
import ContinuumArrays: Basis, Weight, basis_axes, @simplify, Identity, AbstractAffineQuasiVector, ProjectionFactorization,
3838
grid, plotgrid, _plotgrid, _grid, transform_ldiv, TransformFactorization, QInfAxes, broadcastbasis, ExpansionLayout, basismap,
39-
AffineQuasiVector, AffineMap, WeightLayout, AbstractWeightedBasisLayout, WeightedBasisLayout, WeightedBasisLayouts, demap, AbstractBasisLayout, BasisLayout,
39+
AffineQuasiVector, AffineMap, AbstractWeightLayout, AbstractWeightedBasisLayout, WeightedBasisLayout, WeightedBasisLayouts, demap, AbstractBasisLayout, BasisLayout,
4040
checkpoints, weight, unweighted, MappedBasisLayouts, sum_layout, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, _broadcastbasis,
41-
plan_transform, plan_grid_transform, MAX_PLOT_POINTS, MulPlan
41+
plan_transform, plan_grid_transform, MAX_PLOT_POINTS, MulPlan, grammatrix, AdjointBasisLayout, grammatrix_layout
4242
import FastTransforms: Λ, forwardrecurrence, forwardrecurrence!, _forwardrecurrence!, clenshaw, clenshaw!,
4343
_forwardrecurrence_next, _clenshaw_next, check_clenshaw_recurrences, ChebyshevGrid, chebyshevpoints, Plan, ScaledPlan, th_cheb2leg
4444

@@ -160,7 +160,7 @@ end
160160
gives the singularity structure of an expansion, e.g.,
161161
`JacobiWeight`.
162162
"""
163-
singularities(::WeightLayout, w) = w
163+
singularities(::AbstractWeightLayout, w) = w
164164
singularities(lay::BroadcastLayout, a::AbstractQuasiVector) = singularitiesbroadcast(call(a), map(singularities, arguments(lay, a))...)
165165
singularities(::WeightedBasisLayouts, a) = singularities(BroadcastLayout{typeof(*)}(), a)
166166
singularities(::WeightedOPLayout, a) = singularities(weight(a))
@@ -182,17 +182,22 @@ singularities(r::Base.RefValue) = r[] # pass through
182182
orthogonalityweight(P::SubQuasiArray{<:Any,2,<:Any,<:Tuple{AbstractAffineQuasiVector,Slice}}) =
183183
orthogonalityweight(parent(P))[parentindices(P)[1]]
184184

185-
function massmatrix(P::SubQuasiArray{<:Any,2,<:Any,<:Tuple{AbstractAffineQuasiVector,Slice}})
185+
186+
weighted(P::AbstractQuasiMatrix) = Weighted(P)
187+
188+
weightedgrammatrix(P) = weightedgrammatrix_layout(MemoryLayout(P), P)
189+
function weightedgrammatrix_layout(::MappedOPLayout, P)
186190
Q = parent(P)
187191
kr,jr = parentindices(P)
188-
massmatrix(Q)/kr.A
192+
@assert kr isa AbstractAffineQuasiVector
193+
weightedgrammatrix(Q)/kr.A
189194
end
190195

191-
weighted(P::AbstractQuasiMatrix) = Weighted(P)
196+
grammatrix_layout(::MappedOPLayout, P) = grammatrix_layout(MappedBasisLayout(), P)
192197

193198
OrthogonalPolynomial(w::Weight) =error("Override for $(typeof(w))")
194199

195-
@simplify *(B::Identity, C::OrthogonalPolynomial) = C*jacobimatrix(C)
200+
@simplify *(B::Identity, C::OrthogonalPolynomial) = ApplyQuasiMatrix(*, C, jacobimatrix(C))
196201

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

src/classical/chebyshev.jl

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ struct ChebyshevWeight{kind,T} <: AbstractJacobiWeight{T} end
99
ChebyshevWeight{kind}() where kind = ChebyshevWeight{kind,Float64}()
1010
ChebyshevWeight() = ChebyshevWeight{1,Float64}()
1111

12+
AbstractQuasiArray{T}(::ChebyshevWeight{kind}) where {T,kind} = ChebyshevWeight{kind,T}()
13+
AbstractQuasiVector{T}(::ChebyshevWeight{kind}) where {T,kind} = ChebyshevWeight{kind,T}()
14+
15+
1216
getproperty(w::ChebyshevWeight{1,T}, ::Symbol) where T = -one(T)/2
1317
getproperty(w::ChebyshevWeight{2,T}, ::Symbol) where T = one(T)/2
1418

@@ -29,6 +33,8 @@ const ChebyshevUWeight = ChebyshevWeight{2}
2933
const ChebyshevT = Chebyshev{1}
3034
const ChebyshevU = Chebyshev{2}
3135

36+
show(io::IO, P::ChebyshevTWeight{Float64}) = summary(io, P)
37+
show(io::IO, P::ChebyshevUWeight{Float64}) = summary(io, P)
3238
summary(io::IO, ::ChebyshevTWeight{Float64}) = print(io, "ChebyshevTWeight()")
3339
summary(io::IO, ::ChebyshevUWeight{Float64}) = print(io, "ChebyshevUWeight()")
3440

@@ -71,6 +77,9 @@ chebysevuweight(d::AbstractInterval{T}) where T = ChebyshevUWeight{float(T)}[aff
7177
==(::Chebyshev, ::Legendre) = false
7278
==(::Legendre, ::Chebyshev) = false
7379

80+
show(io::IO, w::ChebyshevT{Float64}) = summary(io, w)
81+
show(io::IO, w::ChebyshevU{Float64}) = summary(io, w)
82+
7483
summary(io::IO, w::ChebyshevT{Float64}) = print(io, "ChebyshevT()")
7584
summary(io::IO, w::ChebyshevU{Float64}) = print(io, "ChebyshevU()")
7685

@@ -143,28 +152,30 @@ recurrencecoefficients(C::ChebyshevU) = (Fill(2,∞), Zeros{Int}(∞), Ones{Int}
143152
# Mass matrix
144153
###
145154

146-
massmatrix(::ChebyshevT{V}) where V = Diagonal([convert(V,π); Fill(convert(V,π)/2,∞)])
147-
massmatrix(::ChebyshevU{V}) where V = Diagonal(Fill(convert(V,π)/2,∞))
155+
weightedgrammatrix(::ChebyshevT{V}) where V = Diagonal([convert(V,π); Fill(convert(V,π)/2,∞)])
156+
weightedgrammatrix(::ChebyshevU{V}) where V = Diagonal(Fill(convert(V,π)/2,∞))
148157

149-
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:ChebyshevT}}, B::ChebyshevT) = massmatrix(ChebyshevT{promote_type(eltype(A),eltype(B))}())
150-
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:ChebyshevU}}, B::ChebyshevU) = massmatrix(ChebyshevU{promote_type(eltype(A),eltype(B))}())
158+
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:ChebyshevT}}, B::ChebyshevT) = weightedgrammatrix(ChebyshevT{promote_type(eltype(A),eltype(B))}())
159+
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:ChebyshevU}}, B::ChebyshevU) = weightedgrammatrix(ChebyshevU{promote_type(eltype(A),eltype(B))}())
151160

152-
@simplify function *(A::QuasiAdjoint{<:Any,<:ChebyshevT}, B::ChebyshevT)
153-
T = promote_type(eltype(A), eltype(B))
161+
function grammatrix(A::ChebyshevT{T}) where T
154162
f = (k,j) -> isodd(j-k) ? zero(T) : -(((1 + (-1)^(j + k))*(-1 + j^2 + k^2))/(j^4 + (-1 + k^2)^2 - 2j^2*(1 + k^2)))
155163
BroadcastMatrix{T}(f, 0:∞, (0:∞)')
156164
end
157165

166+
@simplify function *(A::QuasiAdjoint{<:Any,<:ChebyshevT}, B::ChebyshevT)
167+
T = promote_type(eltype(A), eltype(B))
168+
grammatrix(ChebyshevT{T}())
169+
end
170+
158171
@simplify function *(A::QuasiAdjoint{<:Any,<:ChebyshevT}, B::ChebyshevU)
159172
T = promote_type(eltype(A), eltype(B))
160173
f = (k,j) -> isodd(j-k) ? zero(T) : ((one(T) + (-1)^(j + k))*(1 + j))/((1 + j - k)*(1 + j + k))
161174
BroadcastMatrix{T}(f, 0:∞, (0:∞)')
162175
end
163176

164177

165-
166-
@simplify function *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:ChebyshevU}}, B::Weighted{<:Any,<:ChebyshevU})
167-
T = promote_type(eltype(A), eltype(B))
178+
function grammatrix(A::Weighted{T,<:ChebyshevU}) where T
168179
f = (k,j) -> isodd(j-k) ? zero(T) : -((2*(one(T) + (-1)^(j + k))*(1 + j)*(1 + k))/((-1 + j - k)*(1 + j - k)*(1 + j + k)*(3 + j + k)))
169180
BroadcastMatrix{T}(f, 0:∞, (0:∞)')
170181
end
@@ -183,15 +194,14 @@ end
183194
##########
184195

185196
# Ultraspherical(1)\(D*Chebyshev())
186-
@simplify function *(D::Derivative{<:Any,<:ChebyshevInterval}, S::ChebyshevT)
187-
T = promote_type(eltype(D),eltype(S))
188-
A = _BandedMatrix((zero(T):∞)', ℵ₀, -1,1)
189-
ApplyQuasiMatrix(*, ChebyshevU{T}(), A)
197+
function diff(S::ChebyshevT{T}; dims=1) where T
198+
D = _BandedMatrix((zero(T):∞)', ℵ₀, -1,1)
199+
ApplyQuasiMatrix(*, ChebyshevU{T}(), D)
190200
end
191201

192-
@simplify function *(D::Derivative{<:Any,<:ChebyshevInterval}, W::Weighted{<:Any,<:ChebyshevU})
193-
T = promote_type(eltype(D),eltype(W))
194-
Weighted(ChebyshevT{T}()) * _BandedMatrix((-one(T):-one(T):(-∞))', ℵ₀, 1,-1)
202+
function diff(W::Weighted{T,<:ChebyshevU}; dims=1) where T
203+
D = _BandedMatrix((-one(T):-one(T):(-∞))', ℵ₀, 1,-1)
204+
ApplyQuasiMatrix(*, Weighted(ChebyshevT{T}()), D)
195205
end
196206

197207

src/classical/fourier.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ end
147147
Diagonal(Fill(2convert(TV,π),(axes(B,2),)))
148148
end
149149

150-
@simplify function *(D::Derivative, F::Fourier)
151-
TV = promote_type(eltype(D),eltype(F))
152-
Fourier{TV}()*_BlockArray(Diagonal(Vcat([reshape([0.0],1,1)], (1.0:∞) .* Fill([0 -one(TV); one(TV) 0], ∞))), (axes(F,2),axes(F,2)))
150+
function diff(F::Fourier{T}; dims=1) where T
151+
D = _BlockArray(Diagonal(Vcat([reshape([zero(T)],1,1)], (one(T):∞) .* Fill([0 -one(T); one(T) 0], ∞))), (axes(F,2),axes(F,2)))
152+
F * D
153153
end
154154

155-
@simplify function *(D::Derivative, F::Laurent)
156-
TV = promote_type(eltype(D),eltype(F))
157-
Laurent{TV}() * Diagonal(PseudoBlockVector((((1:∞) 2) .* (1 .- 2 .* iseven.(1:∞))) * convert(TV,im), (axes(F,2),)))
155+
function diff(F::Laurent{T}; dims=1) where T
156+
D = Diagonal(PseudoBlockVector((((one(real(T)):∞) 2) .* (1 .- 2 .* iseven.(1:∞))) * convert(T,im), (axes(F,2),)))
157+
F * D
158158
end
159159

160160

src/classical/hermite.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ is a quasi-vector representing `exp(-x^2)` on ℝ.
66
struct HermiteWeight{T} <: Weight{T} end
77

88
HermiteWeight() = HermiteWeight{Float64}()
9+
10+
AbstractQuasiArray{T}(::HermiteWeight) where T = HermiteWeight{T}()
11+
AbstractQuasiVector{T}(::HermiteWeight) where T = HermiteWeight{T}()
12+
13+
914
axes(::HermiteWeight{T}) where T = (Inclusion{T}(ℝ),)
1015
==(::HermiteWeight, ::HermiteWeight) = true
1116

@@ -25,6 +30,11 @@ broadcasted(::typeof(sqrt), H::HermiteWeight{T}) where T = H .^ (one(T)/2)
2530

2631
struct Hermite{T} <: OrthogonalPolynomial{T} end
2732
Hermite() = Hermite{Float64}()
33+
34+
AbstractQuasiArray{T}(::Hermite) where T = Hermite{T}()
35+
AbstractQuasiMatrix{T}(::Hermite) where T = Hermite{T}()
36+
37+
2838
orthogonalityweight(::Hermite{T}) where T = HermiteWeight{T}()
2939

3040
==(::Hermite, ::Hermite) = true
@@ -46,27 +56,17 @@ broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), ::HermiteWeight{T}, ::Hermite
4656
jacobimatrix(H::Hermite{T}) where T = Tridiagonal(Fill(one(T)/2,∞), Zeros{T}(∞), one(T):∞)
4757
recurrencecoefficients(H::Hermite{T}) where T = Fill{T}(2,∞), Zeros{T}(∞), zero(T):2:
4858

49-
massmatrix(::Hermite{T}) where T = Diagonal(sqrt(convert(T,π)) .* convert(T,2) .^ (0:∞) .* gamma.(one(T):∞))
59+
weightedgrammatrix(::Hermite{T}) where T = Diagonal(sqrt(convert(T,π)) .* convert(T,2) .^ (0:∞) .* gamma.(one(T):∞))
5060

51-
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:Hermite}}, B::Hermite) = massmatrix(Hermite{promote_type(eltype(A),eltype(B))}())
61+
@simplify *(A::QuasiAdjoint{<:Any,<:Weighted{<:Any,<:Hermite}}, B::Hermite) = weightedgrammatrix(Hermite{promote_type(eltype(A),eltype(B))}())
5262

5363
##########
5464
# Derivatives
55-
##########
56-
57-
@simplify function *(D::Derivative, H::Hermite)
58-
T = promote_type(eltype(D),eltype(H))
59-
D = _BandedMatrix((zero(T):2:∞)', ℵ₀, -1,1)
60-
H*D
61-
end
62-
63-
@simplify function *(D::Derivative, W::Weighted{<:Any,<:Hermite})
64-
T = promote_type(eltype(D),eltype(W))
65-
D = _BandedMatrix(Fill(-one(T), 1, ∞), ℵ₀, 1,-1)
66-
W*D
67-
end
65+
#####
6866

69-
@simplify function *(D::Derivative, Q::OrthonormalWeighted{<:Any,<:Hermite})
67+
diff(H::Hermite{T}; dims=1) where T = ApplyQuasiMatrix(*, H, _BandedMatrix((zero(T):2:∞)', ℵ₀, -1,1))
68+
diff(W::Weighted{T,<:Hermite}; dims=1) where T = ApplyQuasiMatrix(*, W, _BandedMatrix(Fill(-one(T), 1, ∞), ℵ₀, 1,-1))
69+
function diff(Q::OrthonormalWeighted{<:Any,<:Hermite}; dims=1)
7070
X = jacobimatrix(Q.P)
71-
Q * Tridiagonal(-X.ev, X.dv, X.ev)
71+
ApplyQuasiMatrix(*, Q, Tridiagonal(-X.ev, X.dv, X.ev))
7272
end

0 commit comments

Comments
 (0)