@@ -4,80 +4,27 @@ using TestExtras
44using StableRNGs
55using LinearAlgebra: LinearAlgebra, I, isposdef
66
7- @testset " left_polar! for T = $T " for T in (Float32, Float64, ComplexF32, ComplexF64)
8- rng = StableRNG(123 )
9- m = 54
10- @testset " size ($m , $n )" for n in (37 , m)
11- k = min(m, n)
12- if LinearAlgebra. LAPACK. version() < v" 3.12.0"
13- svdalgs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection())
14- else
15- svdalgs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection(), LAPACK_Jacobi())
16- end
17- algs = (PolarViaSVD.(svdalgs). .. , PolarNewton())
18- @testset " algorithm $alg " for alg in algs
19- A = randn(rng, T, m, n)
20-
21- W, P = left_polar(A; alg)
22- @test W isa Matrix{T} && size(W) == (m, n)
23- @test P isa Matrix{T} && size(P) == (n, n)
24- @test W * P ≈ A
25- @test isisometric(W)
26- @test isposdef(P)
27-
28- Ac = similar(A)
29- W2, P2 = @constinferred left_polar!(copy!(Ac, A), (W, P), alg)
30- @test W2 === W
31- @test P2 === P
32- @test W * P ≈ A
33- @test isisometric(W)
34- @test isposdef(P)
35-
36- noP = similar(P, (0 , 0 ))
37- W2, P2 = @constinferred left_polar!(copy!(Ac, A), (W, noP), alg)
38- @test P2 === noP
39- @test W2 === W
40- @test isisometric(W)
41- P = W' * A # compute P explicitly to verify W correctness
42- @test ishermitian(P; rtol = MatrixAlgebraKit.defaulttol(P))
43- @test isposdef(project_hermitian!(P))
44- 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_polar(T, (m, n))
17+ if CUDA. functional()
18+ TestSuite. test_polar(CuMatrix{T}, (m, n); test_pivoted = false , test_blocksize = false )
19+ TestSuite. test_polar(Diagonal{T, CuVector{T}}, m; test_pivoted = false , test_blocksize = false )
4520 end
46- end
47-
48- @testset "right_polar! for T = $T" for T in (Float32, Float64, ComplexF32, ComplexF64)
49- rng = StableRNG(123)
50- n = 54
51- @testset "size ($m, $n)" for m in (37, n)
52- k = min(m, n)
53- svdalgs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection())
54- algs = (PolarViaSVD.(svdalgs)..., PolarNewton())
55- @testset "algorithm $alg" for alg in algs
56- A = randn(rng, T, m, n)
57-
58- P, Wᴴ = right_polar(A; alg)
59- @test Wᴴ isa Matrix{T} && size(Wᴴ) == (m, n)
60- @test P isa Matrix{T} && size(P) == (m, m)
61- @test P * Wᴴ ≈ A
62- @test isisometric(Wᴴ; side = :right)
63- @test isposdef(P)
64-
65- Ac = similar(A)
66- P2, Wᴴ2 = @constinferred right_polar!(copy!(Ac, A), (P, Wᴴ), alg)
67- @test P2 === P
68- @test Wᴴ2 === Wᴴ
69- @test P * Wᴴ ≈ A
70- @test isisometric(Wᴴ; side = :right)
71- @test isposdef(P)
72-
73- noP = similar(P, (0, 0))
74- P2, Wᴴ2 = @constinferred right_polar!(copy!(Ac, A), (noP, Wᴴ), alg)
75- @test P2 === noP
76- @test Wᴴ2 === Wᴴ
77- @test isisometric(Wᴴ; side = :right)
78- P = A * Wᴴ' # compute P explicitly to verify W correctness
79- @test ishermitian(P; rtol = MatrixAlgebraKit. defaulttol(P))
80- @test isposdef(project_hermitian!(P))
81- end
21+ if AMDGPU. functional()
22+ TestSuite. test_polar(ROCMatrix{T}, (m, n); test_pivoted = false , test_blocksize = false )
23+ TestSuite. test_polar(Diagonal{T, ROCVector{T}}, m; test_pivoted = false , test_blocksize = false )
8224 end
8325end
26+ for T in (BLASFloats... , GenericFloats... )
27+ AT = Diagonal{T, Vector{T}}
28+ TestSuite. test_polar(AT, m; test_pivoted = false , test_blocksize = false )
29+ end
30+
0 commit comments