github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dorg2r.go (about) 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. 4 5 package testlapack 6 7 import ( 8 "fmt" 9 "math/rand" 10 "testing" 11 12 "github.com/gonum/floats" 13 ) 14 15 type Dorg2rer interface { 16 Dgeqrfer 17 Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64) 18 } 19 20 func Dorg2rTest(t *testing.T, impl Dorg2rer) { 21 rnd := rand.New(rand.NewSource(1)) 22 for _, test := range []struct { 23 m, n, k, lda int 24 }{ 25 {3, 3, 0, 0}, 26 {4, 3, 0, 0}, 27 {3, 3, 2, 0}, 28 {4, 3, 2, 0}, 29 30 {5, 5, 0, 20}, 31 {5, 5, 3, 20}, 32 {10, 5, 0, 20}, 33 {10, 5, 2, 20}, 34 } { 35 m := test.m 36 n := test.n 37 lda := test.lda 38 if lda == 0 { 39 lda = test.n 40 } 41 a := make([]float64, m*lda) 42 for i := range a { 43 a[i] = rnd.NormFloat64() 44 } 45 k := min(m, n) 46 tau := make([]float64, k) 47 work := make([]float64, 1) 48 impl.Dgeqrf(m, n, a, lda, tau, work, -1) 49 work = make([]float64, int(work[0])) 50 impl.Dgeqrf(m, n, a, lda, tau, work, len(work)) 51 52 k = test.k 53 if k == 0 { 54 k = n 55 } 56 q := constructQK("QR", m, n, k, a, lda, tau) 57 58 impl.Dorg2r(m, n, k, a, lda, tau, work) 59 60 // Check that the first n columns match. 61 same := true 62 for i := 0; i < m; i++ { 63 for j := 0; j < n; j++ { 64 if !floats.EqualWithinAbsOrRel(q.Data[i*q.Stride+j], a[i*lda+j], 1e-12, 1e-12) { 65 same = false 66 break 67 } 68 } 69 } 70 if !same { 71 fmt.Println() 72 fmt.Println("a =") 73 printRowise(a, m, n, lda, false) 74 fmt.Println("q =") 75 printRowise(q.Data, q.Rows, q.Cols, q.Stride, false) 76 t.Errorf("Q mismatch") 77 } 78 } 79 }