@@ -13,6 +13,82 @@ using StaticArrays: SVector
13
13
using Base: oneto
14
14
15
15
@verbose @testset " Multivariate" begin
16
+ @testset " vectorization order" begin
17
+ @testset " 2D trivial" begin
18
+ S = Chebyshev ()^ 2
19
+ it = tensorizer (S)
20
+ expected_order = [(1 , 1 )
21
+ (1 ,2 )
22
+ (2 ,1 )
23
+ (1 ,3 )
24
+ (2 ,2 )
25
+ (3 ,1 )
26
+ (1 ,4 )
27
+ (2 ,3 )]
28
+ k = 0
29
+ for i in it
30
+ k = k + 1
31
+ if k> length (expected_order)
32
+ break
33
+ end
34
+ @test i == expected_order[k]
35
+ end
36
+ end
37
+
38
+ @testset " 3D trivial" begin
39
+ S = Chebyshev ()^ 3
40
+ it = tensorizer (S)
41
+ expected_order = [(1 , 1 , 1 )
42
+ (1 ,1 ,2 )
43
+ (1 ,2 ,1 )
44
+ (2 ,1 ,1 )
45
+ (1 ,1 ,3 )
46
+ (1 ,2 ,2 )
47
+ (2 ,1 ,2 )
48
+ (1 ,3 ,1 )
49
+ (2 ,2 ,1 )
50
+ (3 ,1 ,1 )
51
+ (1 ,1 ,4 )
52
+ (1 ,2 ,3 )
53
+ (2 ,1 ,3 )
54
+ (1 ,3 ,2 )
55
+ (2 ,2 ,2 )
56
+ (3 ,1 ,2 )
57
+ (1 ,4 ,1 )
58
+ (2 ,3 ,1 )
59
+ (3 ,2 ,1 )
60
+ (4 ,1 ,1 )]
61
+ # convert tuples to arrays for n>2 dimensions
62
+ expected_order = [[v... ] for v ∈ expected_order]
63
+ k = 0
64
+ for i in it
65
+ k = k + 1
66
+ if k> length (expected_order)
67
+ break
68
+ end
69
+ @test i == expected_order[k]
70
+ end
71
+ end
72
+ end
73
+
74
+ @testset " Evaluation" begin
75
+
76
+ @testset " 2D" begin
77
+ f2 = Fun (Chebyshev ()^ 2 , [1.0 ])
78
+ @test f2 (0.2 , 0.4 ) == 1.0
79
+ end
80
+
81
+ @testset " 3D" begin
82
+ f3 = Fun (Chebyshev ()^ 3 , [1.0 ])
83
+ @test f3 (0.2 , 0.4 , 0.2 ) == 1.0
84
+ end
85
+
86
+ @testset " 20D" begin
87
+ f20 = Fun (Chebyshev ()^ 20 , [1.0 ])
88
+ @test f20 (rand (20 )) == 1.0
89
+ end
90
+ end
91
+
16
92
@testset " Square" begin
17
93
S = Space (ChebyshevInterval ()^ 2 )
18
94
@test @inferred (blocklengths (S)) ≡ oneto (∞)
@@ -59,13 +135,55 @@ using Base: oneto
59
135
f= Fun (gg)
60
136
@test f (0. ,0. ) ≈ ff (0. ,0. )
61
137
138
+ end
62
139
140
+ @testset " Arithmetic" begin
63
141
# Fun +-* constant
64
142
f= Fun ((x,y)-> exp (x)* cos (y))
65
143
66
144
@test f (0.1 ,0.2 )+ 2 ≈ (f+ 2 )(0.1 ,0.2 )
67
145
@test f (0.1 ,0.2 )- 2 ≈ (f- 2 )(0.1 ,0.2 )
68
146
@test f (0.1 ,0.2 )* 2 ≈ (f* 2 )(0.1 ,0.2 )
147
+
148
+ @testset " Addition" begin
149
+ # coefficients
150
+ c_1 = rand (20 )
151
+ c_2 = rand (30 )
152
+
153
+ added_coef = [c_2[1 : 20 ]+ c_1;c_2[21 : end ]]
154
+
155
+ # 2D
156
+ f2_1 = Fun (Chebyshev ()^ 2 , c_1)
157
+ f2_2 = Fun (Chebyshev ()^ 2 , c_2)
158
+ @test coefficients (f2_1+ f2_2) == added_coef
159
+
160
+ @test (f2_1+ f2_2)(0.3 , 0.5 )≈ f2_1 (0.3 , 0.5 )+ f2_2 (0.3 , 0.5 )
161
+
162
+ # 3D
163
+ f3_1 = Fun (Chebyshev ()^ 3 , c_1)
164
+ f3_2 = Fun (Chebyshev ()^ 3 , c_2)
165
+ @test coefficients (f3_1+ f3_2) == added_coef
166
+
167
+ @test (f3_1+ f3_2)(0.3 , 0.5 , 0.6 )≈ f3_1 (0.3 , 0.5 , 0.6 )+ f3_2 (0.3 , 0.5 , 0.6 )
168
+ end
169
+
170
+ @testset " Multiplication" begin
171
+ # coefficients
172
+ c_1 = rand (20 )
173
+ c_2 = rand (30 )
174
+
175
+ # 2D
176
+ f2_1 = Fun (Chebyshev ()^ 2 , c_1)
177
+ f2_2 = Fun (Chebyshev ()^ 2 , c_2)
178
+
179
+ @test (f2_1 * f2_2)(0.4 , 0.5 ) ≈ f2_1 (0.4 , 0.5 ) * f2_2 (0.4 , 0.5 )
180
+
181
+ # 3D: not implemented in code yet
182
+ # f3_1 = Fun(Chebyshev()^3, c_1)
183
+ # f3_2 = Fun(Chebyshev()^3, c_2)
184
+
185
+ # @test (f3_1*f3_2)(0.4,0.5,0.6) ≈ f3_1(0.4,0.5,0.6)*f3_2(0.4,0.5,0.6)
186
+ end
69
187
end
70
188
71
189
@testset " LowRankFun" begin
0 commit comments