6 "golang.org/x/exp/rand"
8 "gonum.org/v1/gonum/blas"
11 type Dpbtf2er interface {
12 Dpbtf2(ul blas.Uplo, n, kd int, ab []float64, ldab int) (ok bool)
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))
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)
27 // Compute the Cholesky decomposition of the symmetric matrix.
28 ok := impl.Dpotrf(ul, sym.N, sym.Data, sym.Stride)
30 panic("bad test: symmetric cholesky decomp failed")
33 // Compute the Cholesky decomposition of the banded matrix.
34 ok = impl.Dpbtf2(band.Uplo, band.N, band.K, band.Data, band.Stride)
36 t.Errorf("SymBand cholesky decomp failed")
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)