From 8284bf6c45eabe29454b279809098290bcb95d44 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Thu, 5 Oct 2023 18:27:56 +0200 Subject: [PATCH] Formatter --- src/sectors/sectors.jl | 3 +- test/ad.jl | 8 +- test/choosetests.jl | 16 +-- test/fusiontrees.jl | 254 +++++++++++++++++++++-------------------- test/planar.jl | 9 +- test/spaces.jl | 92 +++++++-------- test/tensors.jl | 112 +++++++++--------- test/utility.jl | 2 +- 8 files changed, 252 insertions(+), 244 deletions(-) diff --git a/src/sectors/sectors.jl b/src/sectors/sectors.jl index a80ecaa9..d633bda3 100644 --- a/src/sectors/sectors.jl +++ b/src/sectors/sectors.jl @@ -397,7 +397,8 @@ function pentagon_equation(a::I, b::I, c::I, d::I; kwargs...) where {I<:Sector} end function hexagon_equation(a::I, b::I, c::I; kwargs...) where {I<:Sector} - BraidingStyle(I) isa NoBraiding && throw(ArgumentError("Hexagon equation only defined for sectors with braiding")) + BraidingStyle(I) isa NoBraiding && + throw(ArgumentError("Hexagon equation only defined for sectors with braiding")) for e in ⊗(c, a), f in ⊗(c, b) for d in intersect(⊗(e, b), ⊗(a, f)) if FusionStyle(I) isa MultiplicityFreeFusion diff --git a/test/ad.jl b/test/ad.jl index 628a1868..cc446f6e 100644 --- a/test/ad.jl +++ b/test/ad.jl @@ -201,21 +201,21 @@ Vlist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'), β = randn(T) C = _randomize!(tensoralloc_contract(T, pC, A, pA, :N, - B, pB, :N, false)) + B, pB, :N, false)) test_rrule(tensorcontract!, C, pC, A, pA, :N, B, pB, :N, α, β; atol, rtol) A2 = TensorMap(randn, T, V[1]' ⊗ V[2]' ← V[3]' ⊗ V[4]' ⊗ V[5]') C = _randomize!(tensoralloc_contract(T, pC, A2, pA, :C, - B, pB, :N, false)) + B, pB, :N, false)) test_rrule(tensorcontract!, C, pC, A2, pA, :C, B, pB, :N, α, β; atol, rtol) B2 = TensorMap(randn, T, V[3]' ⊗ V[1] ← V[2]') C = _randomize!(tensoralloc_contract(T, pC, A, pA, :N, - B2, pB, :C, false)) + B2, pB, :C, false)) test_rrule(tensorcontract!, C, pC, A, pA, :N, B2, pB, :C, α, β; atol, rtol) C = _randomize!(tensoralloc_contract(T, pC, A2, pA, :C, - B2, pB, :C, false)) + B2, pB, :C, false)) test_rrule(tensorcontract!, C, pC, A2, pA, :C, B2, pB, :C, α, β; atol, rtol) end diff --git a/test/choosetests.jl b/test/choosetests.jl index 045b0e21..931fa14d 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -4,11 +4,11 @@ const TESTNAMES = ["sectors", "spaces", "fusiontrees", "tensors", "planar", "ad" const TESTGROUPS = String[] const SECTORNAMES = ["Trivial", "Z2Irrep", "Z3Irrep", "Z4Irrep", "U1Irrep", "CU1Irrep", - "SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon", - "FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep", - "FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep", - "NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}", - "Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"] + "SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon", + "FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep", + "FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep", + "NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}", + "Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"] const DEFAULT_SECTORNAMES = try if ENV["CI"] == "true" println("Detected CI environment") @@ -16,9 +16,11 @@ const DEFAULT_SECTORNAMES = try ["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "U1Irrep", "FermionNumber", "CU1Irrep", "SU2Irrep"] elseif Sys.isapple() - ["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber", "FermionSpin"] + ["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber", + "FermionSpin"] else - ["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep", "FermionSpin"] + ["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep", + "FermionSpin"] end else SECTORNAMES diff --git a/test/fusiontrees.jl b/test/fusiontrees.jl index fc033149..6230c96f 100644 --- a/test/fusiontrees.jl +++ b/test/fusiontrees.jl @@ -176,93 +176,93 @@ using TensorKit: ProductSector end end BraidingStyle(I) isa NoBraiding || @testset "elementy artin braid" begin - N = length(out) - isdual = ntuple(n -> rand(Bool), N) - for in in ⊗(out...) - for i in 1:(N - 1) - for f in fusiontrees(out, in, isdual) - d1 = @constinferred TensorKit.artin_braid(f, i) - @test norm(values(d1)) ≈ 1 - d2 = empty(d1) - for (f1, coeff1) in d1 - for (f2, coeff2) in TensorKit.artin_braid(f1, i; inv=true) - d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 - end - end - for (f2, coeff2) in d2 - if f2 == f - @test coeff2 ≈ 1 - else - @test isapprox(coeff2, 0; atol=1e-12, rtol=1e-12) - end - end - end - end - end + N = length(out) + isdual = ntuple(n -> rand(Bool), N) + for in in ⊗(out...) + for i in 1:(N - 1) + for f in fusiontrees(out, in, isdual) + d1 = @constinferred TensorKit.artin_braid(f, i) + @test norm(values(d1)) ≈ 1 + d2 = empty(d1) + for (f1, coeff1) in d1 + for (f2, coeff2) in TensorKit.artin_braid(f1, i; inv=true) + d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 + end + end + for (f2, coeff2) in d2 + if f2 == f + @test coeff2 ≈ 1 + else + @test isapprox(coeff2, 0; atol=1e-12, rtol=1e-12) + end + end + end + end + end - f = rand(collect(it)) - d1 = TensorKit.artin_braid(f, 2) - d2 = empty(d1) - for (f1, coeff1) in d1 - for (f2, coeff2) in TensorKit.artin_braid(f1, 3) - d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 - end - end - d1 = d2 - d2 = empty(d1) - for (f1, coeff1) in d1 - for (f2, coeff2) in TensorKit.artin_braid(f1, 3; inv=true) - d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 - end - end - d1 = d2 - d2 = empty(d1) - for (f1, coeff1) in d1 - for (f2, coeff2) in TensorKit.artin_braid(f1, 2; inv=true) - d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 - end - end - d1 = d2 - for (f1, coeff1) in d1 - if f1 == f - @test coeff1 ≈ 1 - else - @test isapprox(coeff1, 0; atol=1e-12, rtol=1e-12) - end - end - end + f = rand(collect(it)) + d1 = TensorKit.artin_braid(f, 2) + d2 = empty(d1) + for (f1, coeff1) in d1 + for (f2, coeff2) in TensorKit.artin_braid(f1, 3) + d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 + end + end + d1 = d2 + d2 = empty(d1) + for (f1, coeff1) in d1 + for (f2, coeff2) in TensorKit.artin_braid(f1, 3; inv=true) + d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 + end + end + d1 = d2 + d2 = empty(d1) + for (f1, coeff1) in d1 + for (f2, coeff2) in TensorKit.artin_braid(f1, 2; inv=true) + d2[f2] = get(d2, f2, zero(coeff1)) + coeff2 * coeff1 + end + end + d1 = d2 + for (f1, coeff1) in d1 + if f1 == f + @test coeff1 ≈ 1 + else + @test isapprox(coeff1, 0; atol=1e-12, rtol=1e-12) + end + end + end BraidingStyle(I) isa NoBraiding || @testset "braiding and permuting" begin - f = rand(collect(fusiontrees(out, in, isdual))) - p = tuple(randperm(N)...) - ip = invperm(p) + f = rand(collect(fusiontrees(out, in, isdual))) + p = tuple(randperm(N)...) + ip = invperm(p) - levels = ntuple(identity, N) - d = @constinferred braid(f, levels, p) - d2 = Dict{typeof(f),valtype(d)}() - levels2 = p - for (f2, coeff) in d - for (f1, coeff2) in braid(f2, levels2, ip) - d2[f1] = get(d2, f1, zero(coeff)) + coeff2 * coeff - end - end - for (f1, coeff2) in d2 - if f1 == f - @test coeff2 ≈ 1 - else - @test isapprox(coeff2, 0; atol=1e-12, rtol=1e-12) - end - end + levels = ntuple(identity, N) + d = @constinferred braid(f, levels, p) + d2 = Dict{typeof(f),valtype(d)}() + levels2 = p + for (f2, coeff) in d + for (f1, coeff2) in braid(f2, levels2, ip) + d2[f1] = get(d2, f1, zero(coeff)) + coeff2 * coeff + end + end + for (f1, coeff2) in d2 + if f1 == f + @test coeff2 ≈ 1 + else + @test isapprox(coeff2, 0; atol=1e-12, rtol=1e-12) + end + end - if (BraidingStyle(I) isa Bosonic) && hasfusiontensor(I) - Af = convert(Array, f) - Afp = permutedims(Af, (p..., N + 1)) - Afp2 = zero(Afp) - for (f1, coeff) in d - Afp2 .+= coeff .* convert(Array, f1) - end - @test Afp ≈ Afp2 - end - end + if (BraidingStyle(I) isa Bosonic) && hasfusiontensor(I) + Af = convert(Array, f) + Afp = permutedims(Af, (p..., N + 1)) + Afp2 = zero(Afp) + for (f1, coeff) in d + Afp2 .+= coeff .* convert(Array, f1) + end + @test Afp ≈ Afp2 + end + end @testset "merging" begin N = 3 @@ -282,51 +282,55 @@ using TensorKit: ProductSector for μ in 1:Nsymbol(in1, in2, c) for (f, coeff) in TensorKit.merge(f1, f2, c, μ)) BraidingStyle(I) isa NoBraiding || for c in in1 ⊗ in2 - R = Rsymbol(in1, in2, c) - for μ in 1:Nsymbol(in1, in2, c) - μ′ = FusionStyle(I) isa GenericFusion ? μ : nothing - trees1 = TensorKit.merge(f1, f2, c, μ′) + R = Rsymbol(in1, in2, c) + for μ in 1:Nsymbol(in1, in2, c) + μ′ = FusionStyle(I) isa GenericFusion ? μ : nothing + trees1 = TensorKit.merge(f1, f2, c, μ′) # test merge and braid interplay - trees2 = Dict{keytype(trees1),complex(valtype(trees1))}() - trees3 = Dict{keytype(trees1),complex(valtype(trees1))}() - for ν in 1:Nsymbol(in2, in1, c) - ν′ = FusionStyle(I) isa GenericFusion ? ν : nothing - for (t, coeff) in TensorKit.merge(f2, f1, c, ν′) - trees2[t] = get(trees2, t, zero(valtype(trees2))) + coeff * R[μ, ν] - end - end - perm = ((N .+ (1:N))..., (1:N)...) - levels = ntuple(identity, 2 * N) - for (t, coeff) in trees1 - for (t′, coeff′) in braid(t, levels, perm) - trees3[t′] = get(trees3, t′, zero(valtype(trees3))) + coeff * coeff′ - end - end - for (t, coeff) in trees3 - coeff′ = get(trees2, t, zero(coeff)) - @test isapprox(coeff, coeff′; atol=1e-12, rtol=1e-12) - end + trees2 = Dict{keytype(trees1),complex(valtype(trees1))}() + trees3 = Dict{keytype(trees1),complex(valtype(trees1))}() + for ν in 1:Nsymbol(in2, in1, c) + ν′ = FusionStyle(I) isa GenericFusion ? ν : nothing + for (t, coeff) in TensorKit.merge(f2, f1, c, ν′) + trees2[t] = get(trees2, t, zero(valtype(trees2))) + + coeff * R[μ, ν] + end + end + perm = ((N .+ (1:N))..., (1:N)...) + levels = ntuple(identity, 2 * N) + for (t, coeff) in trees1 + for (t′, coeff′) in braid(t, levels, perm) + trees3[t′] = get(trees3, t′, zero(valtype(trees3))) + + coeff * coeff′ + end + end + for (t, coeff) in trees3 + coeff′ = get(trees2, t, zero(coeff)) + @test isapprox(coeff, coeff′; atol=1e-12, rtol=1e-12) + end # test via conversion - if (BraidingStyle(I) isa Bosonic) && hasfusiontensor(I) - Af1 = convert(Array, f1) - Af2 = convert(Array, f2) - Af0 = convert(Array, - FusionTree((f1.coupled, f2.coupled), c, (false, false), - (), (μ,))) - _Af = TensorOperations.tensorcontract(1:(N + 2), Af1, [1:N; -1], - Af0, [-1; N + 1; N + 2]) - Af = TensorOperations.tensorcontract(1:(2N + 1), Af2, [N .+ (1:N); -1], - _Af, [1:N; -1; 2N + 1]) - Af′ = zero(Af) - for (f, coeff) in trees1 - Af′ .+= coeff .* convert(Array, f) - end - @test Af ≈ Af′ - end - end - end + if (BraidingStyle(I) isa Bosonic) && hasfusiontensor(I) + Af1 = convert(Array, f1) + Af2 = convert(Array, f2) + Af0 = convert(Array, + FusionTree((f1.coupled, f2.coupled), c, + (false, false), + (), (μ,))) + _Af = TensorOperations.tensorcontract(1:(N + 2), Af1, [1:N; -1], + Af0, [-1; N + 1; N + 2]) + Af = TensorOperations.tensorcontract(1:(2N + 1), Af2, + [N .+ (1:N); -1], + _Af, [1:N; -1; 2N + 1]) + Af′ = zero(Af) + for (f, coeff) in trees1 + Af′ .+= coeff .* convert(Array, f) + end + @test Af ≈ Af′ + end + end + end end if I <: ProductSector @@ -531,6 +535,6 @@ using TensorKit: ProductSector end end end - + println("Finished tests for $Istr.") end diff --git a/test/planar.jl b/test/planar.jl index 558d56a2..a4a91cdc 100644 --- a/test/planar.jl +++ b/test/planar.jl @@ -2,7 +2,8 @@ println("------------------------------------") println("Planar") println("------------------------------------") -using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor, SymmetricBraiding +using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor, + SymmetricBraiding using TensorOperations @testset "$(TensorKit.type_repr(I))" verbose = true for I in sectorlist @@ -52,7 +53,7 @@ using TensorOperations planarcontract!(C′, A′, pA, B′, pB, pAB, true, true) end end - + @testset "BraidingTensor conversion" begin for (V1, V2) in [(V1, V1), (V1', V1), (V1, V1'), (V1', V1')] τ = BraidingTensor(V1, V2) @@ -72,7 +73,7 @@ using TensorOperations end end end - + t = TensorMap(randn, V1 * V1' * V1' * V1, V1 * V1') ττ = copy(BraidingTensor(V1, V1')) @@ -312,4 +313,4 @@ end end @test C ≈ C′ end -end \ No newline at end of file +end diff --git a/test/spaces.jl b/test/spaces.jl index 269d775d..1dc5dfe9 100644 --- a/test/spaces.jl +++ b/test/spaces.jl @@ -87,56 +87,56 @@ end @test @constinferred(supremum(V', ℝ^3)) == ℝ^3 end - @timedtestset "ElementarySpace: ComplexSpace" begin - d = 2 - V = ℂ^d - @test eval(Meta.parse(sprint(show, V))) == V - @test eval(Meta.parse(sprint(show, V'))) == V' - @test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V) - @test isa(V, VectorSpace) - @test isa(V, ElementarySpace) - @test isa(InnerProductStyle(V), HasInnerProduct) - @test isa(InnerProductStyle(V), EuclideanProduct) - @test isa(V, ComplexSpace) - @test !isdual(V) - @test isdual(V') - @test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d)) - @test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V') - @test @constinferred(dual(V)) == @constinferred(conj(V)) == - @constinferred(adjoint(V)) != V - @test @constinferred(field(V)) == ℂ - @test @constinferred(sectortype(V)) == Trivial - @test @constinferred(sectortype(V)) == Trivial - @test ((@constinferred sectors(V))...,) == (Trivial(),) - @test length(sectors(V)) == 1 - @test @constinferred(TensorKit.hassector(V, Trivial())) - @test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial())) - @test dim(@constinferred(typeof(V)())) == 0 - @test (sectors(typeof(V)())...,) == () - @test @constinferred(TensorKit.axes(V)) == Base.OneTo(d) - @test ℂ^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d) - W = @constinferred ℂ^1 - @test @constinferred(oneunit(V)) == W == oneunit(typeof(V)) - @test @constinferred(⊕(V, V)) == ℂ^(2d) - @test_throws SpaceMismatch (⊕(V, V')) +@timedtestset "ElementarySpace: ComplexSpace" begin + d = 2 + V = ℂ^d + @test eval(Meta.parse(sprint(show, V))) == V + @test eval(Meta.parse(sprint(show, V'))) == V' + @test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V) + @test isa(V, VectorSpace) + @test isa(V, ElementarySpace) + @test isa(InnerProductStyle(V), HasInnerProduct) + @test isa(InnerProductStyle(V), EuclideanProduct) + @test isa(V, ComplexSpace) + @test !isdual(V) + @test isdual(V') + @test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d)) + @test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V') + @test @constinferred(dual(V)) == @constinferred(conj(V)) == + @constinferred(adjoint(V)) != V + @test @constinferred(field(V)) == ℂ + @test @constinferred(sectortype(V)) == Trivial + @test @constinferred(sectortype(V)) == Trivial + @test ((@constinferred sectors(V))...,) == (Trivial(),) + @test length(sectors(V)) == 1 + @test @constinferred(TensorKit.hassector(V, Trivial())) + @test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial())) + @test dim(@constinferred(typeof(V)())) == 0 + @test (sectors(typeof(V)())...,) == () + @test @constinferred(TensorKit.axes(V)) == Base.OneTo(d) + @test ℂ^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d) + W = @constinferred ℂ^1 + @test @constinferred(oneunit(V)) == W == oneunit(typeof(V)) + @test @constinferred(⊕(V, V)) == ℂ^(2d) + @test_throws SpaceMismatch (⊕(V, V')) promote_except = ErrorException("promotion of types $(typeof(ℝ^d)) and " * "$(typeof(ℂ^d)) failed to change any arguments") @test_throws promote_except (⊕(ℝ^d, ℂ^d)) @test_throws promote_except (⊗(ℝ^d, ℂ^d)) - @test @constinferred(⊕(V, V)) == ℂ^(2d) - @test @constinferred(⊕(V, oneunit(V))) == ℂ^(d + 1) - @test @constinferred(⊕(V, V, V, V)) == ℂ^(4d) - @test @constinferred(fuse(V, V)) == ℂ^(d^2) - @test @constinferred(fuse(V, V', V, V')) == ℂ^(d^4) - @test @constinferred(flip(V)) == V' - @test flip(V) ≅ V - @test flip(V) ≾ V - @test flip(V) ≿ V - @test V ≺ ⊕(V, V) - @test !(V ≻ ⊕(V, V)) - @test @constinferred(infimum(V, ℂ^3)) == V - @test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3) - end + @test @constinferred(⊕(V, V)) == ℂ^(2d) + @test @constinferred(⊕(V, oneunit(V))) == ℂ^(d + 1) + @test @constinferred(⊕(V, V, V, V)) == ℂ^(4d) + @test @constinferred(fuse(V, V)) == ℂ^(d^2) + @test @constinferred(fuse(V, V', V, V')) == ℂ^(d^4) + @test @constinferred(flip(V)) == V' + @test flip(V) ≅ V + @test flip(V) ≾ V + @test flip(V) ≿ V + @test V ≺ ⊕(V, V) + @test !(V ≻ ⊕(V, V)) + @test @constinferred(infimum(V, ℂ^3)) == V + @test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3) +end @testset "GeneralSpace" begin d = 2 diff --git a/test/tensors.jl b/test/tensors.jl index 1ebfb0e2..cc7f9184 100644 --- a/test/tensors.jl +++ b/test/tensors.jl @@ -379,67 +379,67 @@ end end end - t = Tensor(rand, T, V1 ⊗ V1' ⊗ V2 ⊗ V2') - @testset "eig and isposdef" begin - D, V = eigen(t, ((1, 3), (2, 4))) - t2 = permute(t, ((1, 3), (2, 4))) - @test t2 * V ≈ V * D - @test !isposdef(t2) # unlikely for non-hermitian map - t2 = (t2 + t2') - D, V = eigen(t2) - VdV = V' * V - @test VdV ≈ one(VdV) - D̃, Ṽ = @constinferred eigh(t2) - @test D ≈ D̃ - @test V ≈ Ṽ - λ = minimum(minimum(real(LinearAlgebra.diag(b))) - for (c, b) in blocks(D)) - @test isposdef(t2) == isposdef(λ) - @test isposdef(t2 - λ * one(t2) + 0.1 * one(t2)) - @test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2)) - end + t = Tensor(rand, T, V1 ⊗ V1' ⊗ V2 ⊗ V2') + @testset "eig and isposdef" begin + D, V = eigen(t, ((1, 3), (2, 4))) + t2 = permute(t, ((1, 3), (2, 4))) + @test t2 * V ≈ V * D + @test !isposdef(t2) # unlikely for non-hermitian map + t2 = (t2 + t2') + D, V = eigen(t2) + VdV = V' * V + @test VdV ≈ one(VdV) + D̃, Ṽ = @constinferred eigh(t2) + @test D ≈ D̃ + @test V ≈ Ṽ + λ = minimum(minimum(real(LinearAlgebra.diag(b))) + for (c, b) in blocks(D)) + @test isposdef(t2) == isposdef(λ) + @test isposdef(t2 - λ * one(t2) + 0.1 * one(t2)) + @test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2)) end end - @timedtestset "Tensor truncation" begin - for T in (Float32, ComplexF64) - for p in (1, 2, 3, Inf) - # Test both a normal tensor and an adjoint one. - ts = (TensorMap(randn, T, V1 ⊗ V2 ⊗ V3, V4 ⊗ V5), - TensorMap(randn, T, V4 ⊗ V5, V1 ⊗ V2 ⊗ V3)') - for t in ts - U₀, S₀, V₀, = tsvd(t) - t = rmul!(t, 1 / norm(S₀, p)) - U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p) - # @show p, ϵ - # @show domain(S) - # @test min(space(S,1), space(S₀,1)) != space(S₀,1) - U′, S′, V′, ϵ′ = tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p) - @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) - U′, S′, V′, ϵ′ = tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))), - p=p) - @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) - U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p) - @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) - # results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently - U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p) - # @show p, ϵ - # @show domain(S) - # @test min(space(S,1), space(S₀,1)) != space(S₀,1) - U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p) - @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) - end + end + @timedtestset "Tensor truncation" begin + for T in (Float32, ComplexF64) + for p in (1, 2, 3, Inf) + # Test both a normal tensor and an adjoint one. + ts = (TensorMap(randn, T, V1 ⊗ V2 ⊗ V3, V4 ⊗ V5), + TensorMap(randn, T, V4 ⊗ V5, V1 ⊗ V2 ⊗ V3)') + for t in ts + U₀, S₀, V₀, = tsvd(t) + t = rmul!(t, 1 / norm(S₀, p)) + U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p) + # @show p, ϵ + # @show domain(S) + # @test min(space(S,1), space(S₀,1)) != space(S₀,1) + U′, S′, V′, ϵ′ = tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p) + @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) + U′, S′, V′, ϵ′ = tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))), + p=p) + @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) + U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p) + @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) + # results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently + U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p) + # @show p, ϵ + # @show domain(S) + # @test min(space(S,1), space(S₀,1)) != space(S₀,1) + U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p) + @test (U, S, V, ϵ) == (U′, S′, V′, ϵ′) end end end - if hasfusiontensor(I) - @timedtestset "Tensor functions" begin - W = V1 ⊗ V2 - for T in (Float64, ComplexF64) - t = TensorMap(randn, T, W, W) - s = dim(W) - expt = @constinferred exp(t) - @test reshape(convert(Array, expt), (s, s)) ≈ - exp(reshape(convert(Array, t), (s, s))) + end + if hasfusiontensor(I) + @timedtestset "Tensor functions" begin + W = V1 ⊗ V2 + for T in (Float64, ComplexF64) + t = TensorMap(randn, T, W, W) + s = dim(W) + expt = @constinferred exp(t) + @test reshape(convert(Array, expt), (s, s)) ≈ + exp(reshape(convert(Array, t), (s, s))) @test (@constinferred sqrt(t))^2 ≈ t @test reshape(convert(Array, sqrt(t^2)), (s, s)) ≈ diff --git a/test/utility.jl b/test/utility.jl index a6b17a9a..005b9c9b 100644 --- a/test/utility.jl +++ b/test/utility.jl @@ -145,4 +145,4 @@ function force_planar(tsrc::TensorMap{<:GradedSpace}) copyto!(blocks(tdst)[c ⊠ PlanarTrivial()], b) end return tdst -end \ No newline at end of file +end