comparison test/testLazyTensors.jl @ 477:79a88269d7d0 feature/outer_product

Add some tests
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 02 Nov 2020 22:12:24 +0100
parents 1b9af062ba2c
children 2dc2eac27f75
comparison
equal deleted inserted replaced
476:1b9af062ba2c 477:79a88269d7d0
397 @test LazyTensors.flatten_tuple((1,2,(3,(4,5)),6)) == (1,2,3,4,5,6) 397 @test LazyTensors.flatten_tuple((1,2,(3,(4,5)),6)) == (1,2,3,4,5,6)
398 @test LazyTensors.flatten_tuple(((1,2),(3,4),(5,),6)) == (1,2,3,4,5,6) 398 @test LazyTensors.flatten_tuple(((1,2),(3,4),(5,),6)) == (1,2,3,4,5,6)
399 end 399 end
400 400
401 401
402 @testset "LazyIdentityOuterProduct" begin 402 @testset "LazyOuterProduct" begin
403 struct ScalingOperator{T,D} <: TensorMapping{T,D,D} 403 struct ScalingOperator{T,D} <: TensorMapping{T,D,D}
404 λ::T 404 λ::T
405 size::NTuple{D,Int} 405 size::NTuple{D,Int}
406 end 406 end
407 407
428 @test domain_size(ABC) == (5,3,3,2) 428 @test domain_size(ABC) == (5,3,3,2)
429 429
430 @test A⊗B == AB 430 @test A⊗B == AB
431 @test A⊗B⊗C == ABC 431 @test A⊗B⊗C == ABC
432 432
433 # TODO: Include some tests where the domain has different size and dimension 433 A = rand(3,2)
434 434 B = rand(2,4,3)
435 end 435
436 436 v₁ = rand(2,4,3)
437 end 437 v₂ = rand(4,3,2)
438
439 Ã = LazyLinearMap(A,(1,),(2,))
440 B̃ = LazyLinearMap(B,(1,),(2,3))
441
442 ÃB̃ = LazyOuterProduct(Ã,B̃)
443 @tullio ABv[i,k] := A[i,j]*B[k,l,m]*v₁[j,l,m]
444 @test ÃB̃*v₁ ≈ ABv
445
446 B̃Ã = LazyOuterProduct(B̃,Ã)
447 @tullio BAv[k,i] := A[i,j]*B[k,l,m]*v₂[l,m,j]
448 @test B̃Ã*v₂ ≈ BAv
449
450 end
451
452 end