Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Commit bbfcdb5

Browse files
committed
testlapack: use Dlagsy in Dpotrf test and check expected failure for not PD matrices
1 parent 048a65f commit bbfcdb5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

testlapack/dpotrf.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,25 @@ func DpotrfTest(t *testing.T, impl Dpotrfer) {
4848
{500, 600},
4949
} {
5050
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.
5159
lda := test.lda
5260
if lda == 0 {
5361
lda = n
5462
}
55-
// Construct a diagonally-dominant symmetric matrix.
56-
// Such a matrix is positive definite.
5763
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))
6765

6866
aCopy := make([]float64, len(a))
6967
copy(aCopy, a)
7068

7169
ok := impl.Dpotrf(uplo, n, a, lda)
72-
7370
if !ok {
7471
t.Errorf("Case %v: unexpected failure for positive definite matrix", tc)
7572
continue
@@ -122,7 +119,16 @@ func DpotrfTest(t *testing.T, impl Dpotrfer) {
122119
}
123120
}
124121
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)
126132
}
127133
}
128134
}

0 commit comments

Comments
 (0)