gonum.org/v1/gonum@v0.14.0/lapack/testlapack/dorglq.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 Dorglqer interface {
    17  	Dorgl2er
    18  	Dorglq(m, n, k int, a []float64, lda int, tau, work []float64, lwork int)
    19  }
    20  
    21  func DorglqTest(t *testing.T, impl Dorglqer) {
    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  		{10, 30, 10, 0},
    28  		{20, 30, 10, 0},
    29  
    30  		{100, 100, 100, 0},
    31  		{100, 100, 50, 0},
    32  		{100, 130, 100, 0},
    33  		{100, 130, 50, 0},
    34  		{100, 100, 100, 150},
    35  		{100, 100, 50, 150},
    36  		{100, 130, 100, 150},
    37  		{100, 130, 50, 150},
    38  
    39  		{200, 200, 200, 0},
    40  		{200, 200, 150, 0},
    41  		{200, 230, 200, 0},
    42  		{200, 230, 150, 0},
    43  		{200, 200, 200, 250},
    44  		{200, 200, 150, 250},
    45  		{200, 230, 200, 250},
    46  		{200, 230, 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, m)
    61  		for i := range tau {
    62  			tau[i] = math.NaN()
    63  		}
    64  		// Compute LQ factorization.
    65  		impl.Dgelqf(m, n, a, lda, tau, work, -1)
    66  		work = make([]float64, int(work[0]))
    67  		impl.Dgelqf(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.Dorgl2(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.Dorglq(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  }