11using Test, TestExtras
22using TensorKit
33using LinearAlgebra: LinearAlgebra
4- using MatrixAlgebraKit: diagview
5-
4+ using MatrixAlgebraKit: defaulttol, diagview
65
76spacelist = factorization_spacelist (fast_tests)
87
@@ -16,15 +15,16 @@ for V in spacelist
1615 println (" ---------------------------------------------------------------" )
1716 @timedtestset " Singular value and polar decompositions with symmetry: $Istr " verbose = true begin
1817 V1, V2, V3, V4, V5 = V
19- W = V1 ⊗ V2
18+ W = V1 ⊗ V2 ⊗ V3
19+ Vd = fuse (V1 ⊗ V2)
2020
2121 @testset " Condition number and rank" begin
2222 for T in eltypes,
2323 t in (
2424 rand (T, W, W), rand (T, W, W)' ,
2525 rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
2626 rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
27- DiagonalTensorMap (rand (T, reduceddim (V1 )), V1 ),
27+ DiagonalTensorMap (rand (T, reduceddim (Vd )), Vd ),
2828 )
2929
3030 d1, d2 = dim (codomain (t)), dim (domain (t))
@@ -62,7 +62,7 @@ for V in spacelist
6262 rand (T, W, W),
6363 rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ),
6464 rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
65- DiagonalTensorMap (rand (T, reduceddim (V1 )), V1 ),
65+ DiagonalTensorMap (rand (T, reduceddim (Vd )), Vd ),
6666 )
6767
6868 @assert domain (t) ≾ codomain (t)
@@ -81,7 +81,7 @@ for V in spacelist
8181 rand (T, W, W),
8282 rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ),
8383 rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
84- DiagonalTensorMap (rand (T, reduceddim (V1 )), V1 ),
84+ DiagonalTensorMap (rand (T, reduceddim (Vd )), Vd ),
8585 )
8686
8787 @assert codomain (t) ≾ domain (t)
@@ -102,7 +102,7 @@ for V in spacelist
102102 rand (T, W, W), rand (T, W, W)' ,
103103 rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
104104 rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
105- DiagonalTensorMap (rand (T, reduceddim (V1 )), V1 ),
105+ DiagonalTensorMap (rand (T, reduceddim (Vd )), Vd ),
106106 )
107107
108108 u, s, vᴴ = @constinferred svd_full (t)
@@ -131,21 +131,23 @@ for V in spacelist
131131 @test c * vᴴ ≈ t
132132 @test isisometric (vᴴ; side = :right )
133133
134+ atol = norm (t) * defaulttol (T) # tol used by `:svd` left_null/right_null
135+
134136 N = @constinferred left_null (t; alg = :svd )
135137 @test isisometric (N)
136- @test norm (N' * t) ≈ 0 atol = 100 * eps ( norm (t))
138+ @test norm (N' * t) ≈ 0 atol = atol
137139
138- N = @constinferred left_null (t; trunc = (; atol = 100 * eps ( norm (t)) ))
140+ N = @constinferred left_null (t; trunc = (; atol = 6 * atol ))
139141 @test isisometric (N)
140- @test norm (N' * t) ≈ 0 atol = 100 * eps ( norm (t))
142+ @test norm (N' * t) ≈ 0 atol = 10 * atol
141143
142144 Nᴴ = @constinferred right_null (t; alg = :svd )
143145 @test isisometric (Nᴴ; side = :right )
144- @test norm (t * Nᴴ' ) ≈ 0 atol = 100 * eps ( norm (t))
146+ @test norm (t * Nᴴ' ) ≈ 0 atol = atol
145147
146- Nᴴ = @constinferred right_null (t; trunc = (; atol = 100 * eps ( norm (t)) ))
148+ Nᴴ = @constinferred right_null (t; trunc = (; atol = 6 * atol ))
147149 @test isisometric (Nᴴ; side = :right )
148- @test norm (t * Nᴴ' ) ≈ 0 atol = 100 * eps ( norm (t))
150+ @test norm (t * Nᴴ' ) ≈ 0 atol = 10 * atol
149151 end
150152
151153 # empty tensor
@@ -167,7 +169,7 @@ for V in spacelist
167169 rand (T, W, W), rand (T, W, W)' ,
168170 rand (T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2)' , (V3 ⊗ V4 ⊗ V5))' ,
169171 rand (T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)' ), rand (T, (V1 ⊗ V2 ⊗ V3)' , (V4 ⊗ V5))' ,
170- DiagonalTensorMap (rand (T, reduceddim (V1 )), V1 ),
172+ DiagonalTensorMap (rand (T, reduceddim (Vd )), Vd ),
171173 )
172174
173175 @constinferred normalize! (t)
0 commit comments