Skip to content

Commit

Permalink
lapack/netlib: autogenerate errors strings from gonum copy
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Sep 27, 2018
1 parent 7a718cd commit 94581c6
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 61 deletions.
1 change: 1 addition & 0 deletions .travis/check-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -ex

go generate gonum.org/v1/netlib/blas/netlib
go generate gonum.org/v1/netlib/lapack/lapacke
go generate gonum.org/v1/netlib/lapack/netlib
if [ -n "$(git diff)" ]; then
exit 1
fi
68 changes: 68 additions & 0 deletions lapack/netlib/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lapack/netlib/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright ©2018 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:generate go run generate_errors.go

package netlib
57 changes: 57 additions & 0 deletions lapack/netlib/generate_errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright ©2018 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build ignore

package main

import (
"fmt"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
"path/filepath"
)

const errorFile = "../../../gonum/lapack/gonum/errors.go"

func main() {
path, err := filepath.Abs(errorFile)
if err != nil {
log.Fatalf("no absolute path for %q: %v", errorFile, err)
}

fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, nil, 0)
if err != nil {
log.Fatalf("failed to parse %q: %v", path, err)
}

dst := filepath.Base(errorFile)
o, err := os.Create(dst)
if err != nil {
log.Fatalf("failed to create %q: %v", dst, err)
}
defer o.Close()

fmt.Fprintln(o, header)
p := printer.Config{
Mode: printer.UseSpaces | printer.TabIndent,
Tabwidth: 8,
}
p.Fprint(o, fset, f.Decls)
fmt.Fprintln(o)
}

const header = `// Code generated by "go generate gonum.org/v1/netlib/lapack/netlib”; DO NOT EDIT.
// Copyright ©2018 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package netlib
// Copied from gonum/lapack/gonum. Keep in sync.`
61 changes: 0 additions & 61 deletions lapack/netlib/lapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,6 @@ import (
"gonum.org/v1/netlib/lapack/lapacke"
)

// Copied from gonum/lapack/gonum. Keep in sync.
const (
absIncNotOne = "lapack: increment not one or negative one"
badAlpha = "lapack: bad alpha length"
badApplyOrtho = "lapack: bad ApplyOrtho"
badAuxv = "lapack: auxv has insufficient length"
badBeta = "lapack: bad beta length"
badD = "lapack: d has insufficient length"
badDiag = "lapack: bad diag"
badDims = "lapack: bad input dimensions"
badDirect = "lapack: bad direct"
badE = "lapack: e has insufficient length"
badEVComp = "lapack: bad EVComp"
badEVHowMany = "lapack: bad EVHowMany"
badEVJob = "lapack: bad EVJob"
badEVSide = "lapack: bad EVSide"
badGenOrtho = "lapack: bad GenOrtho"
badGSVDJob = "lapack: bad GSVDJob"
badIlo = "lapack: ilo out of range"
badIhi = "lapack: ihi out of range"
badIpiv = "lapack: bad permutation length"
badBalanceJob = "lapack: bad BalanceJob"
badK1 = "lapack: k1 out of range"
badK2 = "lapack: k2 out of range"
badKperm = "lapack: incorrect permutation length"
badLdA = "lapack: index of a out of range"
badNb = "lapack: nb out of range"
badNorm = "lapack: bad norm"
badPivot = "lapack: bad pivot"
badS = "lapack: s has insufficient length"
badSchurComp = "lapack: bad SchurComp"
badSchurJob = "lapack: bad SchurJob"
badShifts = "lapack: bad shifts"
badSide = "lapack: bad side"
badSlice = "lapack: bad input slice length"
badSort = "lapack: bad Sort"
badStore = "lapack: bad store"
badTau = "lapack: tau has insufficient length"
badTauQ = "lapack: tauQ has insufficient length"
badTauP = "lapack: tauP has insufficient length"
badTrans = "lapack: bad trans"
badVn1 = "lapack: vn1 has insufficient length"
badVn2 = "lapack: vn2 has insufficient length"
badUplo = "lapack: illegal triangle"
badWork = "lapack: insufficient working memory"
badZ = "lapack: insufficient z length"
kGTM = "lapack: k > m"
kGTN = "lapack: k > n"
kLT0 = "lapack: k < 0"
mLT0 = "lapack: m < 0"
mLTN = "lapack: m < n"
nanScale = "lapack: NaN scale factor"
negDimension = "lapack: negative matrix dimension"
negZ = "lapack: negative z value"
nLT0 = "lapack: n < 0"
nLTM = "lapack: n < m"
offsetGTM = "lapack: offset > m"
shortWork = "lapack: working array shorter than declared"
zeroDiv = "lapack: zero divisor"
)

func min(m, n int) int {
if m < n {
return m
Expand Down

0 comments on commit 94581c6

Please sign in to comment.