Mercurial > repos > public > sbplib_julia
diff test/LazyTensors/lazy_tensor_operations_test.jl @ 988:83046af6143a
Merge feature/tensormapping_application_promotion
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 16 Mar 2022 18:39:00 +0100 |
parents | 043d13ef8898 |
children | bc384aaade30 bbbc31953367 |
line wrap: on
line diff
--- a/test/LazyTensors/lazy_tensor_operations_test.jl Wed Mar 16 18:32:59 2022 +0100 +++ b/test/LazyTensors/lazy_tensor_operations_test.jl Wed Mar 16 18:39:00 2022 +0100 @@ -36,10 +36,8 @@ m = SizeDoublingMapping{Int, 1, 1}((3,)) v = [0,1,2] - @test m*v isa AbstractVector{Int} @test size(m*v) == 2 .*size(v) @test (m*v)[0] == (:apply,v,(0,)) - @test m*m*v isa AbstractVector{Int} @test (m*m*v)[1] == (:apply,m*v,(1,)) @test (m*m*v)[3] == (:apply,m*v,(3,)) @test (m*m*v)[6] == (:apply,m*v,(6,)) @@ -80,6 +78,43 @@ v = [[1 2];[3 4]] @test m*v == [[2 4];[6 8]] @test (m*v)[2,1] == 6 + + @testset "Type calculation" begin + m = ScalingOperator{Int,1}(2,(3,)) + v = [1.,2.,3.] + @test m*v isa AbstractVector{Float64} + @test m*v == [2.,4.,6.] + @inferred m*v + @inferred (m*v)[1] + + m = ScalingOperator{Int,2}(2,(2,2)) + v = [[1. 2.];[3. 4.]] + @test m*v == [[2. 4.];[6. 8.]] + @test (m*v)[2,1] == 6. + @inferred m*v + @inferred (m*v)[1] + + m = ScalingOperator{ComplexF64,1}(2. +2. *im,(3,)) + v = [1.,2.,3.] + @test m*v isa AbstractVector{ComplexF64} + @test m*v == [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] + @inferred m*v + @inferred (m*v)[1] + + m = ScalingOperator{ComplexF64,1}(1,(3,)) + v = [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] + @test m*v isa AbstractVector{ComplexF64} + @test m*v == [2. + 2. *im, 4. + 4. *im, 6. + 6. *im] + @inferred m*v + @inferred (m*v)[1] + + m = ScalingOperator{Float64,1}(2., (3,)) + v = [[1,2,3], [3,2,1],[1,3,1]] + @test m*v isa AbstractVector{Vector{Float64}} + @test m*v == [[2.,4.,6.], [6.,4.,2.],[2.,6.,2.]] + @inferred m*v + @inferred (m*v)[1] + end end @testset "TensorMapping binary operations" begin @@ -107,6 +142,8 @@ @test range_size(A+B) == range_size(A) == range_size(B) @test domain_size(A+B) == domain_size(A) == domain_size(B) + + @test ((A+B)*ComplexF64[1.1,1.2,1.3])[3] isa ComplexF64 end @@ -129,6 +166,9 @@ v = rand(2) @test (Ã∘B̃)'*v ≈ B'*A'*v rtol=1e-14 + + @test (Ã∘B̃*ComplexF64[1.,2.,3.,4.])[1] isa ComplexF64 + @test ((Ã∘B̃)'*ComplexF64[1.,2.])[1] isa ComplexF64 end @testset "LazyLinearMap" begin @@ -194,6 +234,10 @@ @test I*v == v @test I'*v == v + v = rand(ComplexF64,sz...) + @test I*v == v + @test I'*v == v + @test range_size(I) == sz @test domain_size(I) == sz end @@ -322,6 +366,16 @@ end end + @testset "application to other type" begin + tm = InflatedTensorMapping(I(3,2), A, I(4)) + + v = rand(ComplexF64, domain_size(tm)...) + @test (tm*v)[1,2,3,1] isa ComplexF64 + + v = rand(ComplexF64, domain_size(tm')...) + @test (tm'*v)[1,2,2,1] isa ComplexF64 + end + @testset "Inference of application" begin struct ScalingOperator{T,D} <: TensorMapping{T,D,D} λ::T