1- using KroneckerArrays: ⊗ , arguments
1+ using KroneckerArrays: ⊗ , arg1, arg2
22using LinearAlgebra: Hermitian, I, diag, hermitianpart, norm
3- using MatrixAlgebraKit:
4- eig_full,
5- eig_trunc,
6- eig_vals,
7- eigh_full,
8- eigh_trunc,
9- eigh_vals,
10- left_null,
11- left_orth,
12- left_polar,
13- lq_compact,
14- lq_full,
15- qr_compact,
16- qr_full,
17- right_null,
18- right_orth,
19- right_polar,
20- svd_compact,
21- svd_full,
22- svd_trunc,
3+ using MatrixAlgebraKit: eig_full, eig_trunc, eig_vals, eigh_full, eigh_trunc,
4+ eigh_vals, left_null, left_orth, left_polar, lq_compact, lq_full, qr_compact,
5+ qr_full, right_null, right_orth, right_polar, svd_compact, svd_full, svd_trunc,
236 svd_vals
247using Test: @test , @test_throws , @testset
258using TestExtras: @constinferred
@@ -31,18 +14,26 @@ herm(a) = parent(hermitianpart(a))
3114
3215 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
3316 d, v = eig_full (a)
34- @test a * v ≈ v * d
17+ av = a * v
18+ vd = v * d
19+ @test arg1 (av) ≈ arg1 (vd)
20+ @test arg2 (av) ≈ arg2 (vd)
3521
3622 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
3723 @test_throws ArgumentError eig_trunc (a)
3824
3925 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
4026 d = eig_vals (a)
41- @test d ≈ diag (eig_full (a)[1 ])
27+ d′ = diag (eig_full (a)[1 ])
28+ @test arg1 (d) ≈ arg1 (d′)
29+ @test arg2 (d) ≈ arg2 (d′)
4230
4331 a = herm (randn (elt, 2 , 2 )) ⊗ herm (randn (elt, 3 , 3 ))
4432 d, v = eigh_full (a)
45- @test a * v ≈ v * d
33+ av = a * v
34+ vd = v * d
35+ @test arg1 (av) ≈ arg1 (vd)
36+ @test arg2 (av) ≈ arg2 (vd)
4637 @test eltype (d) === real (elt)
4738 @test eltype (v) === elt
4839
@@ -56,22 +47,30 @@ herm(a) = parent(hermitianpart(a))
5647
5748 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
5849 u, c = qr_compact (a)
59- @test u * c ≈ a
50+ uc = u * c
51+ @test arg1 (uc) ≈ arg1 (a)
52+ @test arg2 (uc) ≈ arg2 (a)
6053 @test collect (u' u) ≈ I
6154
6255 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
6356 u, c = qr_full (a)
64- @test u * c ≈ a
57+ uc = u * c
58+ @test arg1 (uc) ≈ arg1 (a)
59+ @test arg2 (uc) ≈ arg2 (a)
6560 @test collect (u' u) ≈ I
6661
6762 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
6863 c, u = lq_compact (a)
69- @test c * u ≈ a
64+ cu = c * u
65+ @test arg1 (cu) ≈ arg1 (a)
66+ @test arg2 (cu) ≈ arg2 (a)
7067 @test collect (u * u' ) ≈ I
7168
7269 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
7370 c, u = lq_full (a)
74- @test c * u ≈ a
71+ cu = c * u
72+ @test arg1 (cu) ≈ arg1 (a)
73+ @test arg2 (cu) ≈ arg2 (a)
7574 @test collect (u * u' ) ≈ I
7675
7776 a = randn (elt, 3 , 2 ) ⊗ randn (elt, 4 , 3 )
@@ -84,27 +83,37 @@ herm(a) = parent(hermitianpart(a))
8483
8584 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
8685 u, c = left_orth (a)
87- @test u * c ≈ a
86+ uc = u * c
87+ @test arg1 (uc) ≈ arg1 (a)
88+ @test arg2 (uc) ≈ arg2 (a)
8889 @test collect (u' u) ≈ I
8990
9091 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
9192 c, u = right_orth (a)
92- @test c * u ≈ a
93+ cu = c * u
94+ @test arg1 (cu) ≈ arg1 (a)
95+ @test arg2 (cu) ≈ arg2 (a)
9396 @test collect (u * u' ) ≈ I
9497
9598 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
9699 u, c = left_polar (a)
97- @test u * c ≈ a
100+ uc = u * c
101+ @test arg1 (uc) ≈ arg1 (a)
102+ @test arg2 (uc) ≈ arg2 (a)
98103 @test collect (u' u) ≈ I
99104
100105 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
101106 c, u = right_polar (a)
102- @test c * u ≈ a
107+ cu = c * u
108+ @test arg1 (cu) ≈ arg1 (a)
109+ @test arg2 (cu) ≈ arg2 (a)
103110 @test collect (u * u' ) ≈ I
104111
105112 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
106113 u, s, v = svd_compact (a)
107- @test u * s * v ≈ a
114+ usv = u * s * v
115+ @test arg1 (usv) ≈ arg1 (a)
116+ @test arg2 (usv) ≈ arg2 (a)
108117 @test eltype (u) === elt
109118 @test eltype (s) === real (elt)
110119 @test eltype (v) === elt
@@ -113,7 +122,9 @@ herm(a) = parent(hermitianpart(a))
113122
114123 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
115124 u, s, v = svd_full (a)
116- @test u * s * v ≈ a
125+ usv = u * s * v
126+ @test arg1 (usv) ≈ arg1 (a)
127+ @test arg2 (usv) ≈ arg2 (a)
117128 @test eltype (u) === elt
118129 @test eltype (s) === real (elt)
119130 @test eltype (v) === elt
@@ -125,5 +136,7 @@ herm(a) = parent(hermitianpart(a))
125136
126137 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
127138 s = svd_vals (a)
128- @test s ≈ diag (svd_compact (a)[2 ])
139+ s′ = diag (svd_compact (a)[2 ])
140+ @test arg1 (s) ≈ arg1 (s′)
141+ @test arg2 (s) ≈ arg2 (s′)
129142end
0 commit comments