@@ -5,11 +5,11 @@ using LinearAlgebra: LinearAlgebra
5
5
using Random: Random
6
6
using Test: @inferred , @testset , @test
7
7
8
- function test_svd (a, usv; broken = false )
8
+ function test_svd (a, usv)
9
9
U, S, V = usv
10
- @test U * diagonal (S) * V' ≈ a broken = broken
11
- @test U' * U ≈ LinearAlgebra. I
12
- @test V' * V ≈ LinearAlgebra. I
10
+ return ( U * diagonal (S) * V' ≈ a) &&
11
+ ( U' * U ≈ LinearAlgebra. I) &&
12
+ ( V' * V ≈ LinearAlgebra. I)
13
13
end
14
14
15
15
# regular matrix
@@ -19,7 +19,7 @@ eltypes = (Float32, Float64, ComplexF64)
19
19
@testset " ($m , $n ) Matrix{$T }" for ((m, n), T) in Iterators. product (sizes, eltypes)
20
20
a = rand (m, n)
21
21
usv = @inferred svd (a)
22
- test_svd (a, usv)
22
+ @test test_svd (a, usv)
23
23
end
24
24
25
25
# block matrix
@@ -28,7 +28,7 @@ blockszs = (([2, 2], [2, 2]), ([2, 2], [2, 3]), ([2, 2, 1], [2, 3]), ([2, 3], [2
28
28
@testset " ($m , $n ) BlockMatrix{$T }" for ((m, n), T) in Iterators. product (blockszs, eltypes)
29
29
a = mortar ([rand (T, i, j) for i in m, j in n])
30
30
usv = svd (a)
31
- test_svd (a, usv)
31
+ @test test_svd (a, usv)
32
32
@test usv. U isa BlockedMatrix
33
33
@test usv. Vt isa BlockedMatrix
34
34
@test usv. S isa BlockedVector
39
39
@testset " ($m , $n ) BlockDiagonal{$T }" for ((m, n), T) in
40
40
Iterators. product (blockszs, eltypes)
41
41
a = BlockDiagonal ([rand (T, i, j) for (i, j) in zip (m, n)])
42
- if VERSION ≥ v " 1.11"
43
- usv = svd (a)
44
- # TODO : `BlockDiagonal * Adjoint` errors
45
- # TODO : This is broken because of https://github.com/JuliaLang/julia/issues/57034,
46
- # fix and reenable.
47
- test_svd (a, usv; broken= true )
48
- else
49
- # `svd(a)` depends on `diagind(::AbstractMatrix, ::IndexStyle)`
50
- # being defined, but it was only introduced in Julia v1.11.
51
- @test svd (a) broken = true
52
- end
42
+ usv = svd (a)
43
+ @test test_svd (a, usv)
53
44
end
54
45
55
46
# blocksparse
60
51
61
52
# test empty matrix
62
53
usv_empty = svd (a)
63
- test_svd (a, usv_empty)
54
+ @test test_svd (a, usv_empty)
64
55
65
56
# test blockdiagonal
66
57
for i in LinearAlgebra. diagind (blocks (a))
67
58
I = CartesianIndices (blocks (a))[i]
68
59
a[Block (I. I... )] = rand (T, size (blocks (a)[i]))
69
60
end
70
61
usv = svd (a)
71
- test_svd (a, usv)
62
+ @test test_svd (a, usv)
72
63
73
64
perm = Random. randperm (length (m))
74
65
b = a[Block .(perm), Block .(1 : length (n))]
75
66
usv = svd (b)
76
- test_svd (b, usv)
67
+ @test test_svd (b, usv)
77
68
78
69
# test permuted blockdiagonal with missing row/col
79
70
I_removed = rand (eachblockstoredindex (b))
80
71
c = copy (b)
81
72
delete! (blocks (c). storage, CartesianIndex (Int .(Tuple (I_removed))))
82
73
usv = svd (c)
83
- test_svd (c, usv)
74
+ @test test_svd (c, usv)
84
75
end
0 commit comments