github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dorgl2.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/rand" 9 "testing" 10 11 "github.com/gonum/floats" 12 ) 13 14 type Dorgl2er interface { 15 Dgelqfer 16 Dorgl2(m, n, k int, a []float64, lda int, tau []float64, work []float64) 17 } 18 19 func Dorgl2Test(t *testing.T, impl Dorgl2er) { 20 rnd := rand.New(rand.NewSource(1)) 21 for _, test := range []struct { 22 m, n, lda int 23 }{ 24 {3, 3, 0}, 25 {3, 4, 0}, 26 27 {5, 5, 20}, 28 {5, 10, 20}, 29 } { 30 m := test.m 31 n := test.n 32 lda := test.lda 33 if lda == 0 { 34 lda = test.n 35 } 36 a := make([]float64, m*lda) 37 for i := range a { 38 a[i] = rnd.NormFloat64() 39 } 40 k := min(m, n) 41 tau := make([]float64, k) 42 work := make([]float64, 1) 43 impl.Dgelqf(m, n, a, lda, tau, work, -1) 44 work = make([]float64, int(work[0])) 45 impl.Dgelqf(m, n, a, lda, tau, work, len(work)) 46 47 q := constructQ("LQ", m, n, a, lda, tau) 48 49 impl.Dorgl2(m, n, k, a, lda, tau, work) 50 51 // Check that the first m rows match. 52 same := true 53 for i := 0; i < m; i++ { 54 for j := 0; j < n; j++ { 55 if !floats.EqualWithinAbsOrRel(q.Data[i*q.Stride+j], a[i*lda+j], 1e-12, 1e-12) { 56 same = false 57 break 58 } 59 } 60 } 61 if !same { 62 t.Errorf("Q mismatch") 63 } 64 } 65 }