gonum.org/v1/gonum@v0.14.0/blas/testblas/zhemv.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  	"gonum.org/v1/gonum/blas"
    11  )
    12  
    13  var zhemvTestCases = []struct {
    14  	uplo  blas.Uplo
    15  	alpha complex128
    16  	a     []complex128
    17  	x     []complex128
    18  	beta  complex128
    19  	y     []complex128
    20  
    21  	want      []complex128
    22  	wantXNeg  []complex128
    23  	wantYNeg  []complex128
    24  	wantXYNeg []complex128
    25  }{
    26  	{
    27  		uplo:  blas.Upper,
    28  		alpha: 6 + 2i,
    29  		beta:  -6 - 7i,
    30  	},
    31  	{
    32  		uplo:  blas.Lower,
    33  		alpha: 6 + 2i,
    34  		beta:  -6 - 7i,
    35  	},
    36  	{
    37  		uplo:  blas.Upper,
    38  		alpha: 6 + 2i,
    39  		a: []complex128{
    40  			7, 8 + 4i, -9 - 6i, -9 + 3i,
    41  			znan, -3, -10 - 6i, 0 + 3i,
    42  			znan, znan, 6, 2 + 8i,
    43  			znan, znan, znan, -4,
    44  		},
    45  		x: []complex128{
    46  			-4 + 0i,
    47  			-2 - 5i,
    48  			8 + 0i,
    49  			6 - 1i,
    50  		},
    51  		beta: -6 - 7i,
    52  		y: []complex128{
    53  			1 - 5i,
    54  			-2 - 5i,
    55  			0 - 4i,
    56  			7 + 7i,
    57  		},
    58  		want: []complex128{
    59  			-785 - 685i,
    60  			-643 - 156i,
    61  			776 + 692i,
    62  			169 - 317i,
    63  		},
    64  		wantXNeg: []complex128{
    65  			599 + 703i,
    66  			1 + 172i,
    67  			-978 - 86i,
    68  			-449 - 423i,
    69  		},
    70  		wantYNeg: []complex128{
    71  			121 - 203i,
    72  			781 + 712i,
    73  			-648 - 176i,
    74  			-737 - 799i,
    75  		},
    76  		wantXYNeg: []complex128{
    77  			-497 - 309i,
    78  			-973 - 66i,
    79  			-4 + 152i,
    80  			647 + 589i,
    81  		},
    82  	},
    83  	{
    84  		uplo:  blas.Lower,
    85  		alpha: 6 + 2i,
    86  		a: []complex128{
    87  			7, znan, znan, znan,
    88  			8 - 4i, -3, znan, znan,
    89  			-9 + 6i, -10 + 6i, 6, znan,
    90  			-9 - 3i, 0 - 3i, 2 - 8i, -4,
    91  		},
    92  		x: []complex128{
    93  			-4 + 0i,
    94  			-2 - 5i,
    95  			8 + 0i,
    96  			6 - 1i,
    97  		},
    98  		beta: -6 - 7i,
    99  		y: []complex128{
   100  			1 - 5i,
   101  			-2 - 5i,
   102  			0 - 4i,
   103  			7 + 7i,
   104  		},
   105  		want: []complex128{
   106  			-785 - 685i,
   107  			-643 - 156i,
   108  			776 + 692i,
   109  			169 - 317i,
   110  		},
   111  		wantXNeg: []complex128{
   112  			599 + 703i,
   113  			1 + 172i,
   114  			-978 - 86i,
   115  			-449 - 423i,
   116  		},
   117  		wantYNeg: []complex128{
   118  			121 - 203i,
   119  			781 + 712i,
   120  			-648 - 176i,
   121  			-737 - 799i,
   122  		},
   123  		wantXYNeg: []complex128{
   124  			-497 - 309i,
   125  			-973 - 66i,
   126  			-4 + 152i,
   127  			647 + 589i,
   128  		},
   129  	},
   130  	{
   131  		uplo:  blas.Upper,
   132  		alpha: 0,
   133  		a: []complex128{
   134  			7, 8 + 4i, -9 - 6i, -9 + 3i,
   135  			znan, -3, -10 - 6i, 0 + 3i,
   136  			znan, znan, 6, 2 + 8i,
   137  			znan, znan, znan, -4,
   138  		},
   139  		x: []complex128{
   140  			-4 + 0i,
   141  			-2 - 5i,
   142  			8 + 0i,
   143  			6 - 1i,
   144  		},
   145  		beta: -6 - 7i,
   146  		y: []complex128{
   147  			1 - 5i,
   148  			-2 - 5i,
   149  			0 - 4i,
   150  			7 + 7i,
   151  		},
   152  		want: []complex128{
   153  			-41 + 23i,
   154  			-23 + 44i,
   155  			-28 + 24i,
   156  			7 - 91i,
   157  		},
   158  		wantXNeg: []complex128{
   159  			-41 + 23i,
   160  			-23 + 44i,
   161  			-28 + 24i,
   162  			7 - 91i,
   163  		},
   164  		wantYNeg: []complex128{
   165  			-41 + 23i,
   166  			-23 + 44i,
   167  			-28 + 24i,
   168  			7 - 91i,
   169  		},
   170  		wantXYNeg: []complex128{
   171  			-41 + 23i,
   172  			-23 + 44i,
   173  			-28 + 24i,
   174  			7 - 91i,
   175  		},
   176  	},
   177  	{
   178  		uplo:  blas.Upper,
   179  		alpha: 6 + 2i,
   180  		a: []complex128{
   181  			7, 8 + 4i, -9 - 6i, -9 + 3i,
   182  			znan, -3, -10 - 6i, 0 + 3i,
   183  			znan, znan, 6, 2 + 8i,
   184  			znan, znan, znan, -4,
   185  		},
   186  		x: []complex128{
   187  			-4 + 0i,
   188  			-2 - 5i,
   189  			8 + 0i,
   190  			6 - 1i,
   191  		},
   192  		beta: 0,
   193  		y: []complex128{
   194  			1 - 5i,
   195  			-2 - 5i,
   196  			0 - 4i,
   197  			7 + 7i,
   198  		},
   199  		want: []complex128{
   200  			-744 - 708i,
   201  			-620 - 200i,
   202  			804 + 668i,
   203  			162 - 226i,
   204  		},
   205  		wantXNeg: []complex128{
   206  			640 + 680i,
   207  			24 + 128i,
   208  			-950 - 110i,
   209  			-456 - 332i,
   210  		},
   211  		wantYNeg: []complex128{
   212  			162 - 226i,
   213  			804 + 668i,
   214  			-620 - 200i,
   215  			-744 - 708i,
   216  		},
   217  		wantXYNeg: []complex128{
   218  			-456 - 332i,
   219  			-950 - 110i,
   220  			24 + 128i,
   221  			640 + 680i,
   222  		},
   223  	},
   224  }
   225  
   226  type Zhemver interface {
   227  	Zhemv(uplo blas.Uplo, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int)
   228  }
   229  
   230  func ZhemvTest(t *testing.T, impl Zhemver) {
   231  	for tc, test := range zhemvTestCases {
   232  		n := len(test.x)
   233  		for _, incX := range []int{-11, -2, -1, 1, 2, 7} {
   234  			for _, incY := range []int{-11, -2, -1, 1, 2, 7} {
   235  				for _, lda := range []int{max(1, n), n + 11} {
   236  					alpha := test.alpha
   237  					beta := test.beta
   238  
   239  					a := makeZGeneral(test.a, n, n, lda)
   240  					aCopy := make([]complex128, len(a))
   241  					copy(aCopy, a)
   242  
   243  					x := makeZVector(test.x, incX)
   244  					xCopy := make([]complex128, len(x))
   245  					copy(xCopy, x)
   246  
   247  					y := makeZVector(test.y, incY)
   248  
   249  					impl.Zhemv(test.uplo, n, alpha, a, lda, x, incX, beta, y, incY)
   250  
   251  					if !zsame(x, xCopy) {
   252  						t.Errorf("Case %v (incX=%v,incY=%v,lda=%v): unexpected modification of x", tc, incX, incY, lda)
   253  					}
   254  					if !zsame(a, aCopy) {
   255  						t.Errorf("Case %v (incX=%v,incY=%v,lda=%v): unexpected modification of A", tc, incX, incY, lda)
   256  					}
   257  
   258  					var want []complex128
   259  					switch {
   260  					case incX > 0 && incY > 0:
   261  						want = makeZVector(test.want, incY)
   262  					case incX < 0 && incY > 0:
   263  						want = makeZVector(test.wantXNeg, incY)
   264  					case incX > 0 && incY < 0:
   265  						want = makeZVector(test.wantYNeg, incY)
   266  					default:
   267  						want = makeZVector(test.wantXYNeg, incY)
   268  					}
   269  					if !zsame(y, want) {
   270  						t.Errorf("Case %v (incX=%v,incY=%v,lda=%v): unexpected result\nwant %v\ngot  %v", tc, incX, incY, lda, want, y)
   271  					}
   272  				}
   273  			}
   274  		}
   275  	}
   276  }