gonum.org/v1/gonum@v0.14.0/blas/testblas/dsyr.go (about)

     1  // Copyright ©2014 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 testblas
     6  
     7  import (
     8  	"testing"
     9  
    10  	"gonum.org/v1/gonum/blas"
    11  )
    12  
    13  type Dsyrer interface {
    14  	Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int)
    15  }
    16  
    17  func DsyrTest(t *testing.T, blasser Dsyrer) {
    18  	for i, test := range []struct {
    19  		ul    blas.Uplo
    20  		n     int
    21  		a     [][]float64
    22  		x     []float64
    23  		alpha float64
    24  		ans   [][]float64
    25  	}{
    26  		{
    27  			ul: blas.Upper,
    28  			n:  4,
    29  			a: [][]float64{
    30  				{10, 2, 0, 1},
    31  				{0, 1, 2, 3},
    32  				{0, 0, 9, 15},
    33  				{0, 0, 0, -6},
    34  			},
    35  			x:     []float64{1, 2, 0, 5},
    36  			alpha: 8,
    37  			ans: [][]float64{
    38  				{18, 18, 0, 41},
    39  				{0, 33, 2, 83},
    40  				{0, 0, 9, 15},
    41  				{0, 0, 0, 194},
    42  			},
    43  		},
    44  		{
    45  			ul: blas.Lower,
    46  			n:  3,
    47  			a: [][]float64{
    48  				{10, 2, 0},
    49  				{4, 1, 2},
    50  				{2, 7, 9},
    51  			},
    52  			x:     []float64{3, 0, 5},
    53  			alpha: 8,
    54  			ans: [][]float64{
    55  				{82, 2, 0},
    56  				{4, 1, 2},
    57  				{122, 7, 209},
    58  			},
    59  		},
    60  	} {
    61  		incTest := func(incX, extra int) {
    62  			xnew := makeIncremented(test.x, incX, extra)
    63  			aFlat := flatten(test.a)
    64  			ans := flatten(test.ans)
    65  			lda := test.n
    66  			blasser.Dsyr(test.ul, test.n, test.alpha, xnew, incX, aFlat, lda)
    67  			if !dSliceTolEqual(aFlat, ans) {
    68  				t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, aFlat)
    69  			}
    70  		}
    71  		incTest(1, 3)
    72  		incTest(1, 0)
    73  		incTest(3, 2)
    74  		incTest(-2, 2)
    75  	}
    76  }