github.com/gopherd/gonum@v0.0.4/lapack/testlapack/dgebd2.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  	"math/rand"
    11  )
    12  
    13  type Dgebd2er interface {
    14  	Dgebd2(m, n int, a []float64, lda int, d, e, tauq, taup, work []float64)
    15  }
    16  
    17  func Dgebd2Test(t *testing.T, impl Dgebd2er) {
    18  	rnd := rand.New(rand.NewSource(1))
    19  	for _, test := range []struct {
    20  		m, n, lda int
    21  	}{
    22  		{3, 4, 0},
    23  		{4, 3, 0},
    24  		{3, 4, 10},
    25  		{4, 3, 10},
    26  	} {
    27  		m := test.m
    28  		n := test.n
    29  		lda := test.lda
    30  		if lda == 0 {
    31  			lda = n
    32  		}
    33  		// Allocate m×n matrix A and fill it with random numbers.
    34  		a := make([]float64, m*lda)
    35  		for i := range a {
    36  			a[i] = rnd.NormFloat64()
    37  		}
    38  		// Store a copy of A for later comparison.
    39  		aCopy := make([]float64, len(a))
    40  		copy(aCopy, a)
    41  		// Allocate slices for the main and off diagonal.
    42  		nb := min(m, n)
    43  		d := nanSlice(nb)
    44  		e := nanSlice(nb - 1)
    45  		// Allocate slices for scalar factors of elementary reflectors
    46  		// and fill them with NaNs.
    47  		tauP := nanSlice(nb)
    48  		tauQ := nanSlice(nb)
    49  		// Allocate workspace.
    50  		work := nanSlice(max(m, n))
    51  
    52  		// Reduce A to upper or lower bidiagonal form by an orthogonal
    53  		// transformation.
    54  		impl.Dgebd2(m, n, a, lda, d, e, tauQ, tauP, work)
    55  
    56  		// Check that it holds Qᵀ * A * P = B where B is represented by
    57  		// d and e.
    58  		checkBidiagonal(t, m, n, nb, a, lda, d, e, tauP, tauQ, aCopy)
    59  	}
    60  }