Mercurial > repos > public > sbplib_julia
changeset 535:b6768d769f46
Merge refactor/inflated_tensormapping_tests
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 26 Nov 2020 17:20:22 +0100 |
parents | afdfb027e439 (current diff) c5f9b5ab36e7 (diff) |
children | fc0f942b8792 013ca4892540 |
files | |
diffstat | 1 files changed, 46 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/test/testLazyTensors.jl Tue Nov 24 11:04:32 2020 +0100 +++ b/test/testLazyTensors.jl Thu Nov 26 17:20:22 2020 +0100 @@ -364,26 +364,53 @@ end @testset "Application" begin - # Test InflatedTensorMapping mapping w. before and after - tm = InflatedTensorMapping(I(3,2), A, I(4)) - v = rand(domain_size(tm)...) - @tullio IAIv[a,b,c,d] := Ã[c,i]*v[a,b,i,d] - @test tm*v ≈ IAIv rtol=1e-14 - @inferred LazyTensors.split_index(tm,1,1,1,1) + # Testing regular application and transposed application with inflation "before", "after" and "before and after". + # The inflated tensor mappings are chosen to preserve, reduce and increase the dimension of the result compared to the input. + tests = [ + ( + InflatedTensorMapping(I(3,2), A, I(4)), + (v-> @tullio res[a,b,c,d] := Ã[c,i]*v[a,b,i,d]), + ), + ( + InflatedTensorMapping(I(3,2), B, I(4)), + (v-> @tullio res[a,b,c,d,e] := B̃[c,d,i]*v[a,b,i,e]), + ), + ( + InflatedTensorMapping(I(3,2), C, I(4)), + (v-> @tullio res[a,b,c,d] := C̃[c,i,j]*v[a,b,i,j,d]), + ), + ( + InflatedTensorMapping(I(3,2), A), + (v-> @tullio res[a,b,c] := Ã[c,i]*v[a,b,i]), + ), + ( + InflatedTensorMapping(I(3,2), B), + (v-> @tullio res[a,b,c,d] := B̃[c,d,i]*v[a,b,i]), + ), + ( + InflatedTensorMapping(I(3,2), C), + (v-> @tullio res[a,b,c] := C̃[c,i,j]*v[a,b,i,j]), + ), + ( + InflatedTensorMapping(A,I(4)), + (v-> @tullio res[a,b] := Ã[a,i]*v[i,b]), + ), + ( + InflatedTensorMapping(B,I(4)), + (v-> @tullio res[a,b,c] := B̃[a,b,i]*v[i,c]), + ), + ( + InflatedTensorMapping(C,I(4)), + (v-> @tullio res[a,b] := C̃[a,i,j]*v[i,j,b]), + ), + ] - # Test InflatedTensorMapping mapping w. before - tm = InflatedTensorMapping(I(3,2), A) - v = rand(domain_size(tm)...) - @tullio IAIv[a,b,c] := Ã[c,i]*v[a,b,i] - @test tm*v ≈ IAIv rtol=1e-14 - @inferred LazyTensors.split_index(tm,1,1,1) - - # Test InflatedTensorMapping mapping w. after - tm = InflatedTensorMapping(A,I(4)) - v = rand(domain_size(tm)...) - @tullio IAIv[c,d] := Ã[c,i]*v[i,d] - @test tm*v ≈ IAIv rtol=1e-14 - @inferred LazyTensors.split_index(tm,1,1) + for i ∈ 1:length(tests) + tm = tests[i][1] + v = rand(domain_size(tm)...) + true_value = tests[i][2](v) + @test tm*v ≈ true_value rtol=1e-14 + end @testset "Inference of application" begin struct ScalingOperator{T,D} <: TensorMapping{T,D,D}