From 18b9620682e52c6bbe46c420464f269dcd3b239d Mon Sep 17 00:00:00 2001 From: Jofre Date: Tue, 1 Aug 2023 09:00:42 +0200 Subject: [PATCH] Add tensors test --- test/MatrixProductOperator_test.jl | 16 ++++++++++++++++ test/MatrixProductState_test.jl | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/test/MatrixProductOperator_test.jl b/test/MatrixProductOperator_test.jl index 774ec9bc..fed0e2ee 100644 --- a/test/MatrixProductOperator_test.jl +++ b/test/MatrixProductOperator_test.jl @@ -76,6 +76,14 @@ only(select(ψ, last(ψ.interlayer)[3])).meta[:alias][:l] end end + + @testset "tensors" begin + arrays = [rand(1, 2, 2), rand(1, 1, 2, 2), rand(1, 2, 2)] + ψ = MatrixProduct{Operator,Open}(arrays, order = (:l, :r, :i, :o)) + + @test tensors(ψ, 1) isa Tensor + @test size(tensors(ψ)) |> first == length(ψ) == 3 + end end @testset "`Periodic` boundary" begin @@ -131,6 +139,14 @@ @test only(select(ψ, first(ψ.interlayer)[3])).meta[:alias][:r] === only(select(ψ, first(ψ.interlayer)[1])).meta[:alias][:l] end + + @testset "tensors" begin + arrays = [rand(1, 1, 2, 2), rand(1, 1, 2, 2), rand(1, 1, 2, 2)] + ψ = MatrixProduct{Operator,Periodic}(arrays, order = (:l, :r, :i, :o)) + + @test tensors(ψ, 1) isa Tensor + @test size(tensors(ψ)) |> first == length(ψ) == 3 + end end end end diff --git a/test/MatrixProductState_test.jl b/test/MatrixProductState_test.jl index f723e949..446f77e5 100644 --- a/test/MatrixProductState_test.jl +++ b/test/MatrixProductState_test.jl @@ -80,6 +80,14 @@ @test tensors(ψ, 1).meta[:alias][:r] === tensors(ψ, 2).meta[:alias][:l] @test tensors(ψ, 2).meta[:alias][:r] === tensors(ψ, 3).meta[:alias][:l] end + + @testset "tensors" begin + arrays = [rand(1, 2), rand(1, 1, 2), rand(1, 2)] + ψ = MatrixProduct{State,Open}(arrays, order = (:l, :r, :o)) + + @test tensors(ψ, 1) isa Tensor + @test size(tensors(ψ)) |> first == length(ψ) == 3 + end end end @@ -128,6 +136,14 @@ @test tensors(ψ, 2).meta[:alias][:r] === tensors(ψ, 3).meta[:alias][:l] @test tensors(ψ, 3).meta[:alias][:r] === tensors(ψ, 1).meta[:alias][:l] end + + @testset "tensors" begin + arrays = [rand(1, 1, 2), rand(1, 1, 2), rand(1, 1, 2)] + ψ = MatrixProduct{State,Periodic}(arrays, order = (:l, :r, :o)) + + @test tensors(ψ, 1) isa Tensor + @test size(tensors(ψ)) |> first == length(ψ) == 3 + end end end end