Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/allocations_test.jl @ 1886:9ce6d939dfae allocation_testing
Start experimenting with allocation testing
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 07 Apr 2022 07:37:02 +0200 |
parents | |
children | 24590890e124 |
comparison
equal
deleted
inserted
replaced
1075:03f65ef8adb9 | 1886:9ce6d939dfae |
---|---|
1 using Test | |
2 using BenchmarkTools | |
3 | |
4 using Sbplib.Grids | |
5 using Sbplib.SbpOperators | |
6 | |
7 using Sbplib.LazyTensors | |
8 using Sbplib.RegionIndices | |
9 | |
10 @testset "Allocations" begin | |
11 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml", order=4) | |
12 | |
13 @testset "1D" begin | |
14 g₁ = EquidistantGrid(15, 0.,1.) | |
15 | |
16 H = inner_product(g₁, stencil_set) | |
17 H⁻¹ = inverse_inner_product(g₁, stencil_set) | |
18 D₂ = second_derivative(g₁, stencil_set, 1) | |
19 | |
20 eₗ = boundary_restriction(g₁, stencil_set, CartesianBoundary{1,Lower}()) | |
21 eᵣ = boundary_restriction(g₁, stencil_set, CartesianBoundary{1,Upper}()) | |
22 | |
23 dₗ = normal_derivative(g₁, stencil_set, CartesianBoundary{1,Lower}()) | |
24 dᵣ = normal_derivative(g₁, stencil_set, CartesianBoundary{1,Upper}()) | |
25 | |
26 | |
27 | |
28 @testset "Derivative operator" begin | |
29 v = rand(size(g₁)...) | |
30 @test (@ballocated LazyTensors.apply($D₂, $v, 1)) == 0 | |
31 @test (@ballocated LazyTensors.apply($D₂, $v, 6)) == 0 | |
32 @test (@ballocated LazyTensors.apply($D₂, $v, 15)) == 0 | |
33 end | |
34 | |
35 @testset "inner_product operator" begin | |
36 v = rand(size(g₁)...) | |
37 | |
38 @test (@ballocated LazyTensors.apply($H, $v, 1)) == 0 | |
39 @test (@ballocated LazyTensors.apply($H, $v, 6)) == 0 | |
40 @test (@ballocated LazyTensors.apply($H, $v, 15)) == 0 | |
41 | |
42 @test (@ballocated LazyTensors.apply($(H∘H), $v, 5)) == 0 | |
43 end | |
44 | |
45 @testset "inverse_inner_product operator" begin | |
46 v = rand(size(g₁)...) | |
47 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1)) == 0 | |
48 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6)) == 0 | |
49 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15)) == 0 | |
50 end | |
51 | |
52 @testset "boundary operators" begin | |
53 v = rand(size(g₁)...) | |
54 @test (@ballocated LazyTensors.apply($eₗ, $v)) == 0 | |
55 @test (@ballocated LazyTensors.apply($eᵣ, $v)) == 0 | |
56 @test (@ballocated LazyTensors.apply($dₗ, $v)) == 0 | |
57 @test (@ballocated LazyTensors.apply($dᵣ, $v)) == 0 | |
58 end | |
59 | |
60 @testset "boundary operator transposes" begin | |
61 v = fill(1.) | |
62 @test (@ballocated LazyTensors.apply($eₗ', $v, 1)) == 0 | |
63 @test (@ballocated LazyTensors.apply($eₗ', $v, 7)) == 0 | |
64 @test (@ballocated LazyTensors.apply($eₗ', $v, 15)) == 0 | |
65 | |
66 @test (@ballocated LazyTensors.apply($eᵣ', $v, 1)) == 0 | |
67 @test (@ballocated LazyTensors.apply($eᵣ', $v, 7)) == 0 | |
68 @test (@ballocated LazyTensors.apply($eᵣ', $v, 15)) == 0 | |
69 | |
70 @test (@ballocated LazyTensors.apply($dₗ', $v, 1)) == 0 | |
71 @test (@ballocated LazyTensors.apply($dₗ', $v, 7)) == 0 | |
72 @test (@ballocated LazyTensors.apply($dₗ', $v, 15)) == 0 | |
73 | |
74 @test (@ballocated LazyTensors.apply($dᵣ', $v, 1)) == 0 | |
75 @test (@ballocated LazyTensors.apply($dᵣ', $v, 7)) == 0 | |
76 @test (@ballocated LazyTensors.apply($dᵣ', $v, 15)) == 0 | |
77 end | |
78 | |
79 @testset "sat terms" begin | |
80 v = rand(size(g₁)...) | |
81 neumannSATₗ = H⁻¹∘eₗ'∘dₗ | |
82 neumannSATᵣ = H⁻¹∘eᵣ'∘dᵣ | |
83 | |
84 | |
85 @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 1)) == 0 | |
86 @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 6)) == 0 | |
87 @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 15)) == 0 | |
88 | |
89 @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 1)) == 0 | |
90 @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 6)) == 0 | |
91 @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 15)) == 0 | |
92 end | |
93 end | |
94 | |
95 | |
96 @testset "2D" begin | |
97 g₂ = EquidistantGrid((15,15), (0.,0.),(1.,1.)) | |
98 | |
99 H = inner_product(g₂, stencil_set) | |
100 H⁻¹ = inverse_inner_product(g₂, stencil_set) | |
101 D₂x = second_derivative(g₂, stencil_set, 1) | |
102 D₂y = second_derivative(g₂, stencil_set, 2) | |
103 | |
104 e₁ₗ = boundary_restriction(g₂, stencil_set, CartesianBoundary{1,Lower}()) | |
105 e₁ᵤ = boundary_restriction(g₂, stencil_set, CartesianBoundary{1,Upper}()) | |
106 e₂ₗ = boundary_restriction(g₂, stencil_set, CartesianBoundary{2,Lower}()) | |
107 e₂ᵤ = boundary_restriction(g₂, stencil_set, CartesianBoundary{2,Upper}()) | |
108 | |
109 d₁ₗ = normal_derivative(g₂, stencil_set, CartesianBoundary{1,Lower}()) | |
110 d₁ᵤ = normal_derivative(g₂, stencil_set, CartesianBoundary{1,Upper}()) | |
111 d₂ₗ = normal_derivative(g₂, stencil_set, CartesianBoundary{2,Lower}()) | |
112 d₂ᵤ = normal_derivative(g₂, stencil_set, CartesianBoundary{2,Upper}()) | |
113 | |
114 H₁ₗ = inner_product(boundary_grid(g₂, CartesianBoundary{1,Lower}()), stencil_set) | |
115 H₁ᵤ = inner_product(boundary_grid(g₂, CartesianBoundary{1,Upper}()), stencil_set) | |
116 H₂ₗ = inner_product(boundary_grid(g₂, CartesianBoundary{2,Lower}()), stencil_set) | |
117 H₂ᵤ = inner_product(boundary_grid(g₂, CartesianBoundary{2,Upper}()), stencil_set) | |
118 | |
119 | |
120 @testset "Derivative operator" begin | |
121 v = rand(size(g₂)...) | |
122 @test (@ballocated LazyTensors.apply($D₂x, $v, 1, 7)) == 0 | |
123 @test (@ballocated LazyTensors.apply($D₂x, $v, 6, 7)) == 0 | |
124 @test (@ballocated LazyTensors.apply($D₂x, $v, 15, 7)) == 0 | |
125 | |
126 @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 1)) == 0 | |
127 @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 6)) == 0 | |
128 @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 15)) == 0 | |
129 | |
130 @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 1, 1)) == 0 | |
131 @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 7, 6)) == 0 | |
132 @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 15, 15)) == 0 | |
133 end | |
134 | |
135 @testset "inner_product operator" begin | |
136 v = rand(size(g₂)...) | |
137 @test (@ballocated LazyTensors.apply($H, $v, 1, 1)) == 0 | |
138 @test (@ballocated LazyTensors.apply($H, $v, 1, 6)) == 0 | |
139 @test (@ballocated LazyTensors.apply($H, $v, 1, 15)) == 0 | |
140 @test (@ballocated LazyTensors.apply($H, $v, 6, 1)) == 0 | |
141 @test (@ballocated LazyTensors.apply($H, $v, 6, 6)) == 0 | |
142 @test (@ballocated LazyTensors.apply($H, $v, 6, 15)) == 0 | |
143 @test (@ballocated LazyTensors.apply($H, $v, 15, 1)) == 0 | |
144 @test (@ballocated LazyTensors.apply($H, $v, 15, 6)) == 0 | |
145 @test (@ballocated LazyTensors.apply($H, $v, 15, 15)) == 0 | |
146 | |
147 | |
148 @test (@ballocated LazyTensors.apply($(H∘H), $v, 5, 5)) == 0 | |
149 end | |
150 | |
151 @testset "inverse_inner_product operator" begin | |
152 v = rand(size(g₂)...) | |
153 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 1)) == 0 | |
154 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 6)) == 0 | |
155 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 15)) == 0 | |
156 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 1)) == 0 | |
157 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 6)) == 0 | |
158 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 15)) == 0 | |
159 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 1)) == 0 | |
160 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 6)) == 0 | |
161 @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 15)) == 0 | |
162 end | |
163 | |
164 @testset "boundary operators" begin | |
165 v = rand(size(g₂)...) | |
166 @test (@ballocated LazyTensors.apply($e₁ₗ, $v, 1)) == 0 | |
167 @test (@ballocated LazyTensors.apply($e₁ᵤ, $v, 5)) == 0 | |
168 @test (@ballocated LazyTensors.apply($e₂ₗ, $v, 15)) == 0 | |
169 @test (@ballocated LazyTensors.apply($e₂ᵤ, $v, 3)) == 0 | |
170 | |
171 @test (@ballocated LazyTensors.apply($d₁ₗ, $v, 5)) == 0 | |
172 @test (@ballocated LazyTensors.apply($d₁ᵤ, $v, 15)) == 0 | |
173 @test (@ballocated LazyTensors.apply($d₂ₗ, $v, 1)) == 0 | |
174 @test (@ballocated LazyTensors.apply($d₂ᵤ, $v, 5)) == 0 | |
175 end | |
176 | |
177 @testset "boundary operator transposes" begin | |
178 v = rand(first(size(g₂))) | |
179 | |
180 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 1)) == 0 | |
181 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 6)) == 0 | |
182 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 15)) == 0 | |
183 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 1)) == 0 | |
184 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 6)) == 0 | |
185 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 15)) == 0 | |
186 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 1)) == 0 | |
187 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 6)) == 0 | |
188 @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 15)) == 0 | |
189 | |
190 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 1)) == 0 | |
191 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 6)) == 0 | |
192 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 15)) == 0 | |
193 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 1)) == 0 | |
194 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 6)) == 0 | |
195 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 15)) == 0 | |
196 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 1)) == 0 | |
197 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 6)) == 0 | |
198 @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 15)) == 0 | |
199 end | |
200 | |
201 @testset "sat terms" begin | |
202 v = rand(size(g₂)...) | |
203 u = rand(size(g₂)[1]) | |
204 # neumannSAT₁ₗ = H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ | |
205 # neumannSAT₂ᵤ = H⁻¹∘e₂ᵤ'∘H₂ᵤ∘d₂ᵤ | |
206 | |
207 neumannSAT₁ₗ = e₁ₗ'∘d₁ₗ | |
208 neumannSAT₂ᵤ = e₂ᵤ'∘d₂ᵤ | |
209 | |
210 # indices = [1,6,15] | |
211 indices = [1] | |
212 | |
213 @testset for i ∈ indices | |
214 @testset for j ∈ indices | |
215 @test (@ballocated LazyTensors.apply($(e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 | |
216 @test (@ballocated LazyTensors.apply($(d₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 | |
217 | |
218 @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 | |
219 @test_broken (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ∘d₁ₗ∘H⁻¹), $v, $i, $j)) == 0 | |
220 @test (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 | |
221 @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 | |
222 @test (@ballocated LazyTensors.apply($(H⁻¹∘D₂x), $v, $i, $j)) == 0 | |
223 @test (@ballocated LazyTensors.apply($(H⁻¹∘D₂y), $v, $i, $j)) == 0 | |
224 @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘D₂x∘D₂y), $v, $i, $j)) == 0 | |
225 @test_broken (@ballocated LazyTensors.apply($(D₂x∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 | |
226 @test_broken (@ballocated LazyTensors.apply($(D₂y∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 | |
227 @test (@ballocated LazyTensors.apply($(D₂x∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 | |
228 @test (@ballocated LazyTensors.apply($(D₂y∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 | |
229 | |
230 @test (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'), $u, $i, $j)) == 0 | |
231 @test (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ), $u, $i, $j)) == 0 | |
232 @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ), $v, $i)) == 0 | |
233 | |
234 @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘H₁ₗ), $u, $i, $j)) == 0 | |
235 @test (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘H⁻¹), $v, $i)) == 0 | |
236 @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘H⁻¹), $v, $i)) == 0 | |
237 | |
238 @test_broken (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ∘e₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 | |
239 @test (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ∘e₁ₗ'), $u, $i, $j)) == 0 | |
240 @test (@ballocated LazyTensors.apply($(e₁ₗ∘e₁ₗ'∘e₁ₗ), $v, $i)) == 0 | |
241 @test (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 | |
242 @test (@ballocated LazyTensors.apply($(e₁ₗ∘e₁ₗ'), $u, $i)) == 0 | |
243 | |
244 | |
245 @test (@ballocated LazyTensors.apply($H, $v, $i, $j)) == 0 | |
246 @test (@ballocated LazyTensors.apply($(H∘H), $v, $i, $j)) == 0 | |
247 @test_broken (@ballocated LazyTensors.apply($(H∘H∘H), $v, $i, $j)) == 0 | |
248 @test_broken (@ballocated LazyTensors.apply($(H∘H∘H∘H), $v, $i, $j)) == 0 | |
249 end | |
250 @test (@ballocated LazyTensors.apply($(e₁ₗ∘d₁ₗ'), $u, $i)) == 0 | |
251 @test (@ballocated LazyTensors.apply($(d₁ₗ∘e₁ₗ'), $u, $i)) == 0 | |
252 | |
253 @test (@ballocated LazyTensors.apply($(e₁ₗ∘H∘d₁ₗ'), $u, $i)) == 0 | |
254 @test (@ballocated LazyTensors.apply($(d₁ₗ∘H∘e₁ₗ'), $u, $i)) == 0 | |
255 | |
256 @test (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘d₁ₗ'), $u, $i)) == 0 | |
257 @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘e₁ₗ'), $u, $i)) == 0 | |
258 | |
259 @test_broken (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘H∘d₁ₗ'), $u, $i)) == 0 | |
260 @test_broken (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘H∘e₁ₗ'), $u, $i)) == 0 | |
261 | |
262 @test_broken (@ballocated LazyTensors.apply($(e₁ₗ∘H∘d₁ₗ'∘H₁ₗ), $u, $i)) == 0 | |
263 @test_broken (@ballocated LazyTensors.apply($(d₁ₗ∘H∘e₁ₗ'∘H₁ₗ), $u, $i)) == 0 | |
264 end | |
265 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 1)) == 0 | |
266 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 6)) == 0 | |
267 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 15)) == 0 | |
268 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 1)) == 0 | |
269 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 6)) == 0 | |
270 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 15)) == 0 | |
271 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 1)) == 0 | |
272 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 6)) == 0 | |
273 @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 15)) == 0 | |
274 | |
275 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 1)) == 0 | |
276 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 6)) == 0 | |
277 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 15)) == 0 | |
278 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 1)) == 0 | |
279 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 6)) == 0 | |
280 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 15)) == 0 | |
281 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 1)) == 0 | |
282 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 6)) == 0 | |
283 @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 15)) == 0 | |
284 end | |
285 | |
286 end | |
287 end |