comparison test/testLazyTensors.jl @ 522:3968210797a9 refactor/inflated_tensormapping_tests

Run tests for inflated tensor mapping in a loop to make things more readable
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 24 Nov 2020 11:05:41 +0100
parents 27e64b3d3efa
children 390901860b0a
comparison
equal deleted inserted replaced
521:afdfb027e439 522:3968210797a9
362 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) 362 @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4)
363 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) 363 @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4)
364 end 364 end
365 365
366 @testset "Application" begin 366 @testset "Application" begin
367 # Test InflatedTensorMapping mapping w. before and after 367 tests = [
368 tm = InflatedTensorMapping(I(3,2), A, I(4)) 368 (
369 v = rand(domain_size(tm)...) 369 InflatedTensorMapping(I(3,2), A, I(4)),
370 @tullio IAIv[a,b,c,d] := Ã[c,i]*v[a,b,i,d] 370 (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]),
371 @test tm*v ≈ IAIv rtol=1e-14 371 ),
372 @inferred LazyTensors.split_index(tm,1,1,1,1) 372 (
373 373 InflatedTensorMapping(I(3,2), A),
374 # Test InflatedTensorMapping mapping w. before 374 (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]),
375 tm = InflatedTensorMapping(I(3,2), A) 375 ),
376 v = rand(domain_size(tm)...) 376 (
377 @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] 377 InflatedTensorMapping(A,I(4)),
378 @test tm*v ≈ IAIv rtol=1e-14 378 (v-> @tullio res[c,d] := Ã[c,i]*v[i,d]),
379 @inferred LazyTensors.split_index(tm,1,1,1) 379 ),
380 380 ]
381 # Test InflatedTensorMapping mapping w. after 381
382 tm = InflatedTensorMapping(A,I(4)) 382 for i ∈ 1:length(tests)
383 v = rand(domain_size(tm)...) 383 tm = tests[i][1]
384 @tullio IAIv[c,d] := Ã[c,i]*v[i,d] 384 v = rand(domain_size(tm)...)
385 @test tm*v ≈ IAIv rtol=1e-14 385 true_value = tests[i][2](v)
386 @inferred LazyTensors.split_index(tm,1,1) 386 @test tm*v ≈ true_value rtol=1e-14
387 end
387 388
388 @testset "Inference of application" begin 389 @testset "Inference of application" begin
389 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} 390 struct ScalingOperator{T,D} <: TensorMapping{T,D,D}
390 λ::T 391 λ::T
391 size::NTuple{D,Int} 392 size::NTuple{D,Int}