OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / testlapack / dorg2r.go
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.
4
5 package testlapack
6
7 import (
8         "fmt"
9         "testing"
10
11         "golang.org/x/exp/rand"
12
13         "gonum.org/v1/gonum/floats"
14 )
15
16 type Dorg2rer interface {
17         Dgeqrfer
18         Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64)
19 }
20
21 func Dorg2rTest(t *testing.T, impl Dorg2rer) {
22         rnd := rand.New(rand.NewSource(1))
23         for _, test := range []struct {
24                 m, n, k, lda int
25         }{
26                 {3, 3, 0, 0},
27                 {4, 3, 0, 0},
28                 {3, 3, 2, 0},
29                 {4, 3, 2, 0},
30
31                 {5, 5, 0, 20},
32                 {5, 5, 3, 20},
33                 {10, 5, 0, 20},
34                 {10, 5, 2, 20},
35         } {
36                 m := test.m
37                 n := test.n
38                 lda := test.lda
39                 if lda == 0 {
40                         lda = test.n
41                 }
42                 a := make([]float64, m*lda)
43                 for i := range a {
44                         a[i] = rnd.NormFloat64()
45                 }
46                 k := min(m, n)
47                 tau := make([]float64, k)
48                 work := make([]float64, 1)
49                 impl.Dgeqrf(m, n, a, lda, tau, work, -1)
50                 work = make([]float64, int(work[0]))
51                 impl.Dgeqrf(m, n, a, lda, tau, work, len(work))
52
53                 k = test.k
54                 if k == 0 {
55                         k = n
56                 }
57                 q := constructQK("QR", m, n, k, a, lda, tau)
58
59                 impl.Dorg2r(m, n, k, a, lda, tau, work)
60
61                 // Check that the first n columns match.
62                 same := true
63                 for i := 0; i < m; i++ {
64                         for j := 0; j < n; j++ {
65                                 if !floats.EqualWithinAbsOrRel(q.Data[i*q.Stride+j], a[i*lda+j], 1e-12, 1e-12) {
66                                         same = false
67                                         break
68                                 }
69                         }
70                 }
71                 if !same {
72                         fmt.Println()
73                         fmt.Println("a =")
74                         printRowise(a, m, n, lda, false)
75                         fmt.Println("q =")
76                         printRowise(q.Data, q.Rows, q.Cols, q.Stride, false)
77                         t.Errorf("Q mismatch")
78                 }
79         }
80 }