@@ -4,96 +4,26 @@ using TestExtras
44using StableRNGs
55using LinearAlgebra: LinearAlgebra, Diagonal, norm, normalize!
66
7- const BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
8-
9- @testset " project_(anti)hermitian! for T = $T " for T in BLASFloats
10- rng = StableRNG(123 )
11- m = 54
12- noisefactor = eps(real(T))^ (3 / 4 )
13- for alg in (NativeBlocked(blocksize = 16 ), NativeBlocked(blocksize = 32 ), NativeBlocked(blocksize = 64 ))
14- for A in (randn(rng, T, m, m), Diagonal(randn(rng, T, m)))
15- Ah = (A + A' ) / 2
16- Aa = (A - A' ) / 2
17- Ac = copy(A)
18-
19- Bh = project_hermitian(A, alg)
20- @test ishermitian(Bh)
21- @test Bh ≈ Ah
22- @test A == Ac
23- Bh_approx = Bh + noisefactor * Aa
24- # this is still hermitian for real Diagonal: |A - A'| == 0
25- @test ! ishermitian(Bh_approx) || norm(Aa) == 0
26- @test ishermitian(Bh_approx; rtol = 10 * noisefactor)
27-
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- # this is never anti-hermitian for real Diagonal: |A - A'| == 0
35- @test isantihermitian(Ba_approx; rtol = 10 * noisefactor) || norm(Aa) == 0
36-
37- Bh = project_hermitian!(Ac, alg)
38- @test Bh === Ac
39- @test ishermitian(Bh)
40- @test Bh ≈ Ah
41-
42- copy!(Ac, A)
43- Ba = project_antihermitian!(Ac, alg)
44- @test Ba === Ac
45- @test isantihermitian(Ba)
46- @test Ba ≈ Aa
47- end
7+ BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
8+ GenericFloats = (Float16, BigFloat, Complex{BigFloat})
9+
10+ @isdefined(TestSuite) || include(" testsuite/TestSuite.jl" )
11+ using . TestSuite
12+
13+ m = 54
14+ for T in BLASFloats, n in (37 , m, 63 )
15+ TestSuite. seed_rng!(123 )
16+ TestSuite. test_projections(T, (m, n))
17+ if CUDA. functional()
18+ TestSuite. test_projections(CuMatrix{T}, (m, n); test_pivoted = false , test_blocksize = false )
19+ TestSuite. test_projections(Diagonal{T, CuVector{T}}, m; test_pivoted = false , test_blocksize = false )
4820 end
49-
50- # test approximate error calculation
51- A = normalize!(randn(rng, T, m, m))
52- Ah = project_hermitian(A)
53- Aa = project_antihermitian(A)
54-
55- Ah_approx = Ah + noisefactor * Aa
56- ϵ = norm(project_antihermitian(Ah_approx))
57- @test ! ishermitian(Ah_approx; atol = (999 // 1000 ) * ϵ)
58- @test ishermitian(Ah_approx; atol = (1001 // 1000 ) * ϵ)
59-
60- Aa_approx = Aa + noisefactor * Ah
61- ϵ = norm(project_hermitian(Aa_approx))
62- @test ! isantihermitian(Aa_approx; atol = (999 // 1000 ) * ϵ)
63- @test isantihermitian(Aa_approx; atol = (1001 // 1000 ) * ϵ)
64- end
65-
66- @testset " project_isometric! for T = $T " for T in BLASFloats
67- rng = StableRNG(123 )
68- m = 54
69- @testset " size ($m , $n )" for n in (37 , m)
70- k = min(m, n)
71- if LinearAlgebra. LAPACK. version() < v" 3.12.0"
72- svdalgs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection())
73- else
74- svdalgs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection(), LAPACK_Jacobi())
75- end
76- algs = (PolarViaSVD.(svdalgs). .. , PolarNewton())
77- @testset " algorithm $alg " for alg in algs
78- A = randn(rng, T, m, n)
79- W = project_isometric(A, alg)
80- @test isisometric(W)
81- W2 = project_isometric(W, alg)
82- @test W2 ≈ W # stability of the projection
83- @test W * (W' * A) ≈ A
84-
85- Ac = similar(A)
86- W2 = @constinferred project_isometric!(copy!(Ac, A), W, alg)
87- @test W2 === W
88- @test isisometric(W)
89-
90- # test that W is closer to A then any other isometry
91- for k in 1:10
92- δA = randn(rng, T, m, n)
93- W = project_isometric(A, alg)
94- W2 = project_isometric(A + δA / 100, alg)
95- @test norm(A - W2) > norm(A - W)
96- end
97- end
21+ if AMDGPU. functional()
22+ TestSuite. test_projections(ROCMatrix{T}, (m, n); test_pivoted = false , test_blocksize = false )
23+ TestSuite. test_projections(Diagonal{T, ROCVector{T}}, m; test_pivoted = false , test_blocksize = false )
9824 end
9925end
26+ for T in (BLASFloats... , GenericFloats... )
27+ AT = Diagonal{T, Vector{T}}
28+ TestSuite. test_projections(AT, m; test_pivoted = false , test_blocksize = false )
29+ end
0 commit comments