OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / testlapack / dpbtf2.go
1 package testlapack
2
3 import (
4         "testing"
5
6         "golang.org/x/exp/rand"
7
8         "gonum.org/v1/gonum/blas"
9 )
10
11 type Dpbtf2er interface {
12         Dpbtf2(ul blas.Uplo, n, kd int, ab []float64, ldab int) (ok bool)
13         Dpotrfer
14 }
15
16 func Dpbtf2Test(t *testing.T, impl Dpbtf2er) {
17         // Test random symmetric banded matrices against the full version.
18         rnd := rand.New(rand.NewSource(1))
19
20         for _, n := range []int{5, 10, 20} {
21                 for _, kb := range []int{0, 1, 3, n - 1} {
22                         for _, ldoff := range []int{0, 4} {
23                                 for _, ul := range []blas.Uplo{blas.Upper, blas.Lower} {
24                                         ldab := kb + 1 + ldoff
25                                         sym, band := randSymBand(ul, n, ldab, kb, rnd)
26
27                                         // Compute the Cholesky decomposition of the symmetric matrix.
28                                         ok := impl.Dpotrf(ul, sym.N, sym.Data, sym.Stride)
29                                         if !ok {
30                                                 panic("bad test: symmetric cholesky decomp failed")
31                                         }
32
33                                         // Compute the Cholesky decomposition of the banded matrix.
34                                         ok = impl.Dpbtf2(band.Uplo, band.N, band.K, band.Data, band.Stride)
35                                         if !ok {
36                                                 t.Errorf("SymBand cholesky decomp failed")
37                                         }
38
39                                         // Compare the result to the Symmetric decomposition.
40                                         sb := symBandToSym(ul, band.Data, n, kb, ldab)
41                                         if !equalApproxSymmetric(sym, sb, 1e-10) {
42                                                 t.Errorf("chol mismatch banded and sym. n = %v, kb = %v, ldoff = %v", n, kb, ldoff)
43                                         }
44                                 }
45                         }
46                 }
47         }
48 }