comparison test/testLazyTensors.jl @ 433:7327a3e41df0 feature/lazy_identity

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 19 Oct 2020 09:50:16 +0200
parents f24daf573bc6 98ba9b7effd3
children 648a36ebac99
comparison
equal deleted inserted replaced
432:f24daf573bc6 433:7327a3e41df0
211 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2] 211 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2]
212 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3] 212 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3]
213 213
214 end 214 end
215 215
216 @testset "TensorMappingComposition" begin
217 A = rand(2,3)
218 B = rand(3,4)
219
220 Ã = LazyLinearMap(A, (1,), (2,))
221 B̃ = LazyLinearMap(B, (1,), (2,))
222
223 @test Ã∘B̃ isa TensorMappingComposition
224 @test range_size(Ã∘B̃) == (2,)
225 @test domain_size(Ã∘B̃) == (4,)
226 @test_throws DimensionMismatch B̃∘Ã
227
228 # @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)
229
230 v = rand(4)
231 @test Ã∘B̃*v ≈ A*B*v rtol=1e-16
232
233 v = rand(2)
234 @test (Ã∘B̃)'*v ≈ B'*A'*v rtol=1e-16
235 end
236
216 @testset "LazyLinearMap" begin 237 @testset "LazyLinearMap" begin
217 # Test a standard matrix-vector product 238 # Test a standard matrix-vector product
218 # mapping vectors of size 4 to vectors of size 3. 239 # mapping vectors of size 4 to vectors of size 3.
219 A = rand(3,4) 240 A = rand(3,4)
220 Ã = LazyLinearMap(A, (1,), (2,)) 241 Ã = LazyLinearMap(A, (1,), (2,))