3535
3636n = 10
3737
38- # Split n into 2 parts for tests needing two matrices
39- n1 = div (n, 2 )
40- n2 = 2 * n1
41-
4238Random. seed! (1234321 )
4339
4440areal = randn (n,n)/ 2
4541aimg = randn (n,n)/ 2
46- a2real = randn (n,n)/ 2
47- a2img = randn (n,n)/ 2
4842
4943@testset for eltya in (Float32, Float64, ComplexF32, ComplexF64, Int)
5044 aa = eltya == Int ? rand (1 : 7 , n, n) : convert (Matrix{eltya}, eltya <: Complex ? complex .(areal, aimg) : areal)
51- aa2 = eltya == Int ? rand (1 : 7 , n, n) : convert (Matrix{eltya}, eltya <: Complex ? complex .(a2real, a2img) : a2real)
5245 asym = aa' + aa # symmetric indefinite
53- apd = aa' * aa # symmetric positive-definite
54- for (a, a2) in ((aa, aa2), (view (aa, 1 : n, 1 : n), view (aa2, 1 : n, 1 : n)))
55- ε = εa = eps (abs (float (one (eltya))))
56-
46+ for a in (aa, view (aa, 1 : n, 1 : n))
5747 usv = svd (a)
5848 @testset " singular value decomposition" begin
5949 @test usv. S === svdvals (usv)
@@ -72,28 +62,20 @@ a2img = randn(n,n)/2
7262 @test svdz. Vt ≈ Matrix {eltya} (I, 0 , 0 )
7363 end
7464 end
75- usv = svd (a' )
76- @testset " singular value decomposition of adjoint" begin
77- @test usv. S === svdvals (usv)
78- @test usv. U * (Diagonal (usv. S) * usv. Vt) ≈ a'
79- @test convert (Array, usv) ≈ a'
80- @test usv. Vt' ≈ usv. V
81- @test_throws ErrorException usv. Z
82- b = rand (eltya,n)
83- @test usv\ b ≈ a' \ b
84- end
85- usv = svd (transpose (a))
86- @testset " singular value decomposition of transpose" begin
87- @test usv. S === svdvals (usv)
88- @test usv. U * (Diagonal (usv. S) * usv. Vt) ≈ transpose (a)
89- @test convert (Array, usv) ≈ transpose (a)
90- @test usv. Vt' ≈ usv. V
91- @test_throws ErrorException usv. Z
92- b = rand (eltya,n)
93- @test usv\ b ≈ transpose (a)\ b
65+ @testset " singular value decomposition of adjoint/transpose" begin
66+ for transform in (adjoint, transpose)
67+ usv = svd (transform (a))
68+ @test usv. S === svdvals (usv)
69+ @test usv. U * (Diagonal (usv. S) * usv. Vt) ≈ transform (a)
70+ @test convert (Array, usv) ≈ transform (a)
71+ @test usv. Vt' ≈ usv. V
72+ @test_throws ErrorException usv. Z
73+ b = rand (eltya,n)
74+ @test usv\ b ≈ transform (a)\ b
75+ end
9476 end
9577 @testset " Generalized svd" begin
96- a_svd = a[1 : n1 , :]
78+ a_svd = a[1 : div (n, 2 ) , :]
9779 gsvd = svd (a,a_svd)
9880 @test gsvd. U* gsvd. D1* gsvd. R* gsvd. Q' ≈ a
9981 @test gsvd. V* gsvd. D2* gsvd. R* gsvd. Q' ≈ a_svd
@@ -121,6 +103,18 @@ a2img = randn(n,n)/2
121103 @test gsvd. V* gsvd. D2* gsvd. R* gsvd. Q' ≈ c
122104 end
123105 end
106+ @testset " singular value decomposition of Hermitian/real-Symmetric" begin
107+ for T in (eltya <: Real ? (Symmetric, Hermitian) : (Hermitian,))
108+ usv = svd (T (asym))
109+ @test usv. S === svdvals (usv)
110+ @test usv. U * (Diagonal (usv. S) * usv. Vt) ≈ T (asym)
111+ @test convert (Array, usv) ≈ T (asym)
112+ @test usv. Vt' ≈ usv. V
113+ @test_throws ErrorException usv. Z
114+ b = rand (eltya,n)
115+ @test usv\ b ≈ T (asym)\ b
116+ end
117+ end
124118 if eltya <: LinearAlgebra.BlasReal
125119 @testset " Number input" begin
126120 x, y = randn (eltya, 2 )
0 commit comments