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