github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dlabrd.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  
    13  type Dlabrder interface {
    14  	Dlabrd(m, n, nb int, a []float64, lda int, d, e, tauq, taup, x []float64, ldx int, y []float64, ldy int)
    15  }
    16  
    17  func DlabrdTest(t *testing.T, impl Dlabrder) {
    18  	rnd := rand.New(rand.NewSource(1))
    19  	for _, test := range []struct {
    20  		m, n, nb, lda, ldx, ldy int
    21  	}{
    22  		{4, 5, 2, 0, 0, 0},
    23  		{4, 5, 4, 0, 0, 0},
    24  		{5, 5, 2, 0, 0, 0},
    25  		{5, 5, 5, 0, 0, 0},
    26  		{5, 4, 4, 0, 0, 0},
    27  		{5, 4, 4, 0, 0, 0},
    28  
    29  		{4, 5, 2, 10, 11, 12},
    30  		{4, 5, 4, 10, 11, 12},
    31  		{5, 5, 2, 10, 11, 12},
    32  		{5, 5, 5, 10, 11, 12},
    33  		{5, 4, 2, 10, 11, 12},
    34  		{5, 4, 4, 10, 11, 12},
    35  
    36  		{4, 5, 2, 11, 12, 10},
    37  		{4, 5, 4, 11, 12, 10},
    38  		{5, 5, 2, 11, 12, 10},
    39  		{5, 5, 5, 11, 12, 10},
    40  		{5, 4, 2, 11, 12, 10},
    41  		{5, 4, 4, 11, 12, 10},
    42  
    43  		{4, 5, 2, 12, 11, 10},
    44  		{4, 5, 4, 12, 11, 10},
    45  		{5, 5, 2, 12, 11, 10},
    46  		{5, 5, 5, 12, 11, 10},
    47  		{5, 4, 2, 12, 11, 10},
    48  		{5, 4, 4, 12, 11, 10},
    49  	} {
    50  		m := test.m
    51  		n := test.n
    52  		nb := test.nb
    53  		lda := test.lda
    54  		if lda == 0 {
    55  			lda = n
    56  		}
    57  		ldy := test.ldy
    58  		if ldy == 0 {
    59  			ldy = nb
    60  		}
    61  		ldx := test.ldx
    62  		if ldx == 0 {
    63  			ldx = nb
    64  		}
    65  		a := make([]float64, m*lda)
    66  		for i := range a {
    67  			a[i] = rnd.NormFloat64()
    68  		}
    69  		d := make([]float64, nb)
    70  		for i := range d {
    71  			d[i] = math.NaN()
    72  		}
    73  		e := make([]float64, nb)
    74  		for i := range e {
    75  			e[i] = math.NaN()
    76  		}
    77  		tauP := make([]float64, nb)
    78  		for i := range tauP {
    79  			tauP[i] = math.NaN()
    80  		}
    81  		tauQ := make([]float64, nb)
    82  		for i := range tauP {
    83  			tauQ[i] = math.NaN()
    84  		}
    85  		x := make([]float64, m*ldx)
    86  		for i := range x {
    87  			x[i] = rnd.NormFloat64()
    88  		}
    89  		y := make([]float64, n*ldy)
    90  		for i := range y {
    91  			y[i] = rnd.NormFloat64()
    92  		}
    93  		aCopy := make([]float64, len(a))
    94  		copy(aCopy, a)
    95  
    96  		// Compute the reduction.
    97  		impl.Dlabrd(m, n, nb, a, lda, d, e, tauQ, tauP, x, ldx, y, ldy)
    98  
    99  		if m >= n && nb == n {
   100  			tauP[n-1] = 0
   101  		}
   102  		if m < n && nb == m {
   103  			tauQ[m-1] = 0
   104  		}
   105  		checkBidiagonal(t, m, n, nb, a, lda, d, e, tauP, tauQ, aCopy)
   106  	}
   107  }