@@ -32,28 +32,7 @@ using Random: Random
32
32
using StableRNGs: StableRNG
33
33
using Test: @inferred , @test , @test_throws , @testset
34
34
35
- # These functions involve inverses so break when there are zeros on the diagonal.
36
- MATRIX_FUNCTIONS_SINGULAR = [:csc , :cot , :csch , :coth ]
37
-
38
- # Broken because of type stability issues. Fix manually by forcing to be complex.
39
- MATRIX_FUNCTIONS_UNSTABLE = [
40
- :log ,
41
- :sqrt ,
42
- :acos ,
43
- :asin ,
44
- :atan ,
45
- :acsc ,
46
- :asec ,
47
- :acot ,
48
- :acosh ,
49
- :asinh ,
50
- :atanh ,
51
- :acsch ,
52
- :asech ,
53
- :acoth ,
54
- ]
55
-
56
- @testset " Matrix functions (eltype=$elt )" for elt in (Float32, Float64, ComplexF64)
35
+ @testset " Matrix functions (T=$elt )" for elt in (Float32, Float64, ComplexF64)
57
36
rng = StableRNG (123 )
58
37
a = BlockSparseMatrix {elt} (undef, [2 , 3 ], [2 , 3 ])
59
38
a[Block (1 , 1 )] = randn (rng, elt, 2 , 2 )
@@ -62,8 +41,6 @@ MATRIX_FUNCTIONS_UNSTABLE = [
62
41
MATRIX_FUNCTIONS = [MATRIX_FUNCTIONS; [:inv , :pinv ]]
63
42
# Only works when real, also isn't defined in Julia 1.10.
64
43
MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, [:cbrt ])
65
- # Broken because of type stability issues. Fix manually by forcing to be complex.
66
- MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, MATRIX_FUNCTIONS_UNSTABLE)
67
44
for f in MATRIX_FUNCTIONS
68
45
@eval begin
69
46
fa = $ f ($ a)
@@ -73,15 +50,27 @@ MATRIX_FUNCTIONS_UNSTABLE = [
73
50
end
74
51
end
75
52
76
- # Skip inverse functions when there are missing/zero diagonal blocks.
53
+ # Catch case of off-diagonal blocks.
54
+ rng = StableRNG (123 )
55
+ a = BlockSparseMatrix {elt} (undef, [2 , 3 ], [2 , 3 ])
56
+ a[Block (1 , 1 )] = randn (rng, elt, 2 , 2 )
57
+ a[Block (1 , 2 )] = randn (rng, elt, 2 , 3 )
58
+ for f in MATRIX_FUNCTIONS
59
+ @eval begin
60
+ @test_throws ArgumentError $ f ($ a)
61
+ end
62
+ end
63
+
64
+ # Missing diagonal blocks.
77
65
rng = StableRNG (123 )
78
66
a = BlockSparseMatrix {elt} (undef, [2 , 3 ], [2 , 3 ])
79
67
a[Block (2 , 2 )] = randn (rng, elt, 3 , 3 )
80
68
MATRIX_FUNCTIONS = BlockSparseArrays. MATRIX_FUNCTIONS
81
- # These functions involve inverses so break when there are zeros on the diagonal.
69
+ # These functions involve inverses so they break when there are zeros on the diagonal.
70
+ MATRIX_FUNCTIONS_SINGULAR = [
71
+ :log , :acsc , :asec , :acot , :acsch , :asech , :acoth , :csc , :cot , :csch , :coth
72
+ ]
82
73
MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, MATRIX_FUNCTIONS_SINGULAR)
83
- # Broken because of type stability issues. Fix manually by forcing to be complex.
84
- MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, MATRIX_FUNCTIONS_UNSTABLE)
85
74
# Dense version is broken for some reason, investigate.
86
75
MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, [:cbrt ])
87
76
for f in MATRIX_FUNCTIONS
@@ -92,9 +81,16 @@ MATRIX_FUNCTIONS_UNSTABLE = [
92
81
@test issetequal (eachblockstoredindex (fa), [Block (1 , 1 ), Block (2 , 2 )])
93
82
end
94
83
end
95
- for f in MATRIX_FUNCTIONS_SINGULAR
84
+
85
+ SINGULAR_EXCEPTION = if VERSION < v " 1.11-"
86
+ # A different exception is thrown in older versions of Julia.
87
+ LinearAlgebra. LAPACKException
88
+ else
89
+ LinearAlgebra. SingularException
90
+ end
91
+ for f in setdiff (MATRIX_FUNCTIONS_SINGULAR, [:log ])
96
92
@eval begin
97
- @test_throws LinearAlgebra . SingularException $ f ($ a)
93
+ @test_throws $ SINGULAR_EXCEPTION $ f ($ a)
98
94
end
99
95
end
100
96
end
0 commit comments