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.
10 "golang.org/x/exp/rand"
12 "gonum.org/v1/gonum/floats"
15 type Dorgl2er interface {
17 Dorgl2(m, n, k int, a []float64, lda int, tau []float64, work []float64)
20 func Dorgl2Test(t *testing.T, impl Dorgl2er) {
21 rnd := rand.New(rand.NewSource(1))
22 for _, test := range []struct {
37 a := make([]float64, m*lda)
39 a[i] = rnd.NormFloat64()
42 tau := make([]float64, k)
43 work := make([]float64, 1)
44 impl.Dgelqf(m, n, a, lda, tau, work, -1)
45 work = make([]float64, int(work[0]))
46 impl.Dgelqf(m, n, a, lda, tau, work, len(work))
48 q := constructQ("LQ", m, n, a, lda, tau)
50 impl.Dorgl2(m, n, k, a, lda, tau, work)
52 // Check that the first m rows match.
54 for i := 0; i < m; i++ {
55 for j := 0; j < n; j++ {
56 if !floats.EqualWithinAbsOrRel(q.Data[i*q.Stride+j], a[i*lda+j], 1e-12, 1e-12) {
63 t.Errorf("Q mismatch")