github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dorgqr.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 "math" 9 "math/rand" 10 "testing" 11 12 "github.com/gonum/floats" 13 ) 14 15 type Dorgqrer interface { 16 Dorg2rer 17 Dorgqr(m, n, k int, a []float64, lda int, tau, work []float64, lwork int) 18 } 19 20 func DorgqrTest(t *testing.T, impl Dorgqrer) { 21 rnd := rand.New(rand.NewSource(1)) 22 // TODO(btracey): Base tests off of nb and nx. 23 for _, test := range []struct{ m, n, k, lda int }{ 24 {10, 10, 10, 0}, 25 {10, 10, 10, 20}, 26 {30, 10, 10, 0}, 27 {30, 20, 10, 20}, 28 29 {100, 100, 100, 0}, 30 {100, 100, 50, 0}, 31 {130, 100, 100, 0}, 32 {130, 100, 50, 0}, 33 {100, 100, 100, 150}, 34 {100, 100, 50, 150}, 35 {130, 100, 100, 150}, 36 {130, 100, 50, 150}, 37 38 {200, 200, 200, 0}, 39 {200, 200, 150, 0}, 40 {230, 200, 200, 0}, 41 {230, 200, 150, 0}, 42 {200, 200, 200, 250}, 43 {200, 200, 150, 250}, 44 {230, 200, 200, 250}, 45 {230, 200, 150, 250}, 46 } { 47 m := test.m 48 n := test.n 49 k := test.k 50 lda := test.lda 51 if lda == 0 { 52 lda = n 53 } 54 a := make([]float64, m*lda) 55 for i := range a { 56 a[i] = rnd.Float64() 57 } 58 work := make([]float64, 1) 59 tau := make([]float64, n) 60 for i := range tau { 61 tau[i] = math.NaN() 62 } 63 // Compute QR factorization. 64 impl.Dgeqrf(m, n, a, lda, tau, work, -1) 65 work = make([]float64, int(work[0])) 66 impl.Dgeqrf(m, n, a, lda, tau, work, len(work)) 67 68 aUnblocked := make([]float64, len(a)) 69 copy(aUnblocked, a) 70 for i := range work { 71 work[i] = math.NaN() 72 } 73 impl.Dorg2r(m, n, k, aUnblocked, lda, tau, work) 74 // make sure work isn't used before initialized 75 for i := range work { 76 work[i] = math.NaN() 77 } 78 impl.Dorgqr(m, n, k, a, lda, tau, work, len(work)) 79 if !floats.EqualApprox(a, aUnblocked, 1e-10) { 80 t.Errorf("Q Mismatch. m = %d, n = %d, k = %d, lda = %d", m, n, k, lda) 81 } 82 } 83 }