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

     1  // Copyright ©2017 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  
    11  type Zgeruer interface {
    12  	Zgeru(m, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int)
    13  }
    14  
    15  func ZgeruTest(t *testing.T, impl Zgeruer) {
    16  	for tc, test := range []struct {
    17  		alpha complex128
    18  		x     []complex128
    19  		incX  int
    20  		y     []complex128
    21  		incY  int
    22  		a     []complex128
    23  
    24  		want []complex128
    25  	}{
    26  		{
    27  			incX:  1,
    28  			incY:  1,
    29  			alpha: 1 + 2i,
    30  		},
    31  		{
    32  			incX:  1,
    33  			incY:  1,
    34  			alpha: 1 + 2i,
    35  			x:     []complex128{1 + 13i, 18 + 15i, 10 + 18i},
    36  			y:     []complex128{15 + 12i, 4 + 8i, 5 + 16i, 19 + 12i},
    37  			a: []complex128{
    38  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
    39  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
    40  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
    41  			},
    42  			want: []complex128{
    43  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
    44  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
    45  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
    46  			},
    47  		},
    48  		{
    49  			incX:  7,
    50  			incY:  13,
    51  			alpha: 1 + 2i,
    52  			x:     []complex128{1 + 13i, 18 + 15i, 10 + 18i},
    53  			y:     []complex128{15 + 12i, 4 + 8i, 5 + 16i, 19 + 12i},
    54  			a: []complex128{
    55  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
    56  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
    57  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
    58  			},
    59  			want: []complex128{
    60  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
    61  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
    62  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
    63  			},
    64  		},
    65  		{
    66  			incX:  1,
    67  			incY:  13,
    68  			alpha: 1 + 2i,
    69  			x:     []complex128{1 + 13i, 18 + 15i, 10 + 18i},
    70  			y:     []complex128{15 + 12i, 4 + 8i, 5 + 16i, 19 + 12i},
    71  			a: []complex128{
    72  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
    73  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
    74  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
    75  			},
    76  			want: []complex128{
    77  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
    78  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
    79  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
    80  			},
    81  		},
    82  		{
    83  			incX:  1,
    84  			incY:  -13,
    85  			alpha: 1 + 2i,
    86  			x:     []complex128{1 + 13i, 18 + 15i, 10 + 18i},
    87  			y:     []complex128{19 + 12i, 5 + 16i, 4 + 8i, 15 + 12i},
    88  			a: []complex128{
    89  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
    90  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
    91  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
    92  			},
    93  			want: []complex128{
    94  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
    95  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
    96  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
    97  			},
    98  		},
    99  		{
   100  			incX:  7,
   101  			incY:  1,
   102  			alpha: 1 + 2i,
   103  			x:     []complex128{1 + 13i, 18 + 15i, 10 + 18i},
   104  			y:     []complex128{15 + 12i, 4 + 8i, 5 + 16i, 19 + 12i},
   105  			a: []complex128{
   106  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
   107  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
   108  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
   109  			},
   110  			want: []complex128{
   111  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
   112  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
   113  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
   114  			},
   115  		},
   116  		{
   117  			incX:  -7,
   118  			incY:  1,
   119  			alpha: 1 + 2i,
   120  			x:     []complex128{10 + 18i, 18 + 15i, 1 + 13i},
   121  			y:     []complex128{15 + 12i, 4 + 8i, 5 + 16i, 19 + 12i},
   122  			a: []complex128{
   123  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
   124  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
   125  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
   126  			},
   127  			want: []complex128{
   128  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
   129  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
   130  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
   131  			},
   132  		},
   133  		{
   134  			incX:  -7,
   135  			incY:  -13,
   136  			alpha: 1 + 2i,
   137  			x:     []complex128{10 + 18i, 18 + 15i, 1 + 13i},
   138  			y:     []complex128{19 + 12i, 5 + 16i, 4 + 8i, 15 + 12i},
   139  			a: []complex128{
   140  				4 + 7i, 4 + 7i, 12 + 3i, 9 + 10i,
   141  				3 + 3i, 1 + 2i, 17 + 17i, 9 + 18i,
   142  				14 + 12i, 9 + 16i, 1 + 1i, 9 + 1i,
   143  			},
   144  			want: []complex128{
   145  				-551 - 68i, -216 - 133i, -353 - 322i, -646 - 5i,
   146  				-789 + 624i, -455 + 110i, -859 + 80i, -831 + 843i,
   147  				-832 + 270i, -399 - 40i, -737 - 225i, -941 + 411i,
   148  			},
   149  		},
   150  		{
   151  			incX:  1,
   152  			incY:  1,
   153  			alpha: 1 + 2i,
   154  			x:     []complex128{5 + 16i, 12 + 19i, 9 + 7i, 2 + 4i},
   155  			y:     []complex128{18 + 7i, 20 + 15i, 12 + 14i},
   156  			a: []complex128{
   157  				8 + 17i, 2 + 2i, 8 + 17i,
   158  				1 + 10i, 10 + 15i, 4 + 18i,
   159  				11 + 3i, 15 + 7i, 12 + 15i,
   160  				20 + 10i, 8 + 13i, 19 + 10i,
   161  			},
   162  			want: []complex128{
   163  				-660 + 296i, -928 + 117i, -680 - 49i,
   164  				-768 + 602i, -1155 + 485i, -910 + 170i,
   165  				-254 + 418i, -460 + 432i, -398 + 245i,
   166  				-144 + 112i, -232 + 83i, -165 + 22i,
   167  			},
   168  		},
   169  		{
   170  			incX:  7,
   171  			incY:  13,
   172  			alpha: 1 + 2i,
   173  			x:     []complex128{5 + 16i, 12 + 19i, 9 + 7i, 2 + 4i},
   174  			y:     []complex128{18 + 7i, 20 + 15i, 12 + 14i},
   175  			a: []complex128{
   176  				8 + 17i, 2 + 2i, 8 + 17i,
   177  				1 + 10i, 10 + 15i, 4 + 18i,
   178  				11 + 3i, 15 + 7i, 12 + 15i,
   179  				20 + 10i, 8 + 13i, 19 + 10i,
   180  			},
   181  			want: []complex128{
   182  				-660 + 296i, -928 + 117i, -680 - 49i,
   183  				-768 + 602i, -1155 + 485i, -910 + 170i,
   184  				-254 + 418i, -460 + 432i, -398 + 245i,
   185  				-144 + 112i, -232 + 83i, -165 + 22i,
   186  			},
   187  		},
   188  		{
   189  			incX:  -7,
   190  			incY:  -13,
   191  			alpha: 1 + 2i,
   192  			x:     []complex128{2 + 4i, 9 + 7i, 12 + 19i, 5 + 16i},
   193  			y:     []complex128{12 + 14i, 20 + 15i, 18 + 7i},
   194  			a: []complex128{
   195  				8 + 17i, 2 + 2i, 8 + 17i,
   196  				1 + 10i, 10 + 15i, 4 + 18i,
   197  				11 + 3i, 15 + 7i, 12 + 15i,
   198  				20 + 10i, 8 + 13i, 19 + 10i,
   199  			},
   200  			want: []complex128{
   201  				-660 + 296i, -928 + 117i, -680 - 49i,
   202  				-768 + 602i, -1155 + 485i, -910 + 170i,
   203  				-254 + 418i, -460 + 432i, -398 + 245i,
   204  				-144 + 112i, -232 + 83i, -165 + 22i,
   205  			},
   206  		},
   207  		{
   208  			incX:  -7,
   209  			incY:  -13,
   210  			alpha: 0,
   211  			x:     []complex128{5 + 16i, 12 + 19i, 9 + 7i, 2 + 4i},
   212  			y:     []complex128{18 + 7i, 20 + 15i, 12 + 14i},
   213  			a: []complex128{
   214  				8 + 17i, 2 + 2i, 8 + 17i,
   215  				1 + 10i, 10 + 15i, 4 + 18i,
   216  				11 + 3i, 15 + 7i, 12 + 15i,
   217  				20 + 10i, 8 + 13i, 19 + 10i,
   218  			},
   219  			want: []complex128{
   220  				8 + 17i, 2 + 2i, 8 + 17i,
   221  				1 + 10i, 10 + 15i, 4 + 18i,
   222  				11 + 3i, 15 + 7i, 12 + 15i,
   223  				20 + 10i, 8 + 13i, 19 + 10i,
   224  			},
   225  		},
   226  	} {
   227  		m := len(test.x)
   228  		n := len(test.y)
   229  		incX := test.incX
   230  		incY := test.incY
   231  
   232  		for _, lda := range []int{max(1, n), n + 20} {
   233  			x := makeZVector(test.x, incX)
   234  			xCopy := make([]complex128, len(x))
   235  			copy(xCopy, x)
   236  
   237  			y := makeZVector(test.y, incY)
   238  			yCopy := make([]complex128, len(y))
   239  			copy(yCopy, y)
   240  
   241  			a := makeZGeneral(test.a, m, n, lda)
   242  			want := makeZGeneral(test.want, m, n, lda)
   243  
   244  			impl.Zgeru(m, n, test.alpha, x, incX, y, incY, a, lda)
   245  
   246  			if !zsame(x, xCopy) {
   247  				t.Errorf("Case %v: unexpected modification of x", tc)
   248  			}
   249  			if !zsame(y, yCopy) {
   250  				t.Errorf("Case %v: unexpected modification of y", tc)
   251  			}
   252  			if !zsame(want, a) {
   253  				t.Errorf("Case %v: unexpected result\nwant %v\ngot %v", tc, want, a)
   254  			}
   255  		}
   256  	}
   257  }