comparison test/LazyTensors/lazy_tensor_operations_test.jl @ 1013:56fe037641ef refactor/lazy_tensors

Simplify some table tests
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Mar 2022 09:26:13 +0100
parents f7a718bcb4da
children 6abbb2c6c3e4 52f07c77299d
comparison
equal deleted inserted replaced
1008:8920f237caf7 1013:56fe037641ef
219 end 219 end
220 220
221 @testset "Application" begin 221 @testset "Application" begin
222 # Testing regular application and transposed application with inflation "before", "after" and "before and after". 222 # Testing regular application and transposed application with inflation "before", "after" and "before and after".
223 # The inflated tensor mappings are chosen to preserve, reduce and increase the dimension of the result compared to the input. 223 # The inflated tensor mappings are chosen to preserve, reduce and increase the dimension of the result compared to the input.
224 tests = [ 224 cases = [
225 ( 225 (
226 InflatedLazyTensor(I(3,2), A, I(4)), 226 InflatedLazyTensor(I(3,2), A, I(4)),
227 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), # Expected result of apply 227 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), # Expected result of apply
228 (v-> @tullio res[a,b,c,d] := Ã[i,c]*v[a,b,i,d]), # Expected result of apply_transpose 228 (v-> @tullio res[a,b,c,d] := Ã[i,c]*v[a,b,i,d]), # Expected result of apply_transpose
229 ), 229 ),
267 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), 267 (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]),
268 (v-> @tullio res[a,b,c] := C̃[i,a,b]*v[i,c]), 268 (v-> @tullio res[a,b,c] := C̃[i,a,b]*v[i,c]),
269 ), 269 ),
270 ] 270 ]
271 271
272 @testset "apply" begin 272 @testset "$tm" for (tm, true_apply, true_apply_transpose) ∈ cases
273 for i ∈ 1:length(tests) 273 v = rand(domain_size(tm)...)
274 tm = tests[i][1] 274 @test tm*v ≈ true_apply(v) rtol=1e-14
275 v = rand(domain_size(tm)...) 275
276 true_value = tests[i][2](v) 276 v = rand(range_size(tm)...)
277 @test tm*v ≈ true_value rtol=1e-14 277 @test tm'*v ≈ true_apply_transpose(v) rtol=1e-14
278 end
279 end
280
281 @testset "apply_transpose" begin
282 for i ∈ 1:length(tests)
283 tm = tests[i][1]
284 v = rand(range_size(tm)...)
285 true_value = tests[i][3](v)
286 @test tm'*v ≈ true_value rtol=1e-14
287 end
288 end 278 end
289 279
290 @testset "application to other type" begin 280 @testset "application to other type" begin
291 tm = InflatedLazyTensor(I(3,2), A, I(4)) 281 tm = InflatedLazyTensor(I(3,2), A, I(4))
292 282