@@ -12,37 +12,41 @@ const BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
1212 m = 54
1313 noisefactor = eps (real (T))^ (3 / 4 )
1414 for alg in (NativeBlocked (blocksize = 16 ), NativeBlocked (blocksize = 32 ), NativeBlocked (blocksize = 64 ))
15- A = CuArray (randn (rng, T, m, m))
16- Ah = (A + A' ) / 2
17- Aa = (A - A' ) / 2
18- Ac = copy (A)
15+ for A in ( CuArray (randn (rng, T, m, m)), Diagonal ( CuArray ( randn (rng, T, m)) ))
16+ Ah = (A + A' ) / 2
17+ Aa = (A - A' ) / 2
18+ Ac = copy (A)
1919
20- Bh = project_hermitian (A, alg)
21- @test ishermitian (Bh)
22- @test Bh ≈ Ah
23- @test A == Ac
24- Bh_approx = Bh + noisefactor * Aa
25- @test ! ishermitian (Bh_approx)
26- @test ishermitian (Bh_approx; rtol = 10 * noisefactor)
20+ Bh = project_hermitian (A, alg)
21+ @test ishermitian (Bh)
22+ @test Bh ≈ Ah
23+ @test A == Ac
24+ # this is still hermitian for real Diagonals!
25+ Bh_approx = Bh + noisefactor * Aa
26+ if ! isa (A, Diagonal) && ! (T <: Real )
27+ @test ! ishermitian (Bh_approx)
28+ end
29+ @test ishermitian (Bh_approx; rtol = 10 * noisefactor)
2730
28- Ba = project_antihermitian (A, alg)
29- @test isantihermitian (Ba)
30- @test Ba ≈ Aa
31- @test A == Ac
32- Ba_approx = Ba + noisefactor * Ah
33- @test ! isantihermitian (Ba_approx)
34- @test isantihermitian (Ba_approx; rtol = 10 * noisefactor)
31+ Ba = project_antihermitian (A, alg)
32+ @test isantihermitian (Ba)
33+ @test Ba ≈ Aa
34+ @test A == Ac
35+ Ba_approx = Ba + noisefactor * Ah
36+ @test ! isantihermitian (Ba_approx)
37+ @test isantihermitian (Ba_approx; rtol = 10 * noisefactor)
3538
36- Bh = project_hermitian! (Ac, alg)
37- @test Bh === Ac
38- @test ishermitian (Bh)
39- @test Bh ≈ Ah
39+ Bh = project_hermitian! (Ac, alg)
40+ @test Bh === Ac
41+ @test ishermitian (Bh)
42+ @test Bh ≈ Ah
4043
41- copy! (Ac, A)
42- Ba = project_antihermitian! (Ac, alg)
43- @test Ba === Ac
44- @test isantihermitian (Ba)
45- @test Ba ≈ Aa
44+ copy! (Ac, A)
45+ Ba = project_antihermitian! (Ac, alg)
46+ @test Ba === Ac
47+ @test isantihermitian (Ba)
48+ @test Ba ≈ Aa
49+ end
4650 end
4751end
4852
5458 svdalgs = (CUSOLVER_SVDPolar (), CUSOLVER_QRIteration (), CUSOLVER_Jacobi ())
5559 algs = (PolarViaSVD .(svdalgs)... ,) # PolarNewton()) # TODO
5660 @testset " algorithm $alg " for alg in algs
57- A = CuArray (randn (rng, T, m, n))
58- W = project_isometric (A, alg)
59- @test isisometric (W)
60- W2 = project_isometric (W, alg)
61- @test W2 ≈ W # stability of the projection
62- @test W * (W' * A) ≈ A
61+ for A in ( CuArray (randn (rng, T, m, n)), Diagonal ( CuArray ( randn (rng, T, m)) ))
62+ W = project_isometric (A, alg)
63+ @test isisometric (W)
64+ W2 = project_isometric (W, alg)
65+ @test W2 ≈ W # stability of the projection
66+ @test W * (W' * A) ≈ A
6367
64- Ac = similar (A)
65- W2 = @constinferred project_isometric! (copy! (Ac, A), W, alg)
66- @test W2 === W
67- @test isisometric (W)
68+ Ac = similar (A)
69+ W2 = @constinferred project_isometric! (copy! (Ac, A), W, alg)
70+ @test W2 === W
71+ @test isisometric (W)
6872
69- # test that W is closer to A then any other isometry
70- for k in 1 : 10
71- δA = CuArray (randn (rng, T, m, n))
72- W = project_isometric (A, alg)
73- W2 = project_isometric (A + δA / 100 , alg)
74- @test norm (A - W2) > norm (A - W)
73+ # test that W is closer to A then any other isometry
74+ for k in 1 : 10
75+ δA = CuArray (randn (rng, T, size (A)... ))
76+ W = project_isometric (A, alg)
77+ W2 = project_isometric (A + δA / 100 , alg)
78+ @test norm (A - W2) > norm (A - W)
79+ end
7580 end
7681 end
7782 end
0 commit comments