-
Notifications
You must be signed in to change notification settings - Fork 6
/
consts.go
264 lines (251 loc) · 8.15 KB
/
consts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// Copyright (c) Harri Rautila, 2012
// This file is part of github.com/hrautila/linalg package.
// It is free software, distributed under the terms of GNU Lesser General Public
// License Version 3, or any later version. See the COPYING tile included in this archive.
package linalg
import (
"errors"
"fmt"
"strings"
)
// BLAS/LAPACK matrix parameter constants.
const (
// BLAS/LAPACK parameters. Chosen values match corresponding
// parameters in CBLAS implementation.
RowMajor = 101 // Atlas row-major
ColumnMajor = 102 // Atlas column major
PNoTrans = 111 // 'N'
PTrans = 112 // 'T'
PConjTrans = 113 // 'C'
PUpper = 121 // 'U'
PLower = 122 // 'L'
PNonUnit = 131 // 'N'
PUnit = 132 // 'U'
PDiag = 133 // 'D'
PLeft = 141 // 'L'
PRight = 142 // 'R'
// These for LAPACK only
PJobNo = 151 // 'N'
PJobValue = 152 // 'V'
PJobAll = 153 // 'A'
PJobS = 154 // 'S'
PJobO = 155 // 'O'
PRangeAll = 161 // 'A'
PRangeValue = 162 // 'V'
PRangeInt = 163 // 'I'
)
// Structure for BLAS/LAPACK function parameters.
type Parameters struct {
Trans, TransA, TransB int
Uplo int
Diag int
Side int
Jobz int
Jobu int
Jobvt int
Range int
}
func GetParam(name string, params ...Option) (val int) {
val = -1
for _, o := range params {
if strings.EqualFold(o.Name(), name) {
val = o.Int()
return
}
}
return
}
// Parse options and return parameter structure with option fields
// set to given or sensible defaults.
func GetParameters(params ...Option) (p *Parameters, err error) {
err = nil
p = &Parameters{
PNoTrans, // Trans
PNoTrans, // TransA
PNoTrans, // TransB
PLower, // Uplo
PNonUnit, // Diag
PLeft, // Side
PJobNo, // Jobz
PJobNo, // Jobu
PJobNo, // Jobvt
PRangeAll} // Range
Loop:
for _, o := range params {
if _, ok := o.(*IOpt); !ok {
continue Loop
}
pval := o.Int()
switch {
case strings.EqualFold(o.Name(), "trans"):
if pval == PNoTrans || pval == PTrans || pval == PConjTrans {
p.Trans = pval
p.TransA = p.Trans
p.TransB = p.Trans
} else {
err = errors.New("Illegal value for Transpose parameter")
break Loop
}
case strings.EqualFold(o.Name(), "transa"):
if pval == PNoTrans || pval == PTrans || pval == PConjTrans {
p.TransA = pval
} else {
err = errors.New("Illegal value for Transpose parameter")
break Loop
}
case strings.EqualFold(o.Name(), "transb"):
if pval == PNoTrans || pval == PTrans || pval == PConjTrans {
p.TransB = pval
} else {
err = errors.New("Illegal value for Transpose parameter")
break Loop
}
case strings.EqualFold(o.Name(), "uplo"):
if pval == PUpper || pval == PLower {
p.Uplo = pval
} else {
err = errors.New("Illegal value for UpLo parameter")
break Loop
}
case strings.EqualFold(o.Name(), "diag"):
if pval == PNonUnit || pval == PUnit || pval == PDiag {
p.Diag = pval
} else {
err = errors.New("Illegal value for Diag parameter")
break Loop
}
case strings.EqualFold(o.Name(), "side"):
if pval == PLeft || pval == PRight {
p.Side = pval
} else {
err = errors.New("Illegal value for Side parameter")
break Loop
}
// Lapack parameters
case strings.EqualFold(o.Name(), "jobz"):
if pval == PJobNo || pval == PJobValue {
p.Jobz = pval
} else {
err = errors.New("Illegal value for Jobz parameter")
break Loop
}
case strings.EqualFold(o.Name(), "jobu"):
if pval == PJobNo || pval == PJobAll || pval == PJobS || pval == PJobO {
p.Jobu = pval
} else {
err = errors.New("Illegal value for Jobu parameter")
break Loop
}
case strings.EqualFold(o.Name(), "jobvt"):
if pval == PJobNo || pval == PJobAll || pval == PJobS || pval == PJobO {
p.Jobvt = pval
} else {
err = errors.New("Illegal value for Jobu parameter")
break Loop
}
case strings.EqualFold(o.Name(), "range"):
if pval == PRangeAll || pval == PRangeValue || pval == PRangeInt {
p.Range = pval
} else {
err = errors.New("Illegal value for Range parameter")
break Loop
}
}
}
return
}
// Matrix parameter option variables.
var (
// trans: No Transpose 'N'
OptNoTrans = &IOpt{"trans", PNoTrans}
OptNoTransA = &IOpt{"transA", PNoTrans}
OptNoTransB = &IOpt{"transB", PNoTrans}
// trans: Transpose 'T'
OptTrans = &IOpt{"trans", PTrans}
OptTransA = &IOpt{"transA", PTrans}
OptTransB = &IOpt{"transB", PTrans}
// trans: Conjugate Transpose 'C'
OptConjTrans = &IOpt{"trans", PConjTrans}
OptConjTransA = &IOpt{"transA", PConjTrans}
OptConjTransB = &IOpt{"transB", PConjTrans}
// uplo: Upper Triangular 'U'
OptUpper = &IOpt{"uplo", PUpper}
// uplo: Lower Triangular 'L'
OptLower = &IOpt{"uplo", PLower}
// side parameter 'L', 'R'
OptLeft = &IOpt{"side", PLeft}
OptRight = &IOpt{"side", PRight}
// diag parameter 'U'
OptUnit = &IOpt{"diag", PUnit}
// diag parameter 'N'
OptNonUnit = &IOpt{"diag", PNonUnit}
OptDiag = &IOpt{"diag", PDiag}
// Lapack jobz 'N'
OptJobZNo = &IOpt{"jobz", PJobNo}
// Lapack jobz 'V'
OptJobZValue = &IOpt{"jobz", PJobValue}
// Lapack jobu 'N'
OptJobuNo = &IOpt{"jobu", PJobNo}
// Lapack jobu 'A'
OptJobuAll = &IOpt{"jobu", PJobAll}
// Lapack jobu 'S'
OptJobuS = &IOpt{"jobu", PJobS}
// Lapack jobu 'O'
OptJobuO = &IOpt{"jobu", PJobO}
// Lapack jobvt 'N',
OptJobvtNo = &IOpt{"jobvt", PJobNo}
// Lapack jobvt 'A',
OptJobvtAll = &IOpt{"jobvt", PJobAll}
// Lapack jobvt 'S',
OptJobvtS = &IOpt{"jobvt", PJobS}
// Lapack jobvt 'O',
OptJobvtO = &IOpt{"jobvt", PJobO}
// Lapack range 'A'
OptRangeAll = &IOpt{"range", PRangeAll}
// Lapack range 'V'
OptRangeValue = &IOpt{"range", PRangeValue}
// Lapack range 'I'
OptRangeInt = &IOpt{"range", PRangeInt}
)
var paramString map[int]string = map[int]string{
PNoTrans: "N",
PTrans: "T",
PConjTrans: "C",
PUpper: "U",
PLower: "L",
PLeft: "L",
PRight: "R",
PUnit: "U",
PNonUnit: "N",
PJobNo: "N",
PJobValue: "V",
PJobAll: "A",
PJobS: "S",
PJobO: "O",
PRangeAll: "A",
PRangeValue: "V",
PRangeInt: "I",
}
// Map parameter value to name string that can be used when calling Fortran
// library functions.
func ParamString(p int) string {
v, ok := paramString[p]
if ok {
return v
}
return ""
}
// Print parameter structure.
func PrintParameters(p *Parameters) {
fmt.Printf("trans : %d [%s]\n", p.Trans, ParamString(p.Trans))
fmt.Printf("transA: %d [%s]\n", p.TransA, ParamString(p.TransA))
fmt.Printf("transB: %d [%s]\n", p.TransB, ParamString(p.TransB))
fmt.Printf("Uplo : %d [%s]\n", p.Uplo, ParamString(p.Uplo))
fmt.Printf("Diag : %d [%s]\n", p.Diag, ParamString(p.Diag))
fmt.Printf("Side : %d [%s]\n", p.Side, ParamString(p.Side))
fmt.Printf("Jobz : %d [%s]\n", p.Jobz, ParamString(p.Jobz))
fmt.Printf("Range : %d [%s]\n", p.Range, ParamString(p.Range))
}
// Local Variables:
// tab-width: 4
// End: