github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/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  	"math/rand"
    10  	"testing"
    11  
    12  	"github.com/gonum/floats"
    13  )
    14  
    15  type Dorglqer interface {
    16  	Dorgl2er
    17  	Dorglq(m, n, k int, a []float64, lda int, tau, work []float64, lwork int)
    18  }
    19  
    20  func DorglqTest(t *testing.T, impl Dorglqer) {
    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  		{10, 30, 10, 0},
    27  		{20, 30, 10, 0},
    28  
    29  		{100, 100, 100, 0},
    30  		{100, 100, 50, 0},
    31  		{100, 130, 100, 0},
    32  		{100, 130, 50, 0},
    33  		{100, 100, 100, 150},
    34  		{100, 100, 50, 150},
    35  		{100, 130, 100, 150},
    36  		{100, 130, 50, 150},
    37  
    38  		{200, 200, 200, 0},
    39  		{200, 200, 150, 0},
    40  		{200, 230, 200, 0},
    41  		{200, 230, 150, 0},
    42  		{200, 200, 200, 250},
    43  		{200, 200, 150, 250},
    44  		{200, 230, 200, 250},
    45  		{200, 230, 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, m)
    60  		for i := range tau {
    61  			tau[i] = math.NaN()
    62  		}
    63  		// Compute LQ factorization.
    64  		impl.Dgelqf(m, n, a, lda, tau, work, -1)
    65  		work = make([]float64, int(work[0]))
    66  		impl.Dgelqf(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.Dorgl2(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.Dorglq(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  }