github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/general.go (about) 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 package native 6 7 import ( 8 "github.com/gonum/lapack" 9 ) 10 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{} 15 16 var _ lapack.Float64 = Implementation{} 17 18 // This list is duplicated in lapack/cgo. Keep in sync. 19 const ( 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 badWorkStride = "lapack: insufficient working array stride" 61 badZ = "lapack: insufficient z length" 62 kGTM = "lapack: k > m" 63 kGTN = "lapack: k > n" 64 kLT0 = "lapack: k < 0" 65 mLT0 = "lapack: m < 0" 66 mLTN = "lapack: m < n" 67 nanScale = "lapack: NaN scale factor" 68 negDimension = "lapack: negative matrix dimension" 69 negZ = "lapack: negative z value" 70 nLT0 = "lapack: n < 0" 71 nLTM = "lapack: n < m" 72 offsetGTM = "lapack: offset > m" 73 shortWork = "lapack: working array shorter than declared" 74 zeroDiv = "lapack: zero divisor" 75 ) 76 77 // checkMatrix verifies the parameters of a matrix input. 78 func checkMatrix(m, n int, a []float64, lda int) { 79 if m < 0 { 80 panic("lapack: has negative number of rows") 81 } 82 if n < 0 { 83 panic("lapack: has negative number of columns") 84 } 85 if lda < n { 86 panic("lapack: stride less than number of columns") 87 } 88 if len(a) < (m-1)*lda+n { 89 panic("lapack: insufficient matrix slice length") 90 } 91 } 92 93 func checkVector(n int, v []float64, inc int) { 94 if n < 0 { 95 panic("lapack: negative vector length") 96 } 97 if (inc > 0 && (n-1)*inc >= len(v)) || (inc < 0 && (1-n)*inc >= len(v)) { 98 panic("lapack: insufficient vector slice length") 99 } 100 } 101 102 func min(a, b int) int { 103 if a < b { 104 return a 105 } 106 return b 107 } 108 109 func max(a, b int) int { 110 if a > b { 111 return a 112 } 113 return b 114 } 115 116 const ( 117 // dlamchE is the machine epsilon. For IEEE this is 2^{-53}. 118 dlamchE = 1.0 / (1 << 53) 119 120 // dlamchB is the radix of the machine (the base of the number system). 121 dlamchB = 2 122 123 // dlamchP is base * eps. 124 dlamchP = dlamchB * dlamchE 125 126 // dlamchS is the "safe minimum", that is, the lowest number such that 127 // 1/dlamchS does not overflow, or also the smallest normal number. 128 // For IEEE this is 2^{-1022}. 129 dlamchS = 1.0 / (1 << 256) / (1 << 256) / (1 << 256) / (1 << 254) 130 )