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