gonum.org/v1/gonum@v0.14.0/blas/testblas/zhpr.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  type Zhprer interface {
    14  	Zhpr(uplo blas.Uplo, n int, alpha float64, x []complex128, incX int, ap []complex128)
    15  }
    16  
    17  func ZhprTest(t *testing.T, impl Zhprer) {
    18  	for tc, test := range zherTestCases {
    19  		n := len(test.x)
    20  		for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
    21  			for _, incX := range []int{-11, -2, -1, 1, 2, 7} {
    22  				x := makeZVector(test.x, incX)
    23  				xCopy := make([]complex128, len(x))
    24  				copy(xCopy, x)
    25  
    26  				ap := zPack(uplo, n, test.a, n)
    27  				impl.Zhpr(uplo, n, test.alpha, x, incX, ap)
    28  				a := zUnpackAsHermitian(uplo, n, ap)
    29  
    30  				var want []complex128
    31  				if incX > 0 {
    32  					want = makeZGeneral(test.want, n, n, max(1, n))
    33  				} else {
    34  					want = makeZGeneral(test.wantRev, n, n, max(1, n))
    35  				}
    36  
    37  				if !zsame(x, xCopy) {
    38  					t.Errorf("Case %v (uplo=%v,incX=%v,alpha=%v): unexpected modification of x", tc, uplo, incX, test.alpha)
    39  				}
    40  				if !zsame(want, a) {
    41  					t.Errorf("Case %v (uplo=%v,incX=%v,alpha=%v): unexpected result\nwant: %v\ngot:  %v", tc, uplo, incX, test.alpha, want, a)
    42  				}
    43  			}
    44  		}
    45  	}
    46  }