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"
15 "gonum.org/v1/gonum/floats"
18 type Dtrti2er interface {
19 Dtrti2(uplo blas.Uplo, diag blas.Diag, n int, a []float64, lda int)
22 func Dtrti2Test(t *testing.T, impl Dtrti2er) {
24 for _, test := range []struct {
88 impl.Dtrti2(test.uplo, test.diag, test.n, test.a, test.n)
89 if !floats.EqualApprox(test.ans, test.a, tol) {
90 t.Errorf("Matrix inverse mismatch. Want %v, got %v.", test.ans, test.a)
93 rnd := rand.New(rand.NewSource(1))
94 bi := blas64.Implementation()
95 for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
96 for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
97 for _, test := range []struct {
112 a := make([]float64, n*lda)
116 aCopy := make([]float64, len(a))
118 impl.Dtrti2(uplo, diag, n, a, lda)
119 if uplo == blas.Upper {
120 for i := 1; i < n; i++ {
121 for j := 0; j < i; j++ {
127 for i := 0; i < n; i++ {
128 for j := i + 1; j < n; j++ {
134 if diag == blas.Unit {
135 for i := 0; i < n; i++ {
140 ans := make([]float64, len(a))
141 bi.Dgemm(blas.NoTrans, blas.NoTrans, n, n, n, 1, a, lda, aCopy, lda, 0, ans, lda)
143 for i := 0; i < n; i++ {
144 for j := 0; j < n; j++ {
146 if math.Abs(ans[i*lda+i]-1) > tol {
151 if math.Abs(ans[i*lda+j]) > tol {
159 t.Errorf("inv(A) * A != I. Upper = %v, unit = %v, ans = %v", uplo == blas.Upper, diag == blas.Unit, ans)