github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dsyrk.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  	"github.com/jingcheng-WU/gonum/floats"
    12  )
    13  
    14  type Dsyker interface {
    15  	Dsyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int)
    16  }
    17  
    18  func DsyrkTest(t *testing.T, blasser Dsyker) {
    19  	for i, test := range []struct {
    20  		ul    blas.Uplo
    21  		tA    blas.Transpose
    22  		n     int
    23  		k     int
    24  		alpha float64
    25  		a     [][]float64
    26  		c     [][]float64
    27  		beta  float64
    28  		ans   [][]float64
    29  	}{
    30  		{
    31  			ul:    blas.Upper,
    32  			tA:    blas.NoTrans,
    33  			n:     3,
    34  			k:     2,
    35  			alpha: 0,
    36  			a: [][]float64{
    37  				{1, 2},
    38  				{3, 4},
    39  				{5, 6},
    40  			},
    41  			c: [][]float64{
    42  				{1, 2, 3},
    43  				{0, 5, 6},
    44  				{0, 0, 9},
    45  			},
    46  			beta: 2,
    47  			ans: [][]float64{
    48  				{2, 4, 6},
    49  				{0, 10, 12},
    50  				{0, 0, 18},
    51  			},
    52  		},
    53  		{
    54  			ul:    blas.Lower,
    55  			tA:    blas.NoTrans,
    56  			n:     3,
    57  			k:     2,
    58  			alpha: 0,
    59  			a: [][]float64{
    60  				{1, 2},
    61  				{3, 4},
    62  				{5, 6},
    63  			},
    64  			c: [][]float64{
    65  				{1, 0, 0},
    66  				{2, 3, 0},
    67  				{4, 5, 6},
    68  			},
    69  			beta: 2,
    70  			ans: [][]float64{
    71  				{2, 0, 0},
    72  				{4, 6, 0},
    73  				{8, 10, 12},
    74  			},
    75  		},
    76  		{
    77  			ul:    blas.Upper,
    78  			tA:    blas.NoTrans,
    79  			n:     3,
    80  			k:     2,
    81  			alpha: 3,
    82  			a: [][]float64{
    83  				{1, 2},
    84  				{3, 4},
    85  				{5, 6},
    86  			},
    87  			c: [][]float64{
    88  				{1, 2, 3},
    89  				{0, 4, 5},
    90  				{0, 0, 6},
    91  			},
    92  			beta: 2,
    93  			ans: [][]float64{
    94  				{17, 37, 57},
    95  				{0, 83, 127},
    96  				{0, 0, 195},
    97  			},
    98  		},
    99  		{
   100  			ul:    blas.Lower,
   101  			tA:    blas.NoTrans,
   102  			n:     3,
   103  			k:     2,
   104  			alpha: 3,
   105  			a: [][]float64{
   106  				{1, 2},
   107  				{3, 4},
   108  				{5, 6},
   109  			},
   110  			c: [][]float64{
   111  				{1, 0, 0},
   112  				{2, 4, 0},
   113  				{3, 5, 6},
   114  			},
   115  			beta: 2,
   116  			ans: [][]float64{
   117  				{17, 0, 0},
   118  				{37, 83, 0},
   119  				{57, 127, 195},
   120  			},
   121  		},
   122  		{
   123  			ul:    blas.Upper,
   124  			tA:    blas.Trans,
   125  			n:     3,
   126  			k:     2,
   127  			alpha: 3,
   128  			a: [][]float64{
   129  				{1, 3, 5},
   130  				{2, 4, 6},
   131  			},
   132  			c: [][]float64{
   133  				{1, 2, 3},
   134  				{0, 4, 5},
   135  				{0, 0, 6},
   136  			},
   137  			beta: 2,
   138  			ans: [][]float64{
   139  				{17, 37, 57},
   140  				{0, 83, 127},
   141  				{0, 0, 195},
   142  			},
   143  		},
   144  		{
   145  			ul:    blas.Lower,
   146  			tA:    blas.Trans,
   147  			n:     3,
   148  			k:     2,
   149  			alpha: 3,
   150  			a: [][]float64{
   151  				{1, 3, 5},
   152  				{2, 4, 6},
   153  			},
   154  			c: [][]float64{
   155  				{1, 0, 0},
   156  				{2, 4, 0},
   157  				{3, 5, 6},
   158  			},
   159  			beta: 2,
   160  			ans: [][]float64{
   161  				{17, 0, 0},
   162  				{37, 83, 0},
   163  				{57, 127, 195},
   164  			},
   165  		},
   166  		{
   167  			ul:    blas.Upper,
   168  			tA:    blas.Trans,
   169  			n:     3,
   170  			k:     2,
   171  			alpha: 3,
   172  			a: [][]float64{
   173  				{1, 3, 5},
   174  				{2, 4, 6},
   175  			},
   176  			c: [][]float64{
   177  				{1, 2, 3},
   178  				{0, 4, 5},
   179  				{0, 0, 6},
   180  			},
   181  			beta: 0,
   182  			ans: [][]float64{
   183  				{15, 33, 51},
   184  				{0, 75, 117},
   185  				{0, 0, 183},
   186  			},
   187  		},
   188  		{
   189  			ul:    blas.Lower,
   190  			tA:    blas.Trans,
   191  			n:     3,
   192  			k:     2,
   193  			alpha: 3,
   194  			a: [][]float64{
   195  				{1, 3, 5},
   196  				{2, 4, 6},
   197  			},
   198  			c: [][]float64{
   199  				{1, 0, 0},
   200  				{2, 4, 0},
   201  				{3, 5, 6},
   202  			},
   203  			beta: 0,
   204  			ans: [][]float64{
   205  				{15, 0, 0},
   206  				{33, 75, 0},
   207  				{51, 117, 183},
   208  			},
   209  		},
   210  	} {
   211  		aFlat := flatten(test.a)
   212  		cFlat := flatten(test.c)
   213  		ansFlat := flatten(test.ans)
   214  		blasser.Dsyrk(test.ul, test.tA, test.n, test.k, test.alpha, aFlat, len(test.a[0]), test.beta, cFlat, len(test.c[0]))
   215  		if !floats.EqualApprox(ansFlat, cFlat, 1e-14) {
   216  			t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, cFlat)
   217  		}
   218  	}
   219  }