@@ -32,28 +32,7 @@ using Random: Random
3232using StableRNGs: StableRNG
3333using Test: @inferred , @test , @test_throws , @testset
3434
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)
5736 rng = StableRNG (123 )
5837 a = BlockSparseMatrix {elt} (undef, [2 , 3 ], [2 , 3 ])
5938 a[Block (1 , 1 )] = randn (rng, elt, 2 , 2 )
@@ -62,8 +41,6 @@ MATRIX_FUNCTIONS_UNSTABLE = [
6241 MATRIX_FUNCTIONS = [MATRIX_FUNCTIONS; [:inv , :pinv ]]
6342 # Only works when real, also isn't defined in Julia 1.10.
6443 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)
6744 for f in MATRIX_FUNCTIONS
6845 @eval begin
6946 fa = $ f ($ a)
@@ -73,15 +50,27 @@ MATRIX_FUNCTIONS_UNSTABLE = [
7350 end
7451 end
7552
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.
7765 rng = StableRNG (123 )
7866 a = BlockSparseMatrix {elt} (undef, [2 , 3 ], [2 , 3 ])
7967 a[Block (2 , 2 )] = randn (rng, elt, 3 , 3 )
8068 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+ ]
8273 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)
8574 # Dense version is broken for some reason, investigate.
8675 MATRIX_FUNCTIONS = setdiff (MATRIX_FUNCTIONS, [:cbrt ])
8776 for f in MATRIX_FUNCTIONS
@@ -92,9 +81,16 @@ MATRIX_FUNCTIONS_UNSTABLE = [
9281 @test issetequal (eachblockstoredindex (fa), [Block (1 , 1 ), Block (2 , 2 )])
9382 end
9483 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 ])
9692 @eval begin
97- @test_throws LinearAlgebra . SingularException $ f ($ a)
93+ @test_throws $ SINGULAR_EXCEPTION $ f ($ a)
9894 end
9995 end
10096end
0 commit comments