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