github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/blas64/blas64_test.go (about)

     1  // Copyright ©2019 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 blas64
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/jingcheng-WU/gonum/blas"
    12  	"github.com/jingcheng-WU/gonum/blas/testblas"
    13  )
    14  
    15  var impl = b64{}
    16  
    17  func TestDasum(t *testing.T)  { testblas.DasumTest(t, impl) }
    18  func TestDaxpy(t *testing.T)  { testblas.DaxpyTest(t, impl) }
    19  func TestDdot(t *testing.T)   { testblas.DdotTest(t, impl) }
    20  func TestDnrm2(t *testing.T)  { testblas.Dnrm2Test(t, impl) }
    21  func TestIdamax(t *testing.T) { testblas.IdamaxTest(t, impl) }
    22  func TestDswap(t *testing.T)  { testblas.DswapTest(t, impl) }
    23  func TestDcopy(t *testing.T)  { testblas.DcopyTest(t, impl) }
    24  func TestDrotg(t *testing.T)  { testblas.DrotgTest(t, impl) }
    25  func TestDrotmg(t *testing.T) { testblas.DrotmgTest(t, impl) }
    26  func TestDrot(t *testing.T)   { testblas.DrotTest(t, impl) }
    27  func TestDrotm(t *testing.T)  { testblas.DrotmTest(t, impl) }
    28  func TestDscal(t *testing.T)  { testblas.DscalTest(t, impl) }
    29  func TestDgemv(t *testing.T)  { testblas.DgemvTest(t, impl) }
    30  func TestDger(t *testing.T)   { testblas.DgerTest(t, impl) }
    31  func TestDtxmv(t *testing.T)  { testblas.DtxmvTest(t, impl) }
    32  func TestDgbmv(t *testing.T)  { testblas.DgbmvTest(t, impl) }
    33  func TestDtbsv(t *testing.T)  { testblas.DtbsvTest(t, impl) }
    34  func TestDsbmv(t *testing.T)  { testblas.DsbmvTest(t, impl) }
    35  func TestDtbmv(t *testing.T)  { testblas.DtbmvTest(t, impl) }
    36  func TestDtrsv(t *testing.T)  { testblas.DtrsvTest(t, impl) }
    37  func TestDtrmv(t *testing.T)  { testblas.DtrmvTest(t, impl) }
    38  func TestDsymv(t *testing.T)  { testblas.DsymvTest(t, impl) }
    39  func TestDsyr(t *testing.T)   { testblas.DsyrTest(t, impl) }
    40  func TestDsyr2(t *testing.T)  { testblas.Dsyr2Test(t, impl) }
    41  func TestDspr2(t *testing.T)  { testblas.Dspr2Test(t, impl) }
    42  func TestDspr(t *testing.T)   { testblas.DsprTest(t, impl) }
    43  func TestDspmv(t *testing.T)  { testblas.DspmvTest(t, impl) }
    44  func TestDtpsv(t *testing.T)  { testblas.DtpsvTest(t, impl) }
    45  func TestDtpmv(t *testing.T)  { testblas.DtpmvTest(t, impl) }
    46  func TestDgemm(t *testing.T)  { testblas.TestDgemm(t, impl) }
    47  func TestDsymm(t *testing.T)  { testblas.DsymmTest(t, impl) }
    48  func TestDtrsm(t *testing.T)  { testblas.DtrsmTest(t, impl) }
    49  func TestDsyrk(t *testing.T)  { testblas.DsyrkTest(t, impl) }
    50  func TestDsyr2k(t *testing.T) { testblas.Dsyr2kTest(t, impl) }
    51  func TestDtrmm(t *testing.T)  { testblas.DtrmmTest(t, impl) }
    52  
    53  type b64 struct{}
    54  
    55  var _ blas.Float64 = b64{}
    56  
    57  func (b64) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 {
    58  	return Dot(Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y})
    59  }
    60  func (b64) Dnrm2(n int, x []float64, incX int) float64 {
    61  	if incX < 0 {
    62  		return 0
    63  	}
    64  	return Nrm2(Vector{N: n, Inc: incX, Data: x})
    65  }
    66  func (b64) Dasum(n int, x []float64, incX int) float64 {
    67  	if incX < 0 {
    68  		return 0
    69  	}
    70  	return Asum(Vector{N: n, Inc: incX, Data: x})
    71  }
    72  func (b64) Idamax(n int, x []float64, incX int) int {
    73  	if incX < 0 {
    74  		return -1
    75  	}
    76  	return Iamax(Vector{N: n, Inc: incX, Data: x})
    77  }
    78  func (b64) Dswap(n int, x []float64, incX int, y []float64, incY int) {
    79  	Swap(Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y})
    80  }
    81  func (b64) Dcopy(n int, x []float64, incX int, y []float64, incY int) {
    82  	Copy(Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y})
    83  }
    84  func (b64) Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) {
    85  	Axpy(alpha, Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y})
    86  }
    87  func (b64) Drotg(a, b float64) (c, s, r, z float64) {
    88  	return Rotg(a, b)
    89  }
    90  func (b64) Drotmg(d1, d2, b1, b2 float64) (p blas.DrotmParams, rd1, rd2, rb1 float64) {
    91  	return Rotmg(d1, d2, b1, b2)
    92  }
    93  func (b64) Drot(n int, x []float64, incX int, y []float64, incY int, c float64, s float64) {
    94  	Rot(Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y}, c, s)
    95  }
    96  func (b64) Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) {
    97  	Rotm(Vector{N: n, Inc: incX, Data: x}, Vector{N: n, Inc: incY, Data: y}, p)
    98  }
    99  func (b64) Dscal(n int, alpha float64, x []float64, incX int) {
   100  	if incX < 0 {
   101  		return
   102  	}
   103  	Scal(alpha, Vector{N: n, Inc: incX, Data: x})
   104  }
   105  func (b64) Dgemv(tA blas.Transpose, m, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) {
   106  	lenX := m
   107  	lenY := n
   108  	if tA == blas.NoTrans {
   109  		lenX = n
   110  		lenY = m
   111  	}
   112  	Gemv(tA, alpha,
   113  		General{Rows: m, Cols: n, Data: a, Stride: lda},
   114  		Vector{N: lenX, Inc: incX, Data: x},
   115  		beta,
   116  		Vector{N: lenY, Inc: incY, Data: y})
   117  }
   118  func (b64) Dgbmv(tA blas.Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) {
   119  	lenX := m
   120  	lenY := n
   121  	if tA == blas.NoTrans {
   122  		lenX = n
   123  		lenY = m
   124  	}
   125  	Gbmv(tA, alpha,
   126  		Band{Rows: m, Cols: n, KL: kL, KU: kU, Data: a, Stride: lda},
   127  		Vector{N: lenX, Inc: incX, Data: x},
   128  		beta,
   129  		Vector{N: lenY, Inc: incY, Data: y})
   130  }
   131  func (b64) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) {
   132  	Trmv(tA,
   133  		Triangular{Uplo: ul, Diag: d, N: n, Data: a, Stride: lda},
   134  		Vector{N: n, Inc: incX, Data: x})
   135  }
   136  func (b64) Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) {
   137  	Tbmv(tA,
   138  		TriangularBand{Uplo: ul, Diag: d, N: n, K: k, Data: a, Stride: lda},
   139  		Vector{N: n, Inc: incX, Data: x})
   140  }
   141  func (b64) Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) {
   142  	Tpmv(tA,
   143  		TriangularPacked{Uplo: ul, Diag: d, N: n, Data: ap},
   144  		Vector{N: n, Inc: incX, Data: x})
   145  }
   146  func (b64) Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) {
   147  	Trsv(tA,
   148  		Triangular{Uplo: ul, Diag: d, N: n, Data: a, Stride: lda},
   149  		Vector{N: n, Inc: incX, Data: x})
   150  }
   151  func (b64) Dtbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) {
   152  	Tbsv(tA,
   153  		TriangularBand{Uplo: ul, Diag: d, N: n, K: k, Data: a, Stride: lda},
   154  		Vector{N: n, Inc: incX, Data: x})
   155  }
   156  func (b64) Dtpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) {
   157  	Tpsv(tA,
   158  		TriangularPacked{Uplo: ul, Diag: d, N: n, Data: ap},
   159  		Vector{N: n, Inc: incX, Data: x})
   160  }
   161  func (b64) Dsymv(ul blas.Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) {
   162  	Symv(alpha,
   163  		Symmetric{Uplo: ul, N: n, Data: a, Stride: lda},
   164  		Vector{N: n, Inc: incX, Data: x},
   165  		beta,
   166  		Vector{N: n, Inc: incY, Data: y})
   167  }
   168  func (b64) Dsbmv(ul blas.Uplo, n, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) {
   169  	Sbmv(alpha,
   170  		SymmetricBand{Uplo: ul, N: n, K: k, Data: a, Stride: lda},
   171  		Vector{N: n, Inc: incX, Data: x},
   172  		beta,
   173  		Vector{N: n, Inc: incY, Data: y})
   174  }
   175  func (b64) Dspmv(ul blas.Uplo, n int, alpha float64, ap []float64, x []float64, incX int, beta float64, y []float64, incY int) {
   176  	Spmv(alpha,
   177  		SymmetricPacked{Uplo: ul, N: n, Data: ap},
   178  		Vector{N: n, Inc: incX, Data: x},
   179  		beta,
   180  		Vector{N: n, Inc: incY, Data: y})
   181  }
   182  func (b64) Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) {
   183  	Ger(alpha,
   184  		Vector{N: m, Inc: incX, Data: x},
   185  		Vector{N: n, Inc: incY, Data: y},
   186  		General{Rows: m, Cols: n, Data: a, Stride: lda})
   187  }
   188  func (b64) Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) {
   189  	Syr(alpha,
   190  		Vector{N: n, Inc: incX, Data: x},
   191  		Symmetric{Uplo: ul, N: n, Data: a, Stride: lda})
   192  }
   193  func (b64) Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, ap []float64) {
   194  	Spr(alpha,
   195  		Vector{N: n, Inc: incX, Data: x},
   196  		SymmetricPacked{Uplo: ul, N: n, Data: ap})
   197  }
   198  func (b64) Dsyr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) {
   199  	Syr2(alpha,
   200  		Vector{N: n, Inc: incX, Data: x},
   201  		Vector{N: n, Inc: incY, Data: y},
   202  		Symmetric{Uplo: ul, N: n, Data: a, Stride: lda})
   203  }
   204  func (b64) Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64) {
   205  	Spr2(alpha,
   206  		Vector{N: n, Inc: incX, Data: x},
   207  		Vector{N: n, Inc: incY, Data: y},
   208  		SymmetricPacked{Uplo: ul, N: n, Data: a})
   209  }
   210  func (b64) Dgemm(tA, tB blas.Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) {
   211  	am, an := m, k
   212  	if tA != blas.NoTrans {
   213  		am, an = an, am
   214  	}
   215  	bm, bn := k, n
   216  	if tB != blas.NoTrans {
   217  		bm, bn = bn, bm
   218  	}
   219  	Gemm(tA, tB, alpha,
   220  		General{Rows: am, Cols: an, Data: a, Stride: lda},
   221  		General{Rows: bm, Cols: bn, Data: b, Stride: ldb},
   222  		beta,
   223  		General{Rows: m, Cols: n, Data: c, Stride: ldc})
   224  }
   225  func (b64) 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) {
   226  	var an int
   227  	switch s {
   228  	case blas.Left:
   229  		an = m
   230  	case blas.Right:
   231  		an = n
   232  	default:
   233  		panic(fmt.Sprintf("blas64: bad test: invalid side: %q", s))
   234  	}
   235  	Symm(s, alpha,
   236  		Symmetric{Uplo: ul, N: an, Data: a, Stride: lda},
   237  		General{Rows: m, Cols: n, Data: b, Stride: ldb},
   238  		beta,
   239  		General{Rows: m, Cols: n, Data: c, Stride: ldc})
   240  }
   241  func (b64) Dsyrk(ul blas.Uplo, t blas.Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) {
   242  	am, an := n, k
   243  	if t != blas.NoTrans {
   244  		am, an = an, am
   245  	}
   246  	Syrk(t, alpha,
   247  		General{Rows: am, Cols: an, Data: a, Stride: lda},
   248  		beta,
   249  		Symmetric{Uplo: ul, N: n, Data: c, Stride: ldc})
   250  }
   251  func (b64) Dsyr2k(ul blas.Uplo, t blas.Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) {
   252  	am, an := n, k
   253  	if t != blas.NoTrans {
   254  		am, an = an, am
   255  	}
   256  	Syr2k(t, alpha,
   257  		General{Rows: am, Cols: an, Data: a, Stride: lda},
   258  		General{Rows: am, Cols: an, Data: b, Stride: ldb},
   259  		beta,
   260  		Symmetric{Uplo: ul, N: n, Data: c, Stride: ldc})
   261  }
   262  func (b64) Dtrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) {
   263  	var k int
   264  	switch s {
   265  	case blas.Left:
   266  		k = m
   267  	case blas.Right:
   268  		k = n
   269  	default:
   270  		panic(fmt.Sprintf("blas64: bad test: invalid side: %q", s))
   271  	}
   272  	Trmm(s, tA, alpha,
   273  		Triangular{Uplo: ul, Diag: d, N: k, Data: a, Stride: lda},
   274  		General{Rows: m, Cols: n, Data: b, Stride: ldb})
   275  }
   276  func (b64) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) {
   277  	var k int
   278  	switch s {
   279  	case blas.Left:
   280  		k = m
   281  	case blas.Right:
   282  		k = n
   283  	default:
   284  		panic(fmt.Sprintf("blas64: bad test: invalid side: %q", s))
   285  	}
   286  	Trsm(s, tA, alpha,
   287  		Triangular{Uplo: ul, Diag: d, N: k, Data: a, Stride: lda},
   288  		General{Rows: m, Cols: n, Data: b, Stride: ldb})
   289  }