github.com/gopherd/gonum@v0.0.4/blas/testblas/dsymm.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  	"math"
     9  	"testing"
    10  
    11  	"github.com/gopherd/gonum/blas"
    12  	"github.com/gopherd/gonum/floats"
    13  )
    14  
    15  type Dsymmer interface {
    16  	Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int)
    17  }
    18  
    19  func DsymmTest(t *testing.T, blasser Dsymmer) {
    20  	for i, test := range []struct {
    21  		m     int
    22  		n     int
    23  		side  blas.Side
    24  		ul    blas.Uplo
    25  		a     [][]float64
    26  		b     [][]float64
    27  		c     [][]float64
    28  		alpha float64
    29  		beta  float64
    30  		ans   [][]float64
    31  	}{
    32  		{
    33  			side: blas.Left,
    34  			ul:   blas.Upper,
    35  			m:    3,
    36  			n:    4,
    37  			a: [][]float64{
    38  				{2, 3, 4},
    39  				{0, 6, 7},
    40  				{0, 0, 10},
    41  			},
    42  			b: [][]float64{
    43  				{2, 3, 4, 8},
    44  				{5, 6, 7, 15},
    45  				{8, 9, 10, 20},
    46  			},
    47  			c: [][]float64{
    48  				{8, 12, 2, 1},
    49  				{9, 12, 9, 9},
    50  				{12, 1, -1, 5},
    51  			},
    52  			alpha: 2,
    53  			beta:  3,
    54  			ans: [][]float64{
    55  				{126, 156, 144, 285},
    56  				{211, 252, 275, 535},
    57  				{282, 291, 327, 689},
    58  			},
    59  		},
    60  		{
    61  			side: blas.Left,
    62  			ul:   blas.Upper,
    63  			m:    3,
    64  			n:    4,
    65  			a: [][]float64{
    66  				{0, 0, 0},
    67  				{0, 0, 0},
    68  				{0, 0, 0},
    69  			},
    70  			b: [][]float64{
    71  				{0, 0, 0, 0},
    72  				{0, 0, 0, 0},
    73  				{0, 0, 0, 0},
    74  			},
    75  			c: [][]float64{
    76  				{8, 12, 2, 1},
    77  				{9, 12, 9, 9},
    78  				{12, 1, -1, 5},
    79  			},
    80  			alpha: 0,
    81  			beta:  2,
    82  			ans: [][]float64{
    83  				{16, 24, 4, 2},
    84  				{18, 24, 18, 18},
    85  				{24, 2, -2, 10},
    86  			},
    87  		},
    88  		{
    89  			side: blas.Left,
    90  			ul:   blas.Upper,
    91  			m:    4,
    92  			n:    3,
    93  			a: [][]float64{
    94  				{2, 3, 4, 8},
    95  				{0, 6, 7, 9},
    96  				{0, 0, 10, 10},
    97  				{0, 0, 0, 11},
    98  			},
    99  			b: [][]float64{
   100  				{2, 3, 4},
   101  				{5, 6, 7},
   102  				{8, 9, 10},
   103  				{2, 1, 1},
   104  			},
   105  			c: [][]float64{
   106  				{8, 12, 2},
   107  				{9, 12, 9},
   108  				{12, 1, -1},
   109  				{1, 9, 5},
   110  			},
   111  			alpha: 2,
   112  			beta:  3,
   113  			ans: [][]float64{
   114  				{158, 172, 160},
   115  				{247, 270, 293},
   116  				{322, 311, 347},
   117  				{329, 385, 427},
   118  			},
   119  		},
   120  		{
   121  			side: blas.Left,
   122  			ul:   blas.Lower,
   123  			m:    3,
   124  			n:    4,
   125  			a: [][]float64{
   126  				{2, 0, 0},
   127  				{3, 6, 0},
   128  				{4, 7, 10},
   129  			},
   130  			b: [][]float64{
   131  				{2, 3, 4, 8},
   132  				{5, 6, 7, 15},
   133  				{8, 9, 10, 20},
   134  			},
   135  			c: [][]float64{
   136  				{8, 12, 2, 1},
   137  				{9, 12, 9, 9},
   138  				{12, 1, -1, 5},
   139  			},
   140  			alpha: 2,
   141  			beta:  3,
   142  			ans: [][]float64{
   143  				{126, 156, 144, 285},
   144  				{211, 252, 275, 535},
   145  				{282, 291, 327, 689},
   146  			},
   147  		},
   148  		{
   149  			side: blas.Left,
   150  			ul:   blas.Lower,
   151  			m:    4,
   152  			n:    3,
   153  			a: [][]float64{
   154  				{2, 0, 0, 0},
   155  				{3, 6, 0, 0},
   156  				{4, 7, 10, 0},
   157  				{8, 9, 10, 11},
   158  			},
   159  			b: [][]float64{
   160  				{2, 3, 4},
   161  				{5, 6, 7},
   162  				{8, 9, 10},
   163  				{2, 1, 1},
   164  			},
   165  			c: [][]float64{
   166  				{8, 12, 2},
   167  				{9, 12, 9},
   168  				{12, 1, -1},
   169  				{1, 9, 5},
   170  			},
   171  			alpha: 2,
   172  			beta:  3,
   173  			ans: [][]float64{
   174  				{158, 172, 160},
   175  				{247, 270, 293},
   176  				{322, 311, 347},
   177  				{329, 385, 427},
   178  			},
   179  		},
   180  		{
   181  			side: blas.Right,
   182  			ul:   blas.Upper,
   183  			m:    3,
   184  			n:    4,
   185  			a: [][]float64{
   186  				{2, 0, 0, 0},
   187  				{3, 6, 0, 0},
   188  				{4, 7, 10, 0},
   189  				{3, 4, 5, 6},
   190  			},
   191  			b: [][]float64{
   192  				{2, 3, 4, 9},
   193  				{5, 6, 7, -3},
   194  				{8, 9, 10, -2},
   195  			},
   196  			c: [][]float64{
   197  				{8, 12, 2, 10},
   198  				{9, 12, 9, 10},
   199  				{12, 1, -1, 10},
   200  			},
   201  			alpha: 2,
   202  			beta:  3,
   203  			ans: [][]float64{
   204  				{32, 72, 86, 138},
   205  				{47, 108, 167, -6},
   206  				{68, 111, 197, 6},
   207  			},
   208  		},
   209  		{
   210  			side: blas.Right,
   211  			ul:   blas.Upper,
   212  			m:    4,
   213  			n:    3,
   214  			a: [][]float64{
   215  				{2, 0, 0},
   216  				{3, 6, 0},
   217  				{4, 7, 10},
   218  			},
   219  			b: [][]float64{
   220  				{2, 3, 4},
   221  				{5, 6, 7},
   222  				{8, 9, 10},
   223  				{2, 1, 1},
   224  			},
   225  			c: [][]float64{
   226  				{8, 12, 2},
   227  				{9, 12, 9},
   228  				{12, 1, -1},
   229  				{1, 9, 5},
   230  			},
   231  			alpha: 2,
   232  			beta:  3,
   233  			ans: [][]float64{
   234  				{32, 72, 86},
   235  				{47, 108, 167},
   236  				{68, 111, 197},
   237  				{11, 39, 35},
   238  			},
   239  		},
   240  		{
   241  			side: blas.Right,
   242  			ul:   blas.Lower,
   243  			m:    3,
   244  			n:    4,
   245  			a: [][]float64{
   246  				{2, 0, 0, 0},
   247  				{3, 6, 0, 0},
   248  				{4, 7, 10, 0},
   249  				{3, 4, 5, 6},
   250  			},
   251  			b: [][]float64{
   252  				{2, 3, 4, 2},
   253  				{5, 6, 7, 1},
   254  				{8, 9, 10, 1},
   255  			},
   256  			c: [][]float64{
   257  				{8, 12, 2, 1},
   258  				{9, 12, 9, 9},
   259  				{12, 1, -1, 5},
   260  			},
   261  			alpha: 2,
   262  			beta:  3,
   263  			ans: [][]float64{
   264  				{94, 156, 164, 103},
   265  				{145, 244, 301, 187},
   266  				{208, 307, 397, 247},
   267  			},
   268  		},
   269  		{
   270  			side: blas.Right,
   271  			ul:   blas.Lower,
   272  			m:    4,
   273  			n:    3,
   274  			a: [][]float64{
   275  				{2, 0, 0},
   276  				{3, 6, 0},
   277  				{4, 7, 10},
   278  			},
   279  			b: [][]float64{
   280  				{2, 3, 4},
   281  				{5, 6, 7},
   282  				{8, 9, 10},
   283  				{2, 1, 1},
   284  			},
   285  			c: [][]float64{
   286  				{8, 12, 2},
   287  				{9, 12, 9},
   288  				{12, 1, -1},
   289  				{1, 9, 5},
   290  			},
   291  			alpha: 2,
   292  			beta:  3,
   293  			ans: [][]float64{
   294  				{82, 140, 144},
   295  				{139, 236, 291},
   296  				{202, 299, 387},
   297  				{25, 65, 65},
   298  			},
   299  		},
   300  
   301  		{
   302  			side: blas.Left,
   303  			ul:   blas.Upper,
   304  			m:    3,
   305  			n:    4,
   306  			a: [][]float64{
   307  				{2, 3, 4},
   308  				{0, 6, 7},
   309  				{0, 0, 10},
   310  			},
   311  			b: [][]float64{
   312  				{2, 3, 4, 8},
   313  				{5, 6, 7, 15},
   314  				{8, 9, 10, 20},
   315  			},
   316  			c: [][]float64{
   317  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   318  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   319  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   320  			},
   321  			alpha: 2,
   322  			ans: [][]float64{
   323  				{102, 120, 138, 282},
   324  				{184, 216, 248, 508},
   325  				{246, 288, 330, 674},
   326  			},
   327  		},
   328  		{
   329  			side: blas.Left,
   330  			ul:   blas.Upper,
   331  			m:    4,
   332  			n:    3,
   333  			a: [][]float64{
   334  				{2, 3, 4, 8},
   335  				{0, 6, 7, 9},
   336  				{0, 0, 10, 10},
   337  				{0, 0, 0, 11},
   338  			},
   339  			b: [][]float64{
   340  				{2, 3, 4},
   341  				{5, 6, 7},
   342  				{8, 9, 10},
   343  				{2, 1, 1},
   344  			},
   345  			c: [][]float64{
   346  				{math.NaN(), math.NaN(), math.NaN()},
   347  				{math.NaN(), math.NaN(), math.NaN()},
   348  				{math.NaN(), math.NaN(), math.NaN()},
   349  				{math.NaN(), math.NaN(), math.NaN()},
   350  			},
   351  			alpha: 2,
   352  			ans: [][]float64{
   353  				{134, 136, 154},
   354  				{220, 234, 266},
   355  				{286, 308, 350},
   356  				{326, 358, 412},
   357  			},
   358  		},
   359  		{
   360  			side: blas.Left,
   361  			ul:   blas.Lower,
   362  			m:    3,
   363  			n:    4,
   364  			a: [][]float64{
   365  				{2, 0, 0},
   366  				{3, 6, 0},
   367  				{4, 7, 10},
   368  			},
   369  			b: [][]float64{
   370  				{2, 3, 4, 8},
   371  				{5, 6, 7, 15},
   372  				{8, 9, 10, 20},
   373  			},
   374  			c: [][]float64{
   375  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   376  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   377  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   378  			},
   379  			alpha: 2,
   380  			ans: [][]float64{
   381  				{102, 120, 138, 282},
   382  				{184, 216, 248, 508},
   383  				{246, 288, 330, 674},
   384  			},
   385  		},
   386  		{
   387  			side: blas.Left,
   388  			ul:   blas.Lower,
   389  			m:    4,
   390  			n:    3,
   391  			a: [][]float64{
   392  				{2, 0, 0, 0},
   393  				{3, 6, 0, 0},
   394  				{4, 7, 10, 0},
   395  				{8, 9, 10, 11},
   396  			},
   397  			b: [][]float64{
   398  				{2, 3, 4},
   399  				{5, 6, 7},
   400  				{8, 9, 10},
   401  				{2, 1, 1},
   402  			},
   403  			c: [][]float64{
   404  				{math.NaN(), math.NaN(), math.NaN()},
   405  				{math.NaN(), math.NaN(), math.NaN()},
   406  				{math.NaN(), math.NaN(), math.NaN()},
   407  				{math.NaN(), math.NaN(), math.NaN()},
   408  			},
   409  			alpha: 2,
   410  			ans: [][]float64{
   411  				{134, 136, 154},
   412  				{220, 234, 266},
   413  				{286, 308, 350},
   414  				{326, 358, 412},
   415  			},
   416  		},
   417  		{
   418  			side: blas.Right,
   419  			ul:   blas.Upper,
   420  			m:    3,
   421  			n:    4,
   422  			a: [][]float64{
   423  				{2, 0, 0, 0},
   424  				{3, 6, 0, 0},
   425  				{4, 7, 10, 0},
   426  				{3, 4, 5, 6},
   427  			},
   428  			b: [][]float64{
   429  				{2, 3, 4, 9},
   430  				{5, 6, 7, -3},
   431  				{8, 9, 10, -2},
   432  			},
   433  			c: [][]float64{
   434  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   435  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   436  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   437  			},
   438  			alpha: 2,
   439  			ans: [][]float64{
   440  				{8, 36, 80, 108},
   441  				{20, 72, 140, -36},
   442  				{32, 108, 200, -24},
   443  			},
   444  		},
   445  		{
   446  			side: blas.Right,
   447  			ul:   blas.Upper,
   448  			m:    4,
   449  			n:    3,
   450  			a: [][]float64{
   451  				{2, 0, 0},
   452  				{3, 6, 0},
   453  				{4, 7, 10},
   454  			},
   455  			b: [][]float64{
   456  				{2, 3, 4},
   457  				{5, 6, 7},
   458  				{8, 9, 10},
   459  				{2, 1, 1},
   460  			},
   461  			c: [][]float64{
   462  				{math.NaN(), math.NaN(), math.NaN()},
   463  				{math.NaN(), math.NaN(), math.NaN()},
   464  				{math.NaN(), math.NaN(), math.NaN()},
   465  				{math.NaN(), math.NaN(), math.NaN()},
   466  			},
   467  			alpha: 2,
   468  			ans: [][]float64{
   469  				{8, 36, 80, 20},
   470  				{72, 140, 32, 108},
   471  				{200, 8, 12, 20},
   472  			},
   473  		},
   474  		{
   475  			side: blas.Right,
   476  			ul:   blas.Lower,
   477  			m:    3,
   478  			n:    4,
   479  			a: [][]float64{
   480  				{2, 0, 0, 0},
   481  				{3, 6, 0, 0},
   482  				{4, 7, 10, 0},
   483  				{3, 4, 5, 6},
   484  			},
   485  			b: [][]float64{
   486  				{2, 3, 4, 2},
   487  				{5, 6, 7, 1},
   488  				{8, 9, 10, 1},
   489  			},
   490  			c: [][]float64{
   491  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   492  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   493  				{math.NaN(), math.NaN(), math.NaN(), math.NaN()},
   494  			},
   495  			alpha: 2,
   496  			ans: [][]float64{
   497  				{70, 120, 158, 100},
   498  				{118, 208, 274, 160},
   499  				{172, 304, 400, 232},
   500  			},
   501  		},
   502  		{
   503  			side: blas.Right,
   504  			ul:   blas.Lower,
   505  			m:    4,
   506  			n:    3,
   507  			a: [][]float64{
   508  				{2, 0, 0},
   509  				{3, 6, 0},
   510  				{4, 7, 10},
   511  			},
   512  			b: [][]float64{
   513  				{2, 3, 4},
   514  				{5, 6, 7},
   515  				{8, 9, 10},
   516  				{2, 1, 1},
   517  			},
   518  			c: [][]float64{
   519  				{math.NaN(), math.NaN(), math.NaN()},
   520  				{math.NaN(), math.NaN(), math.NaN()},
   521  				{math.NaN(), math.NaN(), math.NaN()},
   522  				{math.NaN(), math.NaN(), math.NaN()},
   523  			},
   524  			alpha: 2,
   525  			ans: [][]float64{
   526  				{58, 104, 138},
   527  				{112, 200, 264},
   528  				{166, 296, 390},
   529  				{22, 38, 50},
   530  			},
   531  		},
   532  	} {
   533  		aFlat := flatten(test.a)
   534  		bFlat := flatten(test.b)
   535  		cFlat := flatten(test.c)
   536  		ansFlat := flatten(test.ans)
   537  		blasser.Dsymm(test.side, test.ul, test.m, test.n, test.alpha, aFlat, len(test.a[0]), bFlat, test.n, test.beta, cFlat, test.n)
   538  		if !floats.EqualApprox(cFlat, ansFlat, 1e-14) {
   539  			t.Errorf("Case %v: Want %v, got %v.", i, ansFlat, cFlat)
   540  		}
   541  	}
   542  }