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/floats"
16 type Dorg2rer interface {
18 Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64)
21 func Dorg2rTest(t *testing.T, impl Dorg2rer) {
22 rnd := rand.New(rand.NewSource(1))
23 for _, test := range []struct {
42 a := make([]float64, m*lda)
44 a[i] = rnd.NormFloat64()
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))
57 q := constructQK("QR", m, n, k, a, lda, tau)
59 impl.Dorg2r(m, n, k, a, lda, tau, work)
61 // Check that the first n columns match.
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) {
74 printRowise(a, m, n, lda, false)
76 printRowise(q.Data, q.Rows, q.Cols, q.Stride, false)
77 t.Errorf("Q mismatch")