comparison test/testLazyTensors.jl @ 436:cffdac9c612d bugfix/tensor_application_multiplication

Close branch before merge
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 19 Oct 2020 20:54:23 +0200
parents 3796e296fe64 6737e769a1ca
children 00c317c9ccfb
comparison
equal deleted inserted replaced
422:f0d6906d8937 436:cffdac9c612d
212 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2] 212 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2]
213 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3] 213 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3]
214 214
215 end 215 end
216 216
217 @testset "TensorMappingComposition" begin
218 A = rand(2,3)
219 B = rand(3,4)
220
221 Ã = LazyLinearMap(A, (1,), (2,))
222 B̃ = LazyLinearMap(B, (1,), (2,))
223
224 @test Ã∘B̃ isa TensorMappingComposition
225 @test range_size(Ã∘B̃) == (2,)
226 @test domain_size(Ã∘B̃) == (4,)
227 @test_throws DimensionMismatch B̃∘Ã
228
229 # @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)
230
231 v = rand(4)
232 @test Ã∘B̃*v ≈ A*B*v rtol=1e-14
233
234 v = rand(2)
235 @test (Ã∘B̃)'*v ≈ B'*A'*v rtol=1e-14
236 end
237
217 @testset "LazyLinearMap" begin 238 @testset "LazyLinearMap" begin
218 # Test a standard matrix-vector product 239 # Test a standard matrix-vector product
219 # mapping vectors of size 4 to vectors of size 3. 240 # mapping vectors of size 4 to vectors of size 3.
220 A = rand(3,4) 241 A = rand(3,4)
221 Ã = LazyLinearMap(A, (1,), (2,)) 242 Ã = LazyLinearMap(A, (1,), (2,))