Mercurial > repos > public > sbplib_julia
changeset 508:27e64b3d3efa
Restructure tests for InflatedTensorMapping
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 23 Nov 2020 21:15:04 +0100 |
parents | fbbb3733650c |
children | fe86ac896377 afdfb027e439 |
files | test/testLazyTensors.jl |
diffstat | 1 files changed, 55 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/test/testLazyTensors.jl Fri Nov 06 21:37:10 2020 +0100 +++ b/test/testLazyTensors.jl Mon Nov 23 21:15:04 2020 +0100 @@ -340,61 +340,69 @@ B = LazyLinearMap(B̃,(1,2),(3,)) C = LazyLinearMap(C̃,(1,),(2,3)) - @test InflatedTensorMapping(I(3,2), A, I(4)) isa TensorMapping{Float64, 4, 4} - @test InflatedTensorMapping(I(3,2), B, I(4)) isa TensorMapping{Float64, 5, 4} - @test InflatedTensorMapping(I(3), C, I(2,3)) isa TensorMapping{Float64, 4, 5} - @test InflatedTensorMapping(C, I(2,3)) isa TensorMapping{Float64, 3, 4} - @test InflatedTensorMapping(I(3), C) isa TensorMapping{Float64, 2, 3} - @test InflatedTensorMapping(I(3), I(2,3)) isa TensorMapping{Float64, 3, 3} - - @test range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) - @test domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) - - @test range_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,4,2,4) - @test domain_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,3,4) - - @test range_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,4,2,3) - @test domain_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,2,3,2,3) - - @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) - @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) + @testset "Constructors" begin + @test InflatedTensorMapping(I(3,2), A, I(4)) isa TensorMapping{Float64, 4, 4} + @test InflatedTensorMapping(I(3,2), B, I(4)) isa TensorMapping{Float64, 5, 4} + @test InflatedTensorMapping(I(3), C, I(2,3)) isa TensorMapping{Float64, 4, 5} + @test InflatedTensorMapping(C, I(2,3)) isa TensorMapping{Float64, 3, 4} + @test InflatedTensorMapping(I(3), C) isa TensorMapping{Float64, 2, 3} + @test InflatedTensorMapping(I(3), I(2,3)) isa TensorMapping{Float64, 3, 3} + end - # 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) + @testset "Range and domain size" begin + @test range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) + @test domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) - # 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 range_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,4,2,4) + @test domain_size(InflatedTensorMapping(I(3,2), B, I(4))) == (3,2,3,4) - # 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) + @test range_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,4,2,3) + @test domain_size(InflatedTensorMapping(I(3), C, I(2,3))) == (3,2,3,2,3) - struct ScalingOperator{T,D} <: TensorMapping{T,D,D} - λ::T - size::NTuple{D,Int} + @inferred range_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,4,4) + @inferred domain_size(InflatedTensorMapping(I(3,2), A, I(4))) == (3,2,2,4) end - LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I] - LazyTensors.range_size(m::ScalingOperator) = m.size - LazyTensors.domain_size(m::ScalingOperator) = m.size + @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) + + # 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) - tm = InflatedTensorMapping(I(2,3),ScalingOperator(2.0, (3,2)),I(3,4)) - v = rand(domain_size(tm)...) + # 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) + + @testset "Inference of application" begin + struct ScalingOperator{T,D} <: TensorMapping{T,D,D} + λ::T + size::NTuple{D,Int} + end - @inferred LazyTensors.split_index(tm,1,2,3,2,2,4) - @inferred apply(tm,v,Index{Unknown}.((1,2,3,2,2,4))...) - @inferred (tm*v)[1,2,3,2,2,4] + LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I] + LazyTensors.range_size(m::ScalingOperator) = m.size + LazyTensors.domain_size(m::ScalingOperator) = m.size + + tm = InflatedTensorMapping(I(2,3),ScalingOperator(2.0, (3,2)),I(3,4)) + v = rand(domain_size(tm)...) + + @inferred LazyTensors.split_index(tm,1,2,3,2,2,4) + @inferred apply(tm,v,Index{Unknown}.((1,2,3,2,2,4))...) + @inferred (tm*v)[1,2,3,2,2,4] + end + end @testset "InflatedTensorMapping of InflatedTensorMapping" begin A = ScalingOperator(2.0,(2,3)) @@ -405,7 +413,6 @@ @test InflatedTensorMapping(I(2), I(2), I(2)) isa InflatedTensorMapping # The constructor should always return its type. end - end @testset "slice_tuple" begin