1+ using FillArrays: Eye
12using KroneckerArrays: ⊗
2- using LinearAlgebra: Hermitian, I, diag, norm
3+ using LinearAlgebra: Hermitian, I, diag, hermitianpart, norm
34using MatrixAlgebraKit:
45 eig_full,
56 eig_trunc,
@@ -23,28 +24,35 @@ using MatrixAlgebraKit:
2324 svd_vals
2425using Test: @test , @test_throws , @testset
2526
27+ herm (a) = hermitianpart (a). data
28+
2629@testset " MatrixAlgebraKit" begin
2730 elt = Float32
2831
2932 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
3033 d, v = eig_full (a)
3134 @test a * v ≈ v * d
3235
36+ a = randn (elt, 2 , 2 ) ⊗ Eye (3 )
37+ d, v = eig_full (a)
38+ @test d. b == v. b == Eye (3 )
39+ @test a * v ≈ v * d
40+
3341 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
3442 @test_throws MethodError eig_trunc (a)
3543
3644 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
3745 d = eig_vals (a)
3846 @test d ≈ diag (eig_full (a)[1 ])
3947
40- a = Hermitian (randn (elt, 2 , 2 )) ⊗ Hermitian (randn (elt, 3 , 3 ))
48+ a = herm (randn (elt, 2 , 2 )) ⊗ herm (randn (elt, 3 , 3 ))
4149 d, v = eigh_full (a)
4250 @test a * v ≈ v * d
4351
44- a = Hermitian (randn (elt, 2 , 2 )) ⊗ Hermitian (randn (elt, 3 , 3 ))
52+ a = herm (randn (elt, 2 , 2 )) ⊗ herm (randn (elt, 3 , 3 ))
4553 @test_throws MethodError eigh_trunc (a)
4654
47- a = Hermitian (randn (elt, 2 , 2 )) ⊗ Hermitian (randn (elt, 3 , 3 ))
55+ a = herm (randn (elt, 2 , 2 )) ⊗ herm (randn (elt, 3 , 3 ))
4856 d = eigh_vals (a)
4957 @test d ≈ diag (eigh_full (a)[1 ])
5058
@@ -102,6 +110,11 @@ using Test: @test, @test_throws, @testset
102110 @test collect (u' u) ≈ I
103111 @test collect (v * v' ) ≈ I
104112
113+ a = randn (elt, 2 , 2 ) ⊗ Eye (3 )
114+ u, s, v = svd_compact (a)
115+ @test u * s * v ≈ a
116+ @test u. b == s. b == v. b == Eye (3 )
117+
105118 a = randn (elt, 2 , 2 ) ⊗ randn (elt, 3 , 3 )
106119 u, s, v = svd_full (a)
107120 @test u * s * v ≈ a
0 commit comments