@@ -48,28 +48,25 @@ func DpotrfTest(t *testing.T, impl Dpotrfer) {
48
48
{500 , 600 },
49
49
} {
50
50
n := test .n
51
+
52
+ // Random diagonal matrix D with positive entries.
53
+ d := make ([]float64 , n )
54
+ Dlatm1 (d , 4 , 10000 , false , 1 , rnd )
55
+
56
+ // Construct a positive definite matrix A as
57
+ // A = U * D * U^T
58
+ // where U is a random orthogonal matrix.
51
59
lda := test .lda
52
60
if lda == 0 {
53
61
lda = n
54
62
}
55
- // Construct a diagonally-dominant symmetric matrix.
56
- // Such a matrix is positive definite.
57
63
a := make ([]float64 , n * lda )
58
- for i := range a {
59
- a [i ] = rnd .Float64 ()
60
- }
61
- for i := 0 ; i < n ; i ++ {
62
- a [i * lda + i ] += float64 (n )
63
- for j := 0 ; j < i ; j ++ {
64
- a [i * lda + j ] = a [j * lda + i ]
65
- }
66
- }
64
+ Dlagsy (n , d , a , lda , rnd , make ([]float64 , 2 * n ))
67
65
68
66
aCopy := make ([]float64 , len (a ))
69
67
copy (aCopy , a )
70
68
71
69
ok := impl .Dpotrf (uplo , n , a , lda )
72
-
73
70
if ! ok {
74
71
t .Errorf ("Case %v: unexpected failure for positive definite matrix" , tc )
75
72
continue
@@ -122,7 +119,16 @@ func DpotrfTest(t *testing.T, impl Dpotrfer) {
122
119
}
123
120
}
124
121
if ! match {
125
- t .Errorf ("Case %v (uplo=%v,n=%v,lda=%v): unexpected result\n %v\n %v" , tc , uplo , n , lda , ans , aCopy )
122
+ t .Errorf ("Case %v (uplo=%v,n=%v,lda=%v): unexpected result" , tc , uplo , n , lda )
123
+ }
124
+
125
+ // Make one element of D negative so that A is not
126
+ // positive definite, and check that Dpotrf fails.
127
+ d [0 ] *= - 1
128
+ Dlagsy (n , d , a , lda , rnd , make ([]float64 , 2 * n ))
129
+ ok = impl .Dpotrf (uplo , n , a , lda )
130
+ if ok {
131
+ t .Errorf ("Case %v: unexpected success for not positive definite matrix" , tc )
126
132
}
127
133
}
128
134
}
0 commit comments