OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / blas / gonum / gonum.go
1 // Copyright ©2015 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 //go:generate ./single_precision.bash
6
7 package gonum
8
9 import "math"
10
11 type Implementation struct{}
12
13 // The following are panic strings used during parameter checks.
14 const (
15         negativeN = "blas: n < 0"
16         zeroIncX  = "blas: zero x index increment"
17         zeroIncY  = "blas: zero y index increment"
18         badLenX   = "blas: x index out of range"
19         badLenY   = "blas: y index out of range"
20
21         mLT0  = "blas: m < 0"
22         nLT0  = "blas: n < 0"
23         kLT0  = "blas: k < 0"
24         kLLT0 = "blas: kL < 0"
25         kULT0 = "blas: kU < 0"
26
27         badUplo      = "blas: illegal triangle"
28         badTranspose = "blas: illegal transpose"
29         badDiag      = "blas: illegal diagonal"
30         badSide      = "blas: illegal side"
31
32         badLdA = "blas: index of a out of range"
33         badLdB = "blas: index of b out of range"
34         badLdC = "blas: index of c out of range"
35
36         badX = "blas: x index out of range"
37         badY = "blas: y index out of range"
38 )
39
40 // [SD]gemm behavior constants. These are kept here to keep them out of the
41 // way during single precision code genration.
42 const (
43         blockSize   = 64 // b x b matrix
44         minParBlock = 4  // minimum number of blocks needed to go parallel
45         buffMul     = 4  // how big is the buffer relative to the number of workers
46 )
47
48 // subMul is a common type shared by [SD]gemm.
49 type subMul struct {
50         i, j int // index of block
51 }
52
53 func max(a, b int) int {
54         if a > b {
55                 return a
56         }
57         return b
58 }
59
60 func min(a, b int) int {
61         if a > b {
62                 return b
63         }
64         return a
65 }
66
67 func checkSMatrix(name byte, m, n int, a []float32, lda int) {
68         if m < 0 {
69                 panic(mLT0)
70         }
71         if n < 0 {
72                 panic(nLT0)
73         }
74         if lda < n {
75                 panic("blas: illegal stride of " + string(name))
76         }
77         if len(a) < (m-1)*lda+n {
78                 panic("blas: index of " + string(name) + " out of range")
79         }
80 }
81
82 func checkDMatrix(name byte, m, n int, a []float64, lda int) {
83         if m < 0 {
84                 panic(mLT0)
85         }
86         if n < 0 {
87                 panic(nLT0)
88         }
89         if lda < n {
90                 panic("blas: illegal stride of " + string(name))
91         }
92         if len(a) < (m-1)*lda+n {
93                 panic("blas: index of " + string(name) + " out of range")
94         }
95 }
96
97 func checkZMatrix(name byte, m, n int, a []complex128, lda int) {
98         if m < 0 {
99                 panic(mLT0)
100         }
101         if n < 0 {
102                 panic(nLT0)
103         }
104         if lda < max(1, n) {
105                 panic("blas: illegal stride of " + string(name))
106         }
107         if len(a) < (m-1)*lda+n {
108                 panic("blas: insufficient " + string(name) + " matrix slice length")
109         }
110 }
111
112 func checkZVector(name byte, n int, x []complex128, incX int) {
113         if n < 0 {
114                 panic(nLT0)
115         }
116         if incX == 0 {
117                 panic(zeroIncX)
118         }
119         if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
120                 panic("blas: insufficient " + string(name) + " vector slice length")
121         }
122 }
123
124 // blocks returns the number of divisions of the dimension length with the given
125 // block size.
126 func blocks(dim, bsize int) int {
127         return (dim + bsize - 1) / bsize
128 }
129
130 // dcabs1 returns |real(z)|+|imag(z)|.
131 func dcabs1(z complex128) float64 {
132         return math.Abs(real(z)) + math.Abs(imag(z))
133 }