-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathalgorithms.jl
More file actions
63 lines (58 loc) · 2.78 KB
/
algorithms.jl
File metadata and controls
63 lines (58 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using MatrixAlgebraKit
using Test
using TestExtras
using MatrixAlgebraKit: LAPACK_SVDAlgorithm, PolarViaSVD, TruncatedAlgorithm,
default_algorithm, select_algorithm, Householder, LAPACK
@testset "default_algorithm" begin
A = randn(3, 3)
for f in (svd_compact!, svd_compact, svd_full!, svd_full)
@test @constinferred(default_algorithm(f, A)) === LAPACK_SafeDivideAndConquer()
end
for f in (eig_full!, eig_full, eig_vals!, eig_vals)
@test @constinferred(default_algorithm(f, A)) === LAPACK_Expert()
end
for f in (eigh_full!, eigh_full, eigh_vals!, eigh_vals)
@test @constinferred(default_algorithm(f, A)) ===
LAPACK_MultipleRelativelyRobustRepresentations()
end
for f in (lq_full!, lq_full, lq_compact!, lq_compact, lq_null!, lq_null)
@test @constinferred(default_algorithm(f, A)) == Householder(; driver = LAPACK())
end
for f in (left_polar!, left_polar, right_polar!, right_polar)
@test @constinferred(default_algorithm(f, A)) ==
PolarViaSVD(LAPACK_SafeDivideAndConquer())
end
for f in (qr_full!, qr_full, qr_compact!, qr_compact, qr_null!, qr_null)
@test @constinferred(default_algorithm(f, A)) == Householder(; driver = LAPACK())
end
for f in (schur_full!, schur_full, schur_vals!, schur_vals)
@test @constinferred(default_algorithm(f, A)) === LAPACK_Expert()
end
@test @constinferred(default_algorithm(qr_compact!, A; blocksize = 2)) ==
Householder(; driver = LAPACK(), blocksize = 2)
end
@testset "select_algorithm" begin
A = randn(3, 3)
for f in (svd_trunc!, svd_trunc)
@test @constinferred(select_algorithm(f, A)) ===
TruncatedAlgorithm(LAPACK_SafeDivideAndConquer(), notrunc())
end
for f in (eig_trunc!, eig_trunc)
@test @constinferred(select_algorithm(f, A)) ===
TruncatedAlgorithm(LAPACK_Expert(), notrunc())
end
for f in (eigh_trunc!, eigh_trunc)
@test @constinferred(select_algorithm(f, A)) ===
TruncatedAlgorithm(LAPACK_MultipleRelativelyRobustRepresentations(), notrunc())
end
alg = TruncatedAlgorithm(LAPACK_Simple(), trunctol(; atol = 0.1, keep_below = true))
for f in (eig_trunc!, eigh_trunc!, svd_trunc!)
@test @constinferred(select_algorithm(eig_trunc!, A, alg)) === alg
@test_throws ArgumentError select_algorithm(eig_trunc!, A, alg; trunc = (; maxrank = 2))
end
@test @constinferred(select_algorithm(svd_compact!, A)) === LAPACK_SafeDivideAndConquer()
@test @constinferred(select_algorithm(svd_compact!, A, nothing)) === LAPACK_SafeDivideAndConquer()
for alg in (:LAPACK_QRIteration, LAPACK_QRIteration, LAPACK_QRIteration())
@test @constinferred(select_algorithm(svd_compact!, A, $alg)) === LAPACK_QRIteration()
end
end