Skip to content

Commit 399ae4f

Browse files
committed
Support vec with RectPolynomial and fix sum ordering
1 parent 6fb10b9 commit 399ae4f

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ InfiniteArrays = "0.15"
3939
InfiniteLinearAlgebra = "0.9, 0.10"
4040
LazyArrays = "2.3.1"
4141
LazyBandedMatrices = "0.11.3"
42-
QuasiArrays = "0.12"
42+
QuasiArrays = "0.12.2"
4343
RecurrenceRelationships = "0.2"
4444
SpecialFunctions = "1, 2"
4545
StaticArrays = "1"

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Base: axes, in, ==, +, -, /, *, ^, \, copy, copyto!, OneTo, getindex, siz
1010
import Base.Broadcast: Broadcasted, broadcasted, DefaultArrayStyle
1111
import DomainSets: boundary, EuclideanDomain
1212

13-
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle, domain
13+
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle, domain, vec_layout
1414
import ContinuumArrays: @simplify, Weight, weight, grid, plotgrid, TransformFactorization, ExpansionLayout, plotvalues, unweighted, plan_transform, checkpoints, transform_ldiv, AbstractBasisLayout, basis_axes, Inclusion, grammatrix, weaklaplacian, layout_broadcasted, laplacian, abslaplacian, laplacian_axis, abslaplacian_axis, diff_layout, operatororder, broadcastbasis
1515

1616
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize

src/rect.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const RectPolynomial{T, PP} = KronPolynomial{2, T, PP}
2727

2828

2929
axes(P::KronPolynomial) = (Inclusion(×(map(domain, axes.(P.args, 1))...)), _krontrav_axes(axes.(P.args, 2)...))
30+
31+
3032
function getindex(P::RectPolynomial{T}, xy::StaticVector{2}, Jj::BlockIndex{1})::T where T
3133
a,b = P.args
3234
J,j = Int(block(Jj)),blockindex(Jj)
@@ -164,9 +166,9 @@ end
164166

165167
## sum
166168

167-
function Base._sum(P::RectPolynomial, dims)
169+
function Base._sum(P::RectPolynomial, dims::Int)
168170
@assert dims == 1
169-
KronTrav(sum.(P.args; dims=1)...)
171+
KronTrav(reverse(sum.(P.args; dims=1))...)
170172
end
171173

172174
## multiplication
@@ -183,4 +185,15 @@ function layout_broadcasted(::Tuple{ExpansionLayout{KronOPLayout{2}},KronOPLayou
183185
end
184186

185187

186-
broadcastbasis(::typeof(+), A::KronPolynomial, B::KronPolynomial) = KronPolynomial(broadcastbasis.(+, A.args, B.args)...)
188+
broadcastbasis(::typeof(+), A::KronPolynomial, B::KronPolynomial) = KronPolynomial(broadcastbasis.(+, A.args, B.args)...)
189+
190+
191+
192+
####
193+
# vec
194+
####
195+
196+
function vec_layout(::ExpansionLayout{KronOPLayout{2}}, f)
197+
A,B = basis(f).args
198+
A*invdiagtrav(coefficients(f))*B'
199+
end

test/test_rect.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ using Base: oneto
148148
end
149149

150150
@testset "sum" begin
151-
P = RectPolynomial(Legendre(),Legendre())
152-
p₀ = expand(P, 𝐱 -> 1)
153-
@test sum(p₀) 4.0
154-
f = expand(P, splat((x,y) -> exp(cos(x^2*y))))
155-
@test sum(f) 10.546408460894801 # empirical
151+
for P in (RectPolynomial(Legendre(),Legendre()), RectPolynomial(Legendre(),Chebyshev()))
152+
p₀ = expand(P, 𝐱 -> 1)
153+
@test sum(p₀) 4.0
154+
f = expand(P, splat((x,y) -> exp(cos(x^2*y))))
155+
@test sum(f) 10.546408460894801 # empirical
156+
end
156157
end
157158

158159
@testset "KronTrav bug" begin
@@ -204,4 +205,10 @@ using Base: oneto
204205

205206
𝐜 = expand(RectPolynomial(Legendre(),Jacobi(1,0)),splat((x,y) -> cos(x*sin(y))))
206207
end
208+
209+
@testset "vec" begin
210+
P = RectPolynomial(Legendre(),Chebyshev())
211+
f = expand(P, splat((x,y) -> cos((x-0.1)*exp(y))))
212+
@test vec(f)[0.1,0.2] f[SVector(0.1,0.2)]
213+
end
207214
end

0 commit comments

Comments
 (0)