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.
4
5package testlapack
6
7import (
8	"testing"
9
10	"golang.org/x/exp/rand"
11
12	"gonum.org/v1/gonum/blas/blas64"
13)
14
15type Dorg2ler interface {
16	Dorg2l(m, n, k int, a []float64, lda int, tau, work []float64)
17	Dgeql2er
18}
19
20func Dorg2lTest(t *testing.T, impl Dorg2ler) {
21	rnd := rand.New(rand.NewSource(1))
22	for _, test := range []struct {
23		m, n, k, lda int
24	}{
25		{5, 4, 3, 0},
26		{5, 4, 4, 0},
27		{3, 3, 2, 0},
28		{5, 5, 5, 0},
29		{5, 4, 3, 11},
30		{5, 4, 4, 11},
31		{3, 3, 2, 11},
32		{5, 5, 5, 11},
33	} {
34		m := test.m
35		n := test.n
36		k := test.k
37		lda := test.lda
38		if lda == 0 {
39			lda = n
40		}
41
42		a := make([]float64, m*lda)
43		for i := range a {
44			a[i] = rnd.NormFloat64()
45		}
46		tau := nanSlice(max(m, n))
47		work := make([]float64, n)
48		impl.Dgeql2(m, n, a, lda, tau, work)
49
50		impl.Dorg2l(m, n, k, a, lda, tau[n-k:], work)
51		if !hasOrthonormalColumns(blas64.General{Rows: m, Cols: n, Data: a, Stride: lda}) {
52			t.Errorf("Case m=%v, n=%v, k=%v: columns of Q not orthonormal", m, n, k)
53		}
54	}
55}
56