comparison test/LazyTensors/lazy_tensor_operations_test.jl @ 1006:d9476fede83d refactor/lazy_tensors

Add check methods for range size
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 20 Mar 2022 22:22:32 +0100
parents becd95ba0fce
children f7a718bcb4da
comparison
equal deleted inserted replaced
1005:becd95ba0fce 1006:d9476fede83d
80 @test_throws MethodError m*ones(Int,2,2) 80 @test_throws MethodError m*ones(Int,2,2)
81 @test_throws MethodError m*m*v 81 @test_throws MethodError m*m*v
82 end 82 end
83 83
84 @testset "Error on unmatched sizes" begin 84 @testset "Error on unmatched sizes" begin
85 @test_throws SizeMismatch ScalingTensor(2,(2,))*ones(3) 85 @test_throws DomainSizeMismatch ScalingTensor(2,(2,))*ones(3)
86 @test_throws SizeMismatch ScalingTensor(2,(2,))*ScalingTensor(2,(3,))*ones(3) 86 @test_throws DomainSizeMismatch ScalingTensor(2,(2,))*ScalingTensor(2,(3,))*ones(3)
87 end 87 end
88 88
89 89
90 @testset "Type calculation" begin 90 @testset "Type calculation" begin
91 m = ScalingTensor(2,(3,)) 91 m = ScalingTensor(2,(3,))
138 for i ∈ eachindex(v) 138 for i ∈ eachindex(v)
139 @test ((A-B)*v)[i] == 2*v[i] - 3*v[i] 139 @test ((A-B)*v)[i] == 2*v[i] - 3*v[i]
140 end 140 end
141 141
142 # TODO: Test with size changing tm 142 # TODO: Test with size changing tm
143 # TODO: Test for mismatch in dimensions (SizeMismatch?) 143 # TODO: Test for mismatch in dimensions (DomainSizeMismatch?)
144 144
145 @test range_size(A+B) == range_size(A) == range_size(B) 145 @test range_size(A+B) == range_size(A) == range_size(B)
146 @test domain_size(A+B) == domain_size(A) == domain_size(B) 146 @test domain_size(A+B) == domain_size(A) == domain_size(B)
147 147
148 @test ((A+B)*ComplexF64[1.1,1.2,1.3])[3] isa ComplexF64 148 @test ((A+B)*ComplexF64[1.1,1.2,1.3])[3] isa ComplexF64
157 B̃ = LazyLinearMap(B, (1,), (2,)) 157 B̃ = LazyLinearMap(B, (1,), (2,))
158 158
159 @test Ã∘B̃ isa LazyTensorComposition 159 @test Ã∘B̃ isa LazyTensorComposition
160 @test range_size(Ã∘B̃) == (2,) 160 @test range_size(Ã∘B̃) == (2,)
161 @test domain_size(Ã∘B̃) == (4,) 161 @test domain_size(Ã∘B̃) == (4,)
162 @test_throws SizeMismatch B̃∘Ã 162 @test_throws DomainSizeMismatch B̃∘Ã
163 163
164 # @test @inbounds B̃∘Ã # Should not error even though dimensions don't match. (Since ]test runs with forced boundschecking this is currently not testable 2020-10-16) 164 # @test @inbounds B̃∘Ã # Should not error even though dimensions don't match. (Since ]test runs with forced boundschecking this is currently not testable 2020-10-16)
165 165
166 v = rand(4) 166 v = rand(4)
167 @test Ã∘B̃*v ≈ A*B*v rtol=1e-14 167 @test Ã∘B̃*v ≈ A*B*v rtol=1e-14