github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dlarfx.go (about)

     1  // Copyright ©2016 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  	"fmt"
     9  	"math/rand"
    10  	"testing"
    11  
    12  	"github.com/gonum/blas"
    13  	"github.com/gonum/blas/blas64"
    14  )
    15  
    16  type Dlarfxer interface {
    17  	Dlarfx(side blas.Side, m, n int, v []float64, tau float64, c []float64, ldc int, work []float64)
    18  }
    19  
    20  func DlarfxTest(t *testing.T, impl Dlarfxer) {
    21  	rnd := rand.New(rand.NewSource(1))
    22  	for _, side := range []blas.Side{blas.Right, blas.Left} {
    23  		for m := 1; m < 12; m++ {
    24  			for n := 1; n < 12; n++ {
    25  				for _, extra := range []int{0, 1, 11} {
    26  					for cas := 0; cas < 10; cas++ {
    27  						testDlarfx(t, impl, side, m, n, extra, rnd)
    28  					}
    29  				}
    30  			}
    31  		}
    32  	}
    33  }
    34  
    35  func testDlarfx(t *testing.T, impl Dlarfxer, side blas.Side, m, n, extra int, rnd *rand.Rand) {
    36  	const tol = 1e-13
    37  
    38  	c := randomGeneral(m, n, n+extra, rnd)
    39  	cWant := randomGeneral(m, n, n+extra, rnd)
    40  	tau := rnd.NormFloat64()
    41  
    42  	var (
    43  		v []float64
    44  		h blas64.General
    45  	)
    46  	if side == blas.Left {
    47  		v = randomSlice(m, rnd)
    48  		h = eye(m, m+extra)
    49  	} else {
    50  		v = randomSlice(n, rnd)
    51  		h = eye(n, n+extra)
    52  	}
    53  	blas64.Ger(-tau, blas64.Vector{Inc: 1, Data: v}, blas64.Vector{Inc: 1, Data: v}, h)
    54  	if side == blas.Left {
    55  		blas64.Gemm(blas.NoTrans, blas.NoTrans, 1, h, c, 0, cWant)
    56  	} else {
    57  		blas64.Gemm(blas.NoTrans, blas.NoTrans, 1, c, h, 0, cWant)
    58  	}
    59  
    60  	var work []float64
    61  	if h.Rows > 10 {
    62  		// Allocate work only if H has order > 10.
    63  		if side == blas.Left {
    64  			work = make([]float64, n)
    65  		} else {
    66  			work = make([]float64, m)
    67  		}
    68  	}
    69  
    70  	impl.Dlarfx(side, m, n, v, tau, c.Data, c.Stride, work)
    71  
    72  	prefix := fmt.Sprintf("Case side=%v, m=%v, n=%v, extra=%v", side, m, n, extra)
    73  
    74  	// Check any invalid modifications of c.
    75  	if !generalOutsideAllNaN(c) {
    76  		t.Errorf("%v: out-of-range write to C\n%v", prefix, c.Data)
    77  	}
    78  
    79  	if !equalApproxGeneral(c, cWant, tol) {
    80  		t.Errorf("%v: unexpected C\n%v", prefix, c.Data)
    81  	}
    82  }