1 // Copyright ©2015 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "golang.org/x/exp/rand"
13 "gonum.org/v1/gonum/blas"
14 "gonum.org/v1/gonum/blas/blas64"
17 type Dtrtrier interface {
19 Dtrtri(uplo blas.Uplo, diag blas.Diag, n int, a []float64, lda int) bool
22 func DtrtriTest(t *testing.T, impl Dtrtrier) {
24 rnd := rand.New(rand.NewSource(1))
25 bi := blas64.Implementation()
26 for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
27 for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
28 for _, test := range []struct {
43 a := make([]float64, n*lda)
47 for i := 0; i < n; i++ {
48 // This keeps the matrices well conditioned.
49 a[i*lda+i] += float64(n)
51 aCopy := make([]float64, len(a))
53 impl.Dtrtri(uplo, diag, n, a, lda)
54 if uplo == blas.Upper {
55 for i := 1; i < n; i++ {
56 for j := 0; j < i; j++ {
62 for i := 0; i < n; i++ {
63 for j := i + 1; j < n; j++ {
69 if diag == blas.Unit {
70 for i := 0; i < n; i++ {
75 ans := make([]float64, len(a))
76 bi.Dgemm(blas.NoTrans, blas.NoTrans, n, n, n, 1, a, lda, aCopy, lda, 0, ans, lda)
78 for i := 0; i < n; i++ {
79 for j := 0; j < n; j++ {
81 if math.Abs(ans[i*lda+i]-1) > tol {
86 if math.Abs(ans[i*lda+j]) > tol {
94 t.Errorf("inv(A) * A != I. Upper = %v, unit = %v, n = %v, lda = %v",
95 uplo == blas.Upper, diag == blas.Unit, n, lda)