Skip to content

Commit e166c40

Browse files
authored
ContinuumArrays v0.15 (#149)
* ContinuumArrays v0.15 * equals_layout * Update test_chebyshev.jl * Update test_chebyshev.jl * Update test_chebyshev.jl
1 parent 43f10bc commit e166c40

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

Project.toml

Lines changed: 2 additions & 2 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.11.1"
4+
version = "0.11.2"
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.14"
32+
ContinuumArrays = "0.15"
3333
DomainSets = "0.6"
3434
FFTW = "1.1"
3535
FastGaussQuadrature = "0.5"

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ 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, _equals, QuasiArrayLayout, PolynomialLayout, diff_layout
33+
AbstractQuasiFill, equals_layout, 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,
38-
grid, plotgrid, _plotgrid, _grid, transform_ldiv, TransformFactorization, QInfAxes, broadcastbasis, ExpansionLayout, basismap,
38+
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,
40-
checkpoints, weight, unweighted, MappedBasisLayouts, sum_layout, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, _broadcastbasis,
40+
checkpoints, weight, unweighted, MappedBasisLayouts, sum_layout, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, broadcastbasis_layout,
4141
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
@@ -87,26 +87,26 @@ end
8787
isorthogonalityweighted(wS) = isorthogonalityweighted(MemoryLayout(wS), wS)
8888

8989

90-
_equals(::MappedOPLayout, ::MappedOPLayout, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
91-
_equals(::MappedOPLayout, ::MappedBasisLayouts, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
92-
_equals(::MappedBasisLayouts, ::MappedOPLayout, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
90+
equals_layout(::MappedOPLayout, ::MappedOPLayout, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
91+
equals_layout(::MappedOPLayout, ::MappedBasisLayouts, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
92+
equals_layout(::MappedBasisLayouts, ::MappedOPLayout, P, Q) = demap(P) == demap(Q) && basismap(P) == basismap(Q)
9393

94-
_broadcastbasis(::typeof(+), ::MappedOPLayout, ::MappedOPLayout, P, Q) = _broadcastbasis(+, MappedBasisLayout(), MappedBasisLayout(), P, Q)
95-
_broadcastbasis(::typeof(+), ::MappedOPLayout, M::MappedBasisLayout, P, Q) = _broadcastbasis(+, MappedBasisLayout(), M, P, Q)
96-
_broadcastbasis(::typeof(+), L::MappedBasisLayout, ::MappedOPLayout, P, Q) = _broadcastbasis(+, L, MappedBasisLayout(), P, Q)
94+
broadcastbasis_layout(::typeof(+), ::MappedOPLayout, ::MappedOPLayout, P, Q) = broadcastbasis_layout(+, MappedBasisLayout(), MappedBasisLayout(), P, Q)
95+
broadcastbasis_layout(::typeof(+), ::MappedOPLayout, M::MappedBasisLayout, P, Q) = broadcastbasis_layout(+, MappedBasisLayout(), M, P, Q)
96+
broadcastbasis_layout(::typeof(+), L::MappedBasisLayout, ::MappedOPLayout, P, Q) = broadcastbasis_layout(+, L, MappedBasisLayout(), P, Q)
9797
sum_layout(::MappedOPLayout, A, dims) = sum_layout(MappedBasisLayout(), A, dims)
9898

9999
# demap to avoid Golub-Welsch fallback
100100
ContinuumArrays.transform_ldiv_if_columns(L::Ldiv{MappedOPLayout,Lay}, ax::OneTo) where Lay = ContinuumArrays.transform_ldiv_if_columns(Ldiv{MappedBasisLayout,Lay}(L.A,L.B), ax)
101101
ContinuumArrays.transform_ldiv_if_columns(L::Ldiv{MappedOPLayout,ApplyLayout{typeof(hcat)}}, ax::OneTo) = ContinuumArrays.transform_ldiv_if_columns(Ldiv{MappedBasisLayout,UnknownLayout}(L.A,L.B), ax)
102102

103-
_equals(::AbstractOPLayout, ::AbstractWeightedBasisLayout, _, _) = false # Weighted-Legendre doesn't exist
104-
_equals(::AbstractWeightedBasisLayout, ::AbstractOPLayout, _, _) = false # Weighted-Legendre doesn't exist
103+
equals_layout(::AbstractOPLayout, ::AbstractWeightedBasisLayout, _, _) = false # Weighted-Legendre doesn't exist
104+
equals_layout(::AbstractWeightedBasisLayout, ::AbstractOPLayout, _, _) = false # Weighted-Legendre doesn't exist
105105

106-
_equals(::WeightedOPLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ)
107-
_equals(::WeightedOPLayout, ::WeightedBasisLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
108-
_equals(::WeightedBasisLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
109-
_equals(::WeightedBasisLayout{<:AbstractOPLayout}, ::WeightedBasisLayout{<:AbstractOPLayout}, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
106+
equals_layout(::WeightedOPLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ)
107+
equals_layout(::WeightedOPLayout, ::WeightedBasisLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
108+
equals_layout(::WeightedBasisLayout, ::WeightedOPLayout, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
109+
equals_layout(::WeightedBasisLayout{<:AbstractOPLayout}, ::WeightedBasisLayout{<:AbstractOPLayout}, wP, wQ) = unweighted(wP) == unweighted(wQ) && weight(wP) == weight(wQ)
110110

111111

112112
copy(L::Ldiv{MappedOPLayout,Lay}) where Lay<:MappedBasisLayouts = copy(Ldiv{MappedBasisLayout,Lay}(L.A,L.B))
@@ -255,10 +255,11 @@ _tritrunc(X, n) = _tritrunc(MemoryLayout(X), X, n)
255255
jacobimatrix(V::SubQuasiArray{<:Any,2,<:Any,<:Tuple{Inclusion,OneTo}}) =
256256
_tritrunc(jacobimatrix(parent(V)), maximum(parentindices(V)[2]))
257257

258-
_grid(::AbstractOPLayout, P, n::Integer) = eigvals(symtridiagonalize(jacobimatrix(P[:,OneTo(n)])))
259-
_grid(::MappedOPLayout, P, n::Integer) = _grid(MappedBasisLayout(), P, n)
260-
_plotgrid(::AbstractOPLayout, P, n::Integer) = grid(P, min(40n, MAX_PLOT_POINTS))
261-
_plotgrid(::MappedOPLayout, P, n::Integer) = _plotgrid(MappedBasisLayout(), P, n)
258+
grid_layout(::AbstractOPLayout, P, n::Integer) = eigvals(symtridiagonalize(jacobimatrix(P[:,OneTo(n)])))
259+
grid_layout(::MappedOPLayout, P, n::Integer) = grid_layout(MappedBasisLayout(), P, n)
260+
plotgrid_layout(::AbstractOPLayout, P, n::Integer) = grid(P, min(40n, MAX_PLOT_POINTS))
261+
plotgrid_layout(::MappedOPLayout, P, n::Integer) = plotgrid_layout(MappedBasisLayout(), P, n)
262+
plotvalues_layout(::ExpansionLayout{MappedOPLayout}, f, x...) = plotvalues_layout(ExpansionLayout{MappedBasisLayout}(), f, x...)
262263

263264
function golubwelsch(X)
264265
D, V = eigen(symtridiagonalize(X)) # Eigenvalue decomposition

src/normalized.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Base.iterate(S::QuasiQR, ::Val{:done}) = nothing
5555

5656
axes(Q::Normalized) = axes(Q.P)
5757

58-
_equals(::AbstractNormalizedOPLayout, ::AbstractNormalizedOPLayout, P, Q) = orthogonalityweight(P) == orthogonalityweight(Q)
59-
_equals(::AbstractNormalizedOPLayout, ::AbstractOPLayout, P, Q) = isnormalized(Q) && orthogonalityweight(P) == orthogonalityweight(Q)
60-
_equals(::AbstractOPLayout, ::AbstractNormalizedOPLayout, P, Q) = isnormalized(P) && orthogonalityweight(P) == orthogonalityweight(Q)
58+
equals_layout(::AbstractNormalizedOPLayout, ::AbstractNormalizedOPLayout, P, Q) = orthogonalityweight(P) == orthogonalityweight(Q)
59+
equals_layout(::AbstractNormalizedOPLayout, ::AbstractOPLayout, P, Q) = isnormalized(Q) && orthogonalityweight(P) == orthogonalityweight(Q)
60+
equals_layout(::AbstractOPLayout, ::AbstractNormalizedOPLayout, P, Q) = isnormalized(P) && orthogonalityweight(P) == orthogonalityweight(Q)
6161

6262

6363

test/test_chebyshev.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map, WeightedBasisLayout
152152
@test chebyshevt(0..1) == chebyshevt(Inclusion(0..1)) == chebyshevt(T) == T
153153
@test (T \ [x exp.(x)])[1:20,1] (T\x)[1:20]
154154
@test (T \ [x exp.(x)])[1:20,2] (T\exp.(x))[1:20]
155+
@test grid(T, 5) == (grid(Chebyshev(), 5) .+ 1)/2
155156

156157
Tn = Chebyshev()[2x .- 1, [1,3,4]]
157158
@test (axes(Tn,1) .* Tn).args[2][1:5,:] (axes(T,1) .* T).args[2][1:5,[1,3,4]]
@@ -169,7 +170,14 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map, WeightedBasisLayout
169170
end
170171

171172
@testset "broadcast" begin
173+
x = Inclusion(0..1)
174+
T = Chebyshev()[2x .- 1,:]
172175
@test (x.^2 .* T)[0.1,1:10] 0.1^2 * T[0.1,1:10]
176+
177+
f = T * [1:3; zeros(∞)]
178+
g = LinearSpline(-1:1)[parentindices(T)[1],:] * [1:3;]
179+
@test_throws ErrorException (f + g)[0.1]
180+
@test_throws ErrorException (g + f)[0.1]
173181
end
174182
end
175183

@@ -228,11 +236,15 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map, WeightedBasisLayout
228236
x = Inclusion(0..1)
229237
wT̃ = wT[2x .- 1, :]
230238
@test MemoryLayout(wT̃) isa MappedWeightedBasisLayout
239+
@test wT̃ == wT̃
240+
@test wT̃ T[2x .- 1, :]
241+
@test T[2x .- 1, :] wT̃
231242
v = wT̃ * (wT̃ \ @.(exp(x)/(sqrt(x)*sqrt(1-x))))
232243
@test v[0.1] let x = 0.1; exp(x)/(sqrt(x)*sqrt(1-x)) end
233244

234245
WT̃ = w[2x .- 1] .* T[2x .- 1, :]
235246
@test MemoryLayout(WT̃) isa WeightedBasisLayout{MappedOPLayout}
247+
@test WT̃  T[2x .- 1, :]
236248
v = WT̃ * (WT̃ \ @.(exp(x)/(sqrt(x)*sqrt(1-x))))
237249
@test v[0.1] let x = 0.1; exp(x)/(sqrt(x)*sqrt(1-x)) end
238250

@@ -254,6 +266,18 @@ import ContinuumArrays: MappedWeightedBasisLayout, Map, WeightedBasisLayout
254266
c = T \ sqrt.(x.^2 .- 1)
255267
@test [T[begin,:]'; L] \ [sqrt(2^2-1); zeros(∞)] c
256268
end
269+
270+
@testset "algebra" begin
271+
T = chebyshevt(2..3)
272+
U = chebyshevu(2..3)
273+
wT = Weighted(ChebyshevT())[parentindices(T)...]
274+
f = T * [1:3; zeros(∞)]
275+
g = U * [1:3; zeros(∞)]
276+
h = wT * [1:3; zeros(∞)]
277+
278+
@test (f + g)[2.1] f[2.1]+g[2.1]
279+
@test (f - g)[2.1] f[2.1]-g[2.1]
280+
end
257281
end
258282
end
259283

@@ -542,6 +566,10 @@ ContinuumArrays.invmap(::InvQuadraticMap{T}) where T = QuadraticMap{T}()
542566
un2 = Tn2 \ (2 * x .^2 .- 1)
543567
u = T \ (2 * x .^2 .- 1)
544568
@test un un2 u[1:10]
569+
570+
f = T * [1:3; zeros(∞)]
571+
g = chebyshevt(0..1) * [1:3; zeros(∞)]
572+
@test_broken (f + g)[0.1] f[0.1] + g[0.1] # ContinuumArrays needs to check maps are equal
545573
end
546574

547575
@testset "block structure" begin

0 commit comments

Comments
 (0)