@@ -23,41 +23,62 @@ bimg = randn(n,2)/2
2323for eltya in (Float32, Float64, Complex64, Complex128, Int)
2424 a = eltya == Int ? rand (1 : 7 , n, n) : convert (Matrix{eltya}, eltya <: Complex ? complex (areal, aimg) : areal)
2525 a2 = eltya == Int ? rand (1 : 7 , n, n) : convert (Matrix{eltya}, eltya <: Complex ? complex (a2real, a2img) : a2real)
26- asym = a' + a # symmetric indefinite
27- apd = a' * a # symmetric positive-definite
28- ε = εa = eps (abs (float (one (eltya))))
29-
30- for eltyb in (Float32, Float64, Complex64, Complex128, Int)
31- b = eltyb == Int ? rand (1 : 5 , n, 2 ) : convert (Matrix{eltyb}, eltyb <: Complex ? complex (breal, bimg) : breal)
32- εb = eps (abs (float (one (eltyb))))
33- ε = max (εa,εb)
34-
35- debug && println (" \n type of a: " , eltya, " type of b: " , eltyb, " \n " )
36-
37- debug && println (" (Automatic) Bunch-Kaufman factor of indefinite matrix" )
38- bc1 = factorize (asym)
39- @test_approx_eq inv (bc1) * asym eye (n)
40- @test_approx_eq_eps asym * (bc1\ b) b 1000 ε
41- for rook in (false , true )
42- @test_approx_eq inv (bkfact (a.' + a, :U , true , rook)) * (a.' + a) eye (n)
43- @test size (bc1) == size (bc1. LD)
44- @test size (bc1,1 ) == size (bc1. LD,1 )
45- @test size (bc1,2 ) == size (bc1. LD,2 )
46- if eltya <: BlasReal
47- @test_throws ArgumentError bkfact (a)
48- end
26+ for atype in (" Array" , " SubArray" )
27+ asym = a' + a # symmetric indefinite
28+ apd = a' * a # symmetric positive-definite
29+ if atype == " Array"
30+ a = a
31+ a2 = a2
32+ else
33+ a = sub (a, 1 : n, 1 : n)
34+ a2 = sub (a2, 1 : n, 1 : n)
35+ asym = sub (asym, 1 : n, 1 : n)
36+ apd = sub (apd, 1 : n, 1 : n)
4937 end
38+ ε = εa = eps (abs (float (one (eltya))))
39+
40+ for eltyb in (Float32, Float64, Complex64, Complex128, Int)
41+ b = eltyb == Int ? rand (1 : 5 , n, 2 ) : convert (Matrix{eltyb}, eltyb <: Complex ? complex (breal, bimg) : breal)
42+ for btype in (" Array" , " SubArray" )
43+ if btype == " Array"
44+ b = b
45+ else
46+ b = sub (b, 1 : n, 1 : 2 )
47+ end
48+
49+ εb = eps (abs (float (one (eltyb))))
50+ ε = max (εa,εb)
51+
52+ debug && println (" \n eltype of a: " , eltya, " eltype of b: " , eltyb)
53+ debug && println (" type of a: " , atype, " type of b: " , btype, " \n " )
54+
55+ debug && println (" (Automatic) Bunch-Kaufman factor of indefinite matrix" )
56+ bc1 = factorize (asym)
57+ @test_approx_eq inv (bc1) * asym eye (n)
58+ @test_approx_eq_eps asym * (bc1\ b) b 1000 ε
59+ for rook in (false , true )
60+ @test_approx_eq inv (bkfact (a.' + a, :U , true , rook)) * (a.' + a) eye (n)
61+ @test size (bc1) == size (bc1. LD)
62+ @test size (bc1,1 ) == size (bc1. LD,1 )
63+ @test size (bc1,2 ) == size (bc1. LD,2 )
64+ if eltya <: BlasReal
65+ @test_throws ArgumentError bkfact (a)
66+ end
67+ end
5068
51- debug && println (" Bunch-Kaufman factors of a pos-def matrix" )
52- for rook in (false , true )
53- bc2 = bkfact (apd, :U , issymmetric (apd), rook)
54- @test_approx_eq inv (bc2) * apd eye (n)
55- @test_approx_eq_eps apd * (bc2\ b) b 150000 ε
56- @test ishermitian (bc2) == ! issymmetric (bc2)
69+ debug && println (" Bunch-Kaufman factors of a pos-def matrix" )
70+ for rook in (false , true )
71+ bc2 = bkfact (apd, :U , issymmetric (apd), rook)
72+ @test_approx_eq inv (bc2) * apd eye (n)
73+ @test_approx_eq_eps apd * (bc2\ b) b 150000 ε
74+ @test ishermitian (bc2) == ! issymmetric (bc2)
75+ end
76+ end
5777 end
5878 end
5979end
6080
81+
6182debug && println (" Bunch-Kaufman factors of a singular matrix" )
6283let
6384 As1 = ones (n, n)
6788 As3[1 , end ] -= im
6889
6990 for As = (As1, As2, As3)
70- for rook in (false , true )
71- F = bkfact (As, :U , issymmetric (As), rook)
72- @test det (F) == 0
73- @test_throws LinAlg. SingularException inv (F)
74- @test_throws LinAlg. SingularException F \ ones (size (As, 1 ))
91+ for Astype in (" Array" , " SubArray" )
92+ if Astype == " Array"
93+ As = As
94+ else
95+ As = sub (As, 1 : n, 1 : n)
96+ end
97+
98+ for rook in (false , true )
99+ F = bkfact (As, :U , issymmetric (As), rook)
100+ @test det (F) == 0
101+ @test_throws LinAlg. SingularException inv (F)
102+ @test_throws LinAlg. SingularException F \ ones (size (As, 1 ))
103+ end
75104 end
76105 end
77106end
0 commit comments