1 // Copyright ©2016 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/blas/blas64"
16 type Dorg2ler interface {
17 Dorg2l(m, n, k int, a []float64, lda int, tau, work []float64)
21 func Dorg2lTest(t *testing.T, impl Dorg2ler) {
22 rnd := rand.New(rand.NewSource(1))
23 for _, test := range []struct {
39 a := make([]float64, m*lda)
41 a[i] = rnd.NormFloat64()
43 tau := nanSlice(max(m, n))
44 work := make([]float64, n)
45 impl.Dgeql2(m, n, a, lda, tau, work)
47 aCopy := make([]float64, len(a))
49 impl.Dorg2l(m, n, k, a, lda, tau[n-k:], work)
50 if !hasOrthonormalColumns(m, n, a, lda) {
51 t.Errorf("Q is not orthonormal. m = %v, n = %v, k = %v", m, n, k)
56 // hasOrthornormalColumns checks that the columns of a are orthonormal.
57 func hasOrthonormalColumns(m, n int, a []float64, lda int) bool {
58 for i := 0; i < n; i++ {
59 for j := i; j < n; j++ {
61 blas64.Vector{Inc: lda, Data: a[i:]},
62 blas64.Vector{Inc: lda, Data: a[j:]},
65 if math.Abs(dot-1) > 1e-10 {
69 if math.Abs(dot) > 1e-10 {