11using MatrixAlgebraKit
2- using Test
3- using TestExtras
4- using StableRNGs
52using LinearAlgebra: Diagonal
63using CUDA, AMDGPU
7- using CUDA. CUSOLVER # pull in opnorm binding
84
95BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
106GenericFloats = (BigFloat, Complex{BigFloat})
@@ -14,58 +10,89 @@ using .TestSuite
1410
1511is_buildkite = get (ENV , " BUILDKITE" , " false" ) == " true"
1612
17- for T in (BLASFloats... , GenericFloats... ), m in (0 , 54 ), n in (0 , 37 , m, 63 )
18- TestSuite. seed_rng! (123 )
19- if T ∈ BLASFloats
20- if CUDA. functional ()
21- TestSuite. test_svd (CuMatrix{T}, (m, n))
22- CUDA_SVD_ALGS = (
23- CUSOLVER_QRIteration (),
24- CUSOLVER_SVDPolar (),
25- CUSOLVER_Jacobi (),
26- )
27- TestSuite. test_svd_algs (CuMatrix{T}, (m, n), CUDA_SVD_ALGS)
28- k = 5
29- p = min (m, n) - k - 2
30- min (m, n) > k + 2 && TestSuite. test_randomized_svd (CuMatrix{T}, (m, n), (MatrixAlgebraKit. TruncatedAlgorithm (CUSOLVER_Randomized (; k, p, niters = 20 ), truncrank (k)),))
31- if n == m
32- TestSuite. test_svd (Diagonal{T, CuVector{T}}, m)
33- TestSuite. test_svd_algs (Diagonal{T, CuVector{T}}, m, (DiagonalAlgorithm (),))
34- end
35- end
36- if AMDGPU. functional ()
37- TestSuite. test_svd (ROCMatrix{T}, (m, n))
38- AMD_SVD_ALGS = (
39- ROCSOLVER_QRIteration (),
40- ROCSOLVER_Jacobi (),
41- )
42- TestSuite. test_svd_algs (ROCMatrix{T}, (m, n), AMD_SVD_ALGS)
43- if n == m
44- TestSuite. test_svd (Diagonal{T, ROCVector{T}}, m)
45- TestSuite. test_svd_algs (Diagonal{T, ROCVector{T}}, m, (DiagonalAlgorithm (),))
46- end
13+ # CPU tests
14+ # ---------
15+ if ! is_buildkite
16+ # LAPACK algorithms:
17+ for T in BLASFloats, m in (0 , 54 ), n in (0 , 37 , m, 63 )
18+ TestSuite. seed_rng! (123 )
19+ LAPACK_SVD_ALGS = (
20+ LAPACK_QRIteration (),
21+ LAPACK_DivideAndConquer (),
22+ LAPACK_SafeDivideAndConquer (; fixgauge = true ),
23+ )
24+ TestSuite. test_svd (T, (m, n))
25+ TestSuite. test_svd_algs (T, (m, n), LAPACK_SVD_ALGS)
26+ @static if VERSION > v " 1.11-" # Jacobi broken on 1.10
27+ m ≥ n && TestSuite. test_svd_algs (T, (m, n), (LAPACK_Jacobi (),); test_full = false , test_vals = false )
4728 end
4829 end
49- if ! is_buildkite
50- if T ∈ BLASFloats
51- LAPACK_SVD_ALGS = (
52- LAPACK_QRIteration (),
53- LAPACK_DivideAndConquer (),
54- LAPACK_SafeDivideAndConquer (; fixgauge = true ),
55- )
56- TestSuite. test_svd (T, (m, n))
57- TestSuite. test_svd_algs (T, (m, n), LAPACK_SVD_ALGS)
58- @static if VERSION > v " 1.11-" # Jacobi broken on 1.10
59- m ≥ n && TestSuite. test_svd_algs (T, (m, n), (LAPACK_Jacobi (),); test_full = false , test_vals = false )
60- end
61- elseif T ∈ GenericFloats
62- TestSuite. test_svd (T, (m, n))
63- TestSuite. test_svd_algs (T, (m, n), (GLA_QRIteration (),))
64- end
65- if m == n
66- AT = Diagonal{T, Vector{T}}
67- TestSuite. test_svd (AT, m)
68- TestSuite. test_svd_algs (AT, m, (DiagonalAlgorithm (),))
69- end
30+
31+ # Generic floats:
32+ for T in GenericFloats, m in (0 , 54 ), n in (0 , 37 , m, 63 )
33+ TestSuite. seed_rng! (123 )
34+ TestSuite. test_svd (T, (m, n))
35+ TestSuite. test_svd_algs (T, (m, n), (GLA_QRIteration (),))
36+ end
37+
38+ # Diagonal:
39+ for T in (BLASFloats... , GenericFloats... ), m in (0 , 54 )
40+ TestSuite. seed_rng! (123 )
41+ AT = Diagonal{T, Vector{T}}
42+ TestSuite. test_svd (AT, m)
43+ TestSuite. test_svd_algs (AT, m, (DiagonalAlgorithm (),))
44+ end
45+ end
46+
47+ # CUDA tests
48+ # ------------
49+ if CUDA. functional ()
50+ # LAPACK algorithms:
51+ for T in BLASFloats, m in (0 , 23 ), n in (0 , 17 , m, 27 )
52+ TestSuite. seed_rng! (123 )
53+ TestSuite. test_svd (CuMatrix{T}, (m, n))
54+ CUDA_SVD_ALGS = (
55+ CUSOLVER_QRIteration (),
56+ CUSOLVER_SVDPolar (),
57+ CUSOLVER_Jacobi (),
58+ )
59+ TestSuite. test_svd_algs (CuMatrix{T}, (m, n), CUDA_SVD_ALGS)
60+ end
61+
62+ # Randomized SVD:
63+ for T in BLASFloats, m in (0 , 23 ), n in (0 , 17 , m, 27 )
64+ TestSuite. seed_rng! (123 )
65+ k = 5
66+ p = min (m, n) - k - 2
67+ p > 0 || continue
68+ TestSuite. test_randomized_svd (CuMatrix{T}, (m, n), (MatrixAlgebraKit. TruncatedAlgorithm (CUSOLVER_Randomized (; k, p, niters = 20 ), truncrank (k)),))
69+ end
70+
71+ # Diagonal:
72+ for T in BLASFloats, m in (0 , 23 )
73+ TestSuite. seed_rng! (123 )
74+ AT = Diagonal{T, CuVector{T}}
75+ TestSuite. test_svd (AT, m)
76+ TestSuite. test_svd_algs (AT, m, (DiagonalAlgorithm (),))
77+ end
78+ end
79+
80+ # AMDGPU tests
81+ # ------------
82+ if AMDGPU. functional ()
83+ # LAPACK algorithms:
84+ for T in BLASFloats, m in (0 , 23 ), n in (0 , 17 , m, 27 )
85+ TestSuite. seed_rng! (123 )
86+ TestSuite. test_svd (ROCMatrix{T}, (m, n))
87+ AMD_SVD_ALGS = (ROCSOLVER_QRIteration (), ROCSOLVER_Jacobi ())
88+ TestSuite. test_svd_algs (ROCMatrix{T}, (m, n), AMD_SVD_ALGS)
89+ end
90+
91+ # Diagonal:
92+ for T in BLASFloats, m in (0 , 23 )
93+ TestSuite. seed_rng! (123 )
94+ AT = Diagonal{T, ROCVector{T}}
95+ TestSuite. test_svd (AT, m)
96+ TestSuite. test_svd_algs (AT, m, (DiagonalAlgorithm (),))
7097 end
7198end
0 commit comments