gonum.org/v1/gonum@v0.14.0/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  	"gonum.org/v1/gonum/blas"
    11  	"gonum.org/v1/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.Upper,
   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, 2, 3},
   112  				{0, 4, 5},
   113  				{0, 0, 6},
   114  			},
   115  			beta: 0,
   116  			ans: [][]float64{
   117  				{15, 33, 51},
   118  				{0, 75, 117},
   119  				{0, 0, 183},
   120  			},
   121  		},
   122  		{
   123  			ul:    blas.Lower,
   124  			tA:    blas.NoTrans,
   125  			n:     3,
   126  			k:     2,
   127  			alpha: 3,
   128  			a: [][]float64{
   129  				{1, 2},
   130  				{3, 4},
   131  				{5, 6},
   132  			},
   133  			c: [][]float64{
   134  				{1, 0, 0},
   135  				{2, 4, 0},
   136  				{3, 5, 6},
   137  			},
   138  			beta: 2,
   139  			ans: [][]float64{
   140  				{17, 0, 0},
   141  				{37, 83, 0},
   142  				{57, 127, 195},
   143  			},
   144  		},
   145  		{
   146  			ul:    blas.Lower,
   147  			tA:    blas.NoTrans,
   148  			n:     3,
   149  			k:     2,
   150  			alpha: 3,
   151  			a: [][]float64{
   152  				{1, 2},
   153  				{3, 4},
   154  				{5, 6},
   155  			},
   156  			c: [][]float64{
   157  				{1, 0, 0},
   158  				{2, 4, 0},
   159  				{3, 5, 6},
   160  			},
   161  			beta: 0,
   162  			ans: [][]float64{
   163  				{15, 0, 0},
   164  				{33, 75, 0},
   165  				{51, 117, 183},
   166  			},
   167  		},
   168  		{
   169  			ul:    blas.Upper,
   170  			tA:    blas.Trans,
   171  			n:     3,
   172  			k:     2,
   173  			alpha: 3,
   174  			a: [][]float64{
   175  				{1, 3, 5},
   176  				{2, 4, 6},
   177  			},
   178  			c: [][]float64{
   179  				{1, 2, 3},
   180  				{0, 4, 5},
   181  				{0, 0, 6},
   182  			},
   183  			beta: 2,
   184  			ans: [][]float64{
   185  				{17, 37, 57},
   186  				{0, 83, 127},
   187  				{0, 0, 195},
   188  			},
   189  		},
   190  		{
   191  			ul:    blas.Lower,
   192  			tA:    blas.Trans,
   193  			n:     3,
   194  			k:     2,
   195  			alpha: 3,
   196  			a: [][]float64{
   197  				{1, 3, 5},
   198  				{2, 4, 6},
   199  			},
   200  			c: [][]float64{
   201  				{1, 0, 0},
   202  				{2, 4, 0},
   203  				{3, 5, 6},
   204  			},
   205  			beta: 2,
   206  			ans: [][]float64{
   207  				{17, 0, 0},
   208  				{37, 83, 0},
   209  				{57, 127, 195},
   210  			},
   211  		},
   212  		{
   213  			ul:    blas.Upper,
   214  			tA:    blas.Trans,
   215  			n:     3,
   216  			k:     2,
   217  			alpha: 3,
   218  			a: [][]float64{
   219  				{1, 3, 5},
   220  				{2, 4, 6},
   221  			},
   222  			c: [][]float64{
   223  				{1, 2, 3},
   224  				{0, 4, 5},
   225  				{0, 0, 6},
   226  			},
   227  			beta: 0,
   228  			ans: [][]float64{
   229  				{15, 33, 51},
   230  				{0, 75, 117},
   231  				{0, 0, 183},
   232  			},
   233  		},
   234  		{
   235  			ul:    blas.Lower,
   236  			tA:    blas.Trans,
   237  			n:     3,
   238  			k:     2,
   239  			alpha: 3,
   240  			a: [][]float64{
   241  				{1, 3, 5},
   242  				{2, 4, 6},
   243  			},
   244  			c: [][]float64{
   245  				{1, 0, 0},
   246  				{2, 4, 0},
   247  				{3, 5, 6},
   248  			},
   249  			beta: 0,
   250  			ans: [][]float64{
   251  				{15, 0, 0},
   252  				{33, 75, 0},
   253  				{51, 117, 183},
   254  			},
   255  		},
   256  		{
   257  			ul:    blas.Lower,
   258  			tA:    blas.Trans,
   259  			n:     3,
   260  			k:     2,
   261  			alpha: 0,
   262  			a: [][]float64{
   263  				{1, 3, 5},
   264  				{2, 4, 6},
   265  			},
   266  			c: [][]float64{
   267  				{1, 0, 0},
   268  				{2, 4, 0},
   269  				{3, 5, 6},
   270  			},
   271  			beta: 0,
   272  			ans: [][]float64{
   273  				{0, 0, 0},
   274  				{0, 0, 0},
   275  				{0, 0, 0},
   276  			},
   277  		},
   278  		{
   279  			ul:    blas.Upper,
   280  			tA:    blas.Trans,
   281  			n:     3,
   282  			k:     2,
   283  			alpha: 0,
   284  			a: [][]float64{
   285  				{1, 3, 5},
   286  				{2, 4, 6},
   287  			},
   288  			c: [][]float64{
   289  				{1, 2, 3},
   290  				{0, 4, 5},
   291  				{0, 0, 6},
   292  			},
   293  			beta: 0,
   294  			ans: [][]float64{
   295  				{0, 0, 0},
   296  				{0, 0, 0},
   297  				{0, 0, 0},
   298  			},
   299  		},
   300  	} {
   301  		aFlat := flatten(test.a)
   302  		cFlat := flatten(test.c)
   303  		ansFlat := flatten(test.ans)
   304  		blasser.Dsyrk(test.ul, test.tA, test.n, test.k, test.alpha, aFlat, len(test.a[0]), test.beta, cFlat, len(test.c[0]))
   305  		if !floats.EqualApprox(ansFlat, cFlat, 1e-14) {
   306  			t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, cFlat)
   307  		}
   308  	}
   309  }