github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dsbmv.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  	"github.com/jingcheng-WU/gonum/blas"
    11  )
    12  
    13  type Dsbmver interface {
    14  	Dsbmv(ul blas.Uplo, n, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int)
    15  }
    16  
    17  func DsbmvTest(t *testing.T, blasser Dsbmver) {
    18  	for i, test := range []struct {
    19  		ul    blas.Uplo
    20  		n     int
    21  		k     int
    22  		alpha float64
    23  		beta  float64
    24  		a     [][]float64
    25  		x     []float64
    26  		y     []float64
    27  
    28  		ans []float64
    29  	}{
    30  		{
    31  			ul:    blas.Upper,
    32  			n:     4,
    33  			k:     2,
    34  			alpha: 2,
    35  			beta:  3,
    36  			a: [][]float64{
    37  				{7, 8, 2, 0},
    38  				{0, 8, 2, -3},
    39  				{0, 0, 3, 6},
    40  				{0, 0, 0, 9},
    41  			},
    42  			x:   []float64{1, 2, 3, 4},
    43  			y:   []float64{-1, -2, -3, -4},
    44  			ans: []float64{55, 30, 69, 84},
    45  		},
    46  		{
    47  			ul:    blas.Lower,
    48  			n:     4,
    49  			k:     2,
    50  			alpha: 2,
    51  			beta:  3,
    52  			a: [][]float64{
    53  				{7, 0, 0, 0},
    54  				{8, 8, 0, 0},
    55  				{2, 2, 3, 0},
    56  				{0, -3, 6, 9},
    57  			},
    58  			x:   []float64{1, 2, 3, 4},
    59  			y:   []float64{-1, -2, -3, -4},
    60  			ans: []float64{55, 30, 69, 84},
    61  		},
    62  	} {
    63  		extra := 0
    64  		var aFlat []float64
    65  		if test.ul == blas.Upper {
    66  			aFlat = flattenBanded(test.a, test.k, 0)
    67  		} else {
    68  			aFlat = flattenBanded(test.a, 0, test.k)
    69  		}
    70  		incTest := func(incX, incY, extra int) {
    71  			xnew := makeIncremented(test.x, incX, extra)
    72  			ynew := makeIncremented(test.y, incY, extra)
    73  			ans := makeIncremented(test.ans, incY, extra)
    74  			blasser.Dsbmv(test.ul, test.n, test.k, test.alpha, aFlat, test.k+1, xnew, incX, test.beta, ynew, incY)
    75  			if !dSliceTolEqual(ans, ynew) {
    76  				t.Errorf("Case %v: Want %v, got %v", i, ans, ynew)
    77  			}
    78  		}
    79  		incTest(1, 1, extra)
    80  		incTest(1, 3, extra)
    81  		incTest(1, -3, extra)
    82  		incTest(2, 3, extra)
    83  		incTest(2, -3, extra)
    84  		incTest(3, 2, extra)
    85  		incTest(-3, 2, extra)
    86  	}
    87  }