github.com/gopherd/gonum@v0.0.4/blas/testblas/ztpmv.go (about)

     1  // Copyright ©2018 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/gopherd/gonum/blas"
    11  )
    12  
    13  type Ztpmver interface {
    14  	Ztpmv(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, n int, ap []complex128, x []complex128, incX int)
    15  }
    16  
    17  func ZtpmvTest(t *testing.T, impl Ztpmver) {
    18  	for tc, test := range ztrmvTestCases {
    19  		n := len(test.x)
    20  		uplo := test.uplo
    21  		for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
    22  			for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
    23  				for _, incX := range []int{-11, -2, -1, 1, 2, 7} {
    24  					ap := zPack(uplo, n, test.a, n)
    25  					apCopy := make([]complex128, len(ap))
    26  					copy(apCopy, ap)
    27  
    28  					x := makeZVector(test.x, incX)
    29  
    30  					impl.Ztpmv(uplo, trans, diag, n, ap, x, incX)
    31  
    32  					if !zsame(ap, apCopy) {
    33  						t.Errorf("Case %v (uplo=%v,trans=%v,diag=%v,incX=%v): unexpected modification of A", tc, uplo, trans, diag, incX)
    34  					}
    35  
    36  					var want []complex128
    37  					if diag == blas.NonUnit {
    38  						switch {
    39  						case trans == blas.NoTrans && incX > 0:
    40  							want = makeZVector(test.want, incX)
    41  						case trans == blas.NoTrans && incX < 0:
    42  							want = makeZVector(test.wantNeg, incX)
    43  						case trans == blas.Trans && incX > 0:
    44  							want = makeZVector(test.wantTrans, incX)
    45  						case trans == blas.Trans && incX < 0:
    46  							want = makeZVector(test.wantTransNeg, incX)
    47  						case trans == blas.ConjTrans && incX > 0:
    48  							want = makeZVector(test.wantConjTrans, incX)
    49  						case trans == blas.ConjTrans && incX < 0:
    50  							want = makeZVector(test.wantConjTransNeg, incX)
    51  						}
    52  					} else {
    53  						switch {
    54  						case trans == blas.NoTrans && incX > 0:
    55  							want = makeZVector(test.wantUnit, incX)
    56  						case trans == blas.NoTrans && incX < 0:
    57  							want = makeZVector(test.wantUnitNeg, incX)
    58  						case trans == blas.Trans && incX > 0:
    59  							want = makeZVector(test.wantUnitTrans, incX)
    60  						case trans == blas.Trans && incX < 0:
    61  							want = makeZVector(test.wantUnitTransNeg, incX)
    62  						case trans == blas.ConjTrans && incX > 0:
    63  							want = makeZVector(test.wantUnitConjTrans, incX)
    64  						case trans == blas.ConjTrans && incX < 0:
    65  							want = makeZVector(test.wantUnitConjTransNeg, incX)
    66  						}
    67  					}
    68  					if !zsame(x, want) {
    69  						t.Errorf("Case %v (uplo=%v,trans=%v,diag=%v,incX=%v): unexpected result\nwant %v\ngot  %v", tc, uplo, trans, diag, incX, want, x)
    70  					}
    71  				}
    72  			}
    73  		}
    74  	}
    75  }