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.
8 "gonum.org/v1/gonum/lapack"
11 // Implementation is the native Go implementation of LAPACK routines. It
12 // is built on top of calls to the return of blas64.Implementation(), so while
13 // this code is in pure Go, the underlying BLAS implementation may not be.
14 type Implementation struct{}
16 var _ lapack.Float64 = Implementation{}
18 // This list is duplicated in lapack/cgo. Keep in sync.
20 absIncNotOne = "lapack: increment not one or negative one"
21 badAlpha = "lapack: bad alpha length"
22 badAuxv = "lapack: auxv has insufficient length"
23 badBeta = "lapack: bad beta length"
24 badD = "lapack: d has insufficient length"
25 badDecompUpdate = "lapack: bad decomp update"
26 badDiag = "lapack: bad diag"
27 badDims = "lapack: bad input dimensions"
28 badDirect = "lapack: bad direct"
29 badE = "lapack: e has insufficient length"
30 badEVComp = "lapack: bad EVComp"
31 badEVJob = "lapack: bad EVJob"
32 badEVSide = "lapack: bad EVSide"
33 badGSVDJob = "lapack: bad GSVDJob"
34 badHowMany = "lapack: bad HowMany"
35 badIlo = "lapack: ilo out of range"
36 badIhi = "lapack: ihi out of range"
37 badIpiv = "lapack: bad permutation length"
38 badJob = "lapack: bad Job"
39 badK1 = "lapack: k1 out of range"
40 badK2 = "lapack: k2 out of range"
41 badKperm = "lapack: incorrect permutation length"
42 badLdA = "lapack: index of a out of range"
43 badNb = "lapack: nb out of range"
44 badNorm = "lapack: bad norm"
45 badPivot = "lapack: bad pivot"
46 badS = "lapack: s has insufficient length"
47 badShifts = "lapack: bad shifts"
48 badSide = "lapack: bad side"
49 badSlice = "lapack: bad input slice length"
50 badSort = "lapack: bad Sort"
51 badStore = "lapack: bad store"
52 badTau = "lapack: tau has insufficient length"
53 badTauQ = "lapack: tauQ has insufficient length"
54 badTauP = "lapack: tauP has insufficient length"
55 badTrans = "lapack: bad trans"
56 badVn1 = "lapack: vn1 has insufficient length"
57 badVn2 = "lapack: vn2 has insufficient length"
58 badUplo = "lapack: illegal triangle"
59 badWork = "lapack: insufficient working memory"
60 badZ = "lapack: insufficient z length"
61 kGTM = "lapack: k > m"
62 kGTN = "lapack: k > n"
63 kLT0 = "lapack: k < 0"
64 mLTN = "lapack: m < n"
65 nanScale = "lapack: NaN scale factor"
66 negDimension = "lapack: negative matrix dimension"
67 negZ = "lapack: negative z value"
68 nLT0 = "lapack: n < 0"
69 nLTM = "lapack: n < m"
70 offsetGTM = "lapack: offset > m"
71 shortWork = "lapack: working array shorter than declared"
72 zeroDiv = "lapack: zero divisor"
75 // checkMatrix verifies the parameters of a matrix input.
76 func checkMatrix(m, n int, a []float64, lda int) {
78 panic("lapack: has negative number of rows")
81 panic("lapack: has negative number of columns")
84 panic("lapack: stride less than number of columns")
86 if len(a) < (m-1)*lda+n {
87 panic("lapack: insufficient matrix slice length")
91 func checkVector(n int, v []float64, inc int) {
93 panic("lapack: negative vector length")
95 if (inc > 0 && (n-1)*inc >= len(v)) || (inc < 0 && (1-n)*inc >= len(v)) {
96 panic("lapack: insufficient vector slice length")
100 func checkSymBanded(ab []float64, n, kd, lda int) {
102 panic("lapack: negative banded length")
105 panic("lapack: negative bandwidth value")
108 panic("lapack: stride less than number of bands")
110 if len(ab) < (n-1)*lda+kd {
111 panic("lapack: insufficient banded vector length")
115 func min(a, b int) int {
122 func max(a, b int) int {
130 // dlamchE is the machine epsilon. For IEEE this is 2^{-53}.
131 dlamchE = 1.0 / (1 << 53)
133 // dlamchB is the radix of the machine (the base of the number system).
136 // dlamchP is base * eps.
137 dlamchP = dlamchB * dlamchE
139 // dlamchS is the "safe minimum", that is, the lowest number such that
140 // 1/dlamchS does not overflow, or also the smallest normal number.
141 // For IEEE this is 2^{-1022}.
142 dlamchS = 1.0 / (1 << 256) / (1 << 256) / (1 << 256) / (1 << 254)