Skip to content

Commit 116019e

Browse files
committed
sample on rectangles
1 parent d470905 commit 116019e

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MultivariateOrthogonalPolynomials"
22
uuid = "4f6956fd-4f93-5457-9149-7bfc4b2ce06d"
3-
version = "0.9.3"
3+
version = "0.9.4"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -29,8 +29,8 @@ ArrayLayouts = "1.11"
2929
BandedMatrices = "1"
3030
BlockArrays = "1.0"
3131
BlockBandedMatrices = "0.13"
32-
ClassicalOrthogonalPolynomials = "0.15"
33-
ContinuumArrays = "0.19.5"
32+
ClassicalOrthogonalPolynomials = "0.15.8"
33+
ContinuumArrays = "0.19.6"
3434
DomainSets = "0.7"
3535
FastTransforms = "0.17"
3636
FillArrays = "1.0"
@@ -40,6 +40,7 @@ InfiniteLinearAlgebra = "0.9, 0.10"
4040
LazyArrays = "2.3.1"
4141
LazyBandedMatrices = "0.11.3"
4242
QuasiArrays = "0.12.2"
43+
Random = "1.11.0"
4344
RecurrenceRelationships = "0.2"
4445
SpecialFunctions = "1, 2"
4546
StaticArrays = "1"
@@ -48,8 +49,9 @@ julia = "1.10"
4849
[extras]
4950
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
5051
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
52+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
5153
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
5254
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5355

5456
[targets]
55-
test = ["Base64", "ForwardDiff", "RecipesBase", "Test"]
57+
test = ["Base64", "ForwardDiff", "Random", "RecipesBase", "Test"]

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import LazyArrays: arguments, paddeddata, LazyArrayStyle, LazyLayout, PaddedLayo
2121
import LazyBandedMatrices: LazyBandedBlockBandedLayout, AbstractBandedBlockBandedLayout, AbstractLazyBandedBlockBandedLayout, _krontrav_axes, DiagTravLayout, invdiagtrav, ApplyBandedBlockBandedLayout, krontrav
2222
import InfiniteArrays: InfiniteCardinal, OneToInf
2323

24-
import ClassicalOrthogonalPolynomials: jacobimatrix, Weighted, orthogonalityweight, HalfWeighted, WeightedBasis, pad, recurrencecoefficients, clenshaw, weightedgrammatrix, Clenshaw, OPLayout
24+
import ClassicalOrthogonalPolynomials: jacobimatrix, Weighted, orthogonalityweight, HalfWeighted, WeightedBasis, pad, recurrencecoefficients, clenshaw, weightedgrammatrix, Clenshaw, OPLayout, sample, sample_layout
2525
import HarmonicOrthogonalPolynomials: BivariateOrthogonalPolynomial, MultivariateOrthogonalPolynomial, Plan,
2626
AngularMomentum, angularmomentum, BlockOneTo, BlockRange1, interlace,
2727
MultivariateOPLayout, AbstractMultivariateOPLayout, MAX_PLOT_BLOCKS

src/rect.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,14 @@ end
202202
function vec_layout(::KronExpansionLayout{OPLayout, OPLayout}, f)
203203
A,C,Bc = arguments(f)
204204
RectPolynomial(A, Bc') * DiagTrav(C)
205-
end
205+
end
206+
207+
function sample_layout(::ExpansionLayout{MultivariateOrthogonalPolynomials.KronOPLayout{2}}, f::AbstractQuasiVector, n)
208+
F = reshape(f)
209+
x = sample(sum(F; dims=2), n)
210+
# x = sample(F[:,y]) # TODO: this should work
211+
y = [sample(F[x,:]) for x in x]
212+
map(SVector, x, y)
213+
end
214+
215+
sample_layout(lay::ExpansionLayout{MultivariateOrthogonalPolynomials.KronOPLayout{2}}, f::AbstractQuasiVector) = only(sample_layout(lay, f, 1))

test/test_rect.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, LinearAlgebra, BlockArrays, FillArrays, Base64, LazyBandedMatrices, ArrayLayouts, Test
2-
using ClassicalOrthogonalPolynomials: expand, coefficients, recurrencecoefficients
1+
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, LinearAlgebra, BlockArrays, FillArrays, Base64, LazyBandedMatrices, ArrayLayouts, Random, Test
2+
using ClassicalOrthogonalPolynomials: expand, coefficients, recurrencecoefficients, sample
33
using MultivariateOrthogonalPolynomials: weaklaplacian, ClenshawKron
44
using ContinuumArrays: plotgridvalues, ExpansionLayout
55
using Base: oneto
66

7+
Random.seed!(3242)
8+
79
@testset "RectPolynomial" begin
810
@testset "Evaluation" begin
911
T = ChebyshevT()
@@ -161,7 +163,7 @@ using Base: oneto
161163
f = expand(P, splat((x,y) -> 1))
162164
@test diff(f,(1,0))[SVector(0.1,0.2)] == diff(f,(0,1))[SVector(0.1,0.2)] == 0.0
163165
f = expand(P, splat((x,y) -> x))
164-
@test diff(f,(1,0))[SVector(0.1,0.2)] == 1.0
166+
@test diff(f,(1,0))[SVector(0.1,0.2)] 1.0
165167
@test diff(f,(0,1))[SVector(0.1,0.2)] == 0.0
166168
f = expand(P, splat((x,y) -> cos(x*exp(y))))
167169
@test diff(f,(1,0))[SVector(0.1,0.2)] -sin(0.1*exp(0.2))*exp(0.2)
@@ -247,5 +249,8 @@ using Base: oneto
247249
F = reshape(f)
248250
@test sum(F; dims=1)[1,0.2] 2.346737615950585
249251
@test sum(F; dims=2)[0.1,1] 2.1748993079723618
252+
253+
x,y = coordinates(P)
254+
@test sum(sample(f, 100_000))/100_000 [sum(x .* f)/sum(f),sum(y .* f)/sum(f)] rtol=1E-1
250255
end
251256
end

0 commit comments

Comments
 (0)