|
1 | 1 | using MatrixAlgebraKit |
2 | 2 | using Test |
3 | | -using TestExtras |
4 | 3 | using StableRNGs |
5 | | -using LinearAlgebra: LinearAlgebra, I, isposdef |
| 4 | +using LinearAlgebra: Diagonal |
| 5 | +using CUDA, AMDGPU |
6 | 6 |
|
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) |
| 7 | +BLASFloats = (Float32, Float64, ComplexF32, ComplexF64) |
| 8 | +GenericFloats = (BigFloat, Complex{BigFloat}) |
20 | 9 |
|
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) |
| 10 | +@isdefined(TestSuite) || include("testsuite/TestSuite.jl") |
| 11 | +using .TestSuite |
27 | 12 |
|
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) |
| 13 | +is_buildkite = get(ENV, "BUILDKITE", "false") == "true" |
35 | 14 |
|
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)) |
| 15 | +m = 54 |
| 16 | +for T in (BLASFloats..., GenericFloats...), n in (37, m, 63) |
| 17 | + TestSuite.seed_rng!(123) |
| 18 | + if T ∈ BLASFloats |
| 19 | + if CUDA.functional() |
| 20 | + CUDA_POLAR_ALGS = (PolarViaSVD.((CUSOLVER_QRIteration(), CUSOLVER_SVDPolar(), CUSOLVER_Jacobi()))..., PolarNewton()) |
| 21 | + TestSuite.test_polar(CuMatrix{T}, (m, n), CUDA_POLAR_ALGS) |
| 22 | + n == m && TestSuite.test_polar(Diagonal{T, CuVector{T}}, m, (PolarNewton(),)) |
| 23 | + end |
| 24 | + if AMDGPU.functional() |
| 25 | + ROC_POLAR_ALGS = (PolarViaSVD.((ROCSOLVER_QRIteration(), ROCSOLVER_Jacobi()))..., PolarNewton()) |
| 26 | + TestSuite.test_polar(ROCMatrix{T}, (m, n), ROC_POLAR_ALGS) |
| 27 | + n == m && TestSuite.test_polar(Diagonal{T, ROCVector{T}}, m, (PolarNewton(),)) |
44 | 28 | end |
45 | 29 | 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)) |
| 30 | + if !is_buildkite |
| 31 | + if T ∈ BLASFloats |
| 32 | + LAPACK_POLAR_ALGS = (PolarViaSVD.((LAPACK_QRIteration(), LAPACK_Bisection(), LAPACK_DivideAndConquer()))..., PolarNewton()) |
| 33 | + TestSuite.test_polar(T, (m, n), LAPACK_POLAR_ALGS) |
| 34 | + LAPACK_JACOBI = (PolarViaSVD(LAPACK_Jacobi()),) |
| 35 | + TestSuite.test_polar(T, (m, n), LAPACK_JACOBI; test_right=false) |
| 36 | + elseif T ∈ GenericFloats |
| 37 | + GLA_POLAR_ALGS = (PolarViaSVD.((GLA_QRIteration(),))..., PolarNewton()) |
| 38 | + TestSuite.test_polar(T, (m, n), GLA_POLAR_ALGS) |
| 39 | + end |
| 40 | + if m == n |
| 41 | + AT = Diagonal{T, Vector{T}} |
| 42 | + TestSuite.test_polar(AT, m, (PolarNewton(),)) |
81 | 43 | end |
82 | 44 | end |
83 | 45 | end |
0 commit comments