diff --git a/mat/eigen.go b/mat/eigen.go index caa208e9d..4bed4068a 100644 --- a/mat/eigen.go +++ b/mat/eigen.go @@ -11,7 +11,7 @@ import ( const ( badFact = "mat: use without successful factorization" - badNoVect = "mat: eigenvectors not computed" + noVectors = "mat: eigenvectors not computed" ) // EigenSym is a type for creating and manipulating the Eigen decomposition of @@ -103,7 +103,7 @@ func (e *EigenSym) VectorsTo(dst *Dense) { panic(badFact) } if !e.vectorsComputed { - panic(badNoVect) + panic(noVectors) } r, c := e.vectors.Dims() if dst.IsEmpty() { @@ -320,7 +320,7 @@ func (e *Eigen) VectorsTo(dst *CDense) { panic(badFact) } if e.kind&EigenRight == 0 { - panic(badNoVect) + panic(noVectors) } if dst.IsEmpty() { dst.ReuseAs(e.n, e.n) @@ -346,7 +346,7 @@ func (e *Eigen) LeftVectorsTo(dst *CDense) { panic(badFact) } if e.kind&EigenLeft == 0 { - panic(badNoVect) + panic(noVectors) } if dst.IsEmpty() { dst.ReuseAs(e.n, e.n) diff --git a/mathext/internal/cephes/cephes.go b/mathext/internal/cephes/cephes.go index d01552ac7..20cac067e 100644 --- a/mathext/internal/cephes/cephes.go +++ b/mathext/internal/cephes/cephes.go @@ -15,9 +15,9 @@ See https://github.com/deepmind/torch-cephes/blob/master/LICENSE.txt and https://lists.debian.org/debian-legal/2004/12/msg00295.html */ -var ( - badParamOutOfBounds = "cephes: parameter out of bounds" - badParamFunctionSingularity = "cephes: function singularity" +const ( + paramOutOfBounds = "cephes: parameter out of bounds" + errParamFunctionSingularity = "cephes: function singularity" ) const ( diff --git a/mathext/internal/cephes/igam.go b/mathext/internal/cephes/igam.go index 9bd044549..fcd2a1833 100644 --- a/mathext/internal/cephes/igam.go +++ b/mathext/internal/cephes/igam.go @@ -69,7 +69,7 @@ func Igam(a, x float64) float64 { } if x < 0 || a <= 0 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } // Asymptotic regime where a ~ x; see [2]. @@ -101,7 +101,7 @@ func IgamC(a, x float64) float64 { switch { case x < 0, a <= 0: - panic(badParamOutOfBounds) + panic(paramOutOfBounds) case x == 0: return 1 case math.IsInf(x, 0): diff --git a/mathext/internal/cephes/igami.go b/mathext/internal/cephes/igami.go index 446e8ccfb..697582e43 100644 --- a/mathext/internal/cephes/igami.go +++ b/mathext/internal/cephes/igami.go @@ -26,7 +26,7 @@ func IgamI(a, p float64) float64 { dithresh := 5.0 * machEp if p < 0 || p > 1 || a <= 0 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } if p == 0 { diff --git a/mathext/internal/cephes/incbeta.go b/mathext/internal/cephes/incbeta.go index 661846f8f..6a818154f 100644 --- a/mathext/internal/cephes/incbeta.go +++ b/mathext/internal/cephes/incbeta.go @@ -24,7 +24,7 @@ const ( // Incbet computes the regularized incomplete beta function. func Incbet(aa, bb, xx float64) float64 { if aa <= 0 || bb <= 0 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } if xx <= 0 || xx >= 1 { if xx == 0 { @@ -33,7 +33,7 @@ func Incbet(aa, bb, xx float64) float64 { if xx == 1 { return 1 } - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } var flag int diff --git a/mathext/internal/cephes/ndtri.go b/mathext/internal/cephes/ndtri.go index 156a30d4a..03910ff8f 100644 --- a/mathext/internal/cephes/ndtri.go +++ b/mathext/internal/cephes/ndtri.go @@ -108,13 +108,13 @@ func Ndtri(y0 float64) float64 { if y0 <= 0.0 { if y0 < 0 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } return math.Inf(-1) } if y0 >= 1.0 { if y0 > 1 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } return math.Inf(1) } diff --git a/mathext/internal/cephes/zeta.go b/mathext/internal/cephes/zeta.go index 746c0a5f5..f87b552e2 100644 --- a/mathext/internal/cephes/zeta.go +++ b/mathext/internal/cephes/zeta.go @@ -48,15 +48,15 @@ func Zeta(x, q float64) float64 { } if x < 1 { - panic(badParamOutOfBounds) + panic(paramOutOfBounds) } if q <= 0 { if q == math.Floor(q) { - panic(badParamFunctionSingularity) + panic(errParamFunctionSingularity) } if x != math.Floor(x) { - panic(badParamOutOfBounds) // Because q^-x not defined + panic(paramOutOfBounds) // Because q^-x not defined } } diff --git a/optimize/convex/lp/simplex.go b/optimize/convex/lp/simplex.go index 57fa5ec29..fc5364fb5 100644 --- a/optimize/convex/lp/simplex.go +++ b/optimize/convex/lp/simplex.go @@ -33,9 +33,7 @@ var ( ErrZeroRow = errors.New("lp: A has a row of all zeros") ) -var ( - badShape = "lp: size mismatch" -) +const badShape = "lp: size mismatch" // TODO(btracey): Should these tolerances be part of a settings struct? diff --git a/optimize/errors.go b/optimize/errors.go index a06645a81..7d6f8aee0 100644 --- a/optimize/errors.go +++ b/optimize/errors.go @@ -75,6 +75,4 @@ func (err ErrGrad) Error() string { } // List of shared panic strings -var ( - badProblem = "optimize: objective function is undefined" -) +const badProblem = "optimize: objective function is undefined" diff --git a/optimize/functions/doc.go b/optimize/functions/doc.go index 3bdfe8bfa..0f29768d7 100644 --- a/optimize/functions/doc.go +++ b/optimize/functions/doc.go @@ -10,6 +10,4 @@ // significance due to prior use as benchmark cases. package functions // import "gonum.org/v1/gonum/optimize/functions" -const ( - badInputDim = "functions: wrong input dimension" -) +const badInputDim = "functions: wrong input dimension" diff --git a/stat/combin/combin.go b/stat/combin/combin.go index e6aa61026..c50b9492a 100644 --- a/stat/combin/combin.go +++ b/stat/combin/combin.go @@ -10,10 +10,10 @@ import ( ) const ( - badNegInput = "combin: negative input" - badSetSize = "combin: n < k" - badInput = "combin: wrong input slice length" - nonpositiveDimension = "combin: non-positive dimension" + errNegInput = "combin: negative input" + badSetSize = "combin: n < k" + badInput = "combin: wrong input slice length" + errNonpositiveDimension = "combin: non-positive dimension" ) // Binomial returns the binomial coefficient of (n,k), also commonly referred to @@ -28,7 +28,7 @@ const ( // No check is made for overflow. func Binomial(n, k int) int { if n < 0 || k < 0 { - panic(badNegInput) + panic(errNegInput) } if n < k { panic(badSetSize) @@ -61,7 +61,7 @@ func GeneralizedBinomial(n, k float64) float64 { // See GeneralizedBinomial for more information. func LogGeneralizedBinomial(n, k float64) float64 { if n < 0 || k < 0 { - panic(badNegInput) + panic(errNegInput) } if n < k { panic(badSetSize) @@ -193,7 +193,7 @@ func nextCombination(s []int, n, k int) { // [0,n) integers, if n or k are non-negative, or if k is greater than n. func CombinationIndex(comb []int, n, k int) int { if n < 0 || k < 0 { - panic(badNegInput) + panic(errNegInput) } if n < k { panic(badSetSize) @@ -359,7 +359,7 @@ func IdxFor(sub, dims []int) int { v := sub[i] d := dims[i] if d <= 0 { - panic(nonpositiveDimension) + panic(errNonpositiveDimension) } if v < 0 || v >= d { panic("combin: invalid subscript") @@ -386,7 +386,7 @@ func SubFor(sub []int, idx int, dims []int) []int { panic(badInput) } if idx < 0 { - panic(badNegInput) + panic(errNegInput) } stride := 1 for i := len(dims) - 1; i >= 1; i-- { @@ -396,7 +396,7 @@ func SubFor(sub []int, idx int, dims []int) []int { v := idx / stride d := dims[i] if d < 0 { - panic(nonpositiveDimension) + panic(errNonpositiveDimension) } if v >= dims[i] { panic("combin: index too large") @@ -528,7 +528,7 @@ func (p *PermutationGenerator) Permutation(dst []int) []int { // [0,n) integers, if n or k are non-negative, or if k is greater than n. func PermutationIndex(perm []int, n, k int) int { if n < 0 || k < 0 { - panic(badNegInput) + panic(errNegInput) } if n < k { panic(badSetSize) diff --git a/stat/distmat/general.go b/stat/distmat/general.go index 072ad7760..f6be29e8a 100644 --- a/stat/distmat/general.go +++ b/stat/distmat/general.go @@ -4,4 +4,4 @@ package distmat -var badDim = "distmat: dimension mismatch" +const badDim = "distmat: dimension mismatch" diff --git a/stat/distmv/general.go b/stat/distmv/general.go index 704e29902..c5e6c8b0a 100644 --- a/stat/distmv/general.go +++ b/stat/distmv/general.go @@ -4,7 +4,7 @@ package distmv -var ( +const ( badQuantile = "distmv: quantile not between 0 and 1" badReceiver = "distmv: input slice is not nil or the correct length" badSizeMismatch = "distmv: size mismatch" diff --git a/stat/distmv/normal.go b/stat/distmv/normal.go index 8ddd606e9..aad27dad0 100644 --- a/stat/distmv/normal.go +++ b/stat/distmv/normal.go @@ -15,9 +15,7 @@ import ( "gonum.org/v1/gonum/stat/distuv" ) -var ( - badInputLength = "distmv: input slice length mismatch" -) +const badInputLength = "distmv: input slice length mismatch" // Normal is a multivariate normal distribution (also known as the multivariate // Gaussian distribution). Its pdf in k dimensions is given by diff --git a/stat/distuv/general.go b/stat/distuv/general.go index 5db299d73..5b7899194 100644 --- a/stat/distuv/general.go +++ b/stat/distuv/general.go @@ -10,11 +10,11 @@ type Parameter struct { Value float64 } -var ( +const ( badPercentile = "distuv: percentile out of bounds" badLength = "distuv: slice length mismatch" badSuffStat = "distuv: wrong suffStat length" - badNoSamples = "distuv: must have at least one sample" + errNoSamples = "distuv: must have at least one sample" ) const ( diff --git a/stat/distuv/laplace.go b/stat/distuv/laplace.go index 93048faa4..727a6aa75 100644 --- a/stat/distuv/laplace.go +++ b/stat/distuv/laplace.go @@ -50,7 +50,7 @@ func (l *Laplace) Fit(samples, weights []float64) { } if len(samples) == 0 { - panic(badNoSamples) + panic(errNoSamples) } if len(samples) == 1 { l.Mu = samples[0] diff --git a/stat/samplemv/metropolishastings.go b/stat/samplemv/metropolishastings.go index e3451fbea..ad09fa380 100644 --- a/stat/samplemv/metropolishastings.go +++ b/stat/samplemv/metropolishastings.go @@ -205,7 +205,7 @@ func (p *ProposalNormal) ConditionalRand(x, y []float64) []float64 { x = make([]float64, p.normal.Dim()) } if len(x) != len(y) { - panic(badLengthMismatch) + panic(errLengthMismatch) } p.normal.SetMean(y) p.normal.Rand(x) diff --git a/stat/samplemv/samplemv.go b/stat/samplemv/samplemv.go index 20ac11415..e0a38d275 100644 --- a/stat/samplemv/samplemv.go +++ b/stat/samplemv/samplemv.go @@ -14,9 +14,7 @@ import ( "gonum.org/v1/gonum/stat/distmv" ) -var ( - badLengthMismatch = "samplemv: slice length mismatch" -) +const errLengthMismatch = "samplemv: slice length mismatch" var ( _ Sampler = LatinHypercube{} @@ -62,7 +60,7 @@ type SampleUniformWeighted struct { func (w SampleUniformWeighted) SampleWeighted(batch *mat.Dense, weights []float64) { r, _ := batch.Dims() if r != len(weights) { - panic(badLengthMismatch) + panic(errLengthMismatch) } w.Sample(batch) for i := range weights { @@ -143,7 +141,7 @@ func (l Importance) SampleWeighted(batch *mat.Dense, weights []float64) { func importance(batch *mat.Dense, weights []float64, target distmv.LogProber, proposal distmv.RandLogProber) { r, _ := batch.Dims() if r != len(weights) { - panic(badLengthMismatch) + panic(errLengthMismatch) } for i := 0; i < r; i++ { v := batch.RawRowView(i) diff --git a/stat/sampleuv/sample.go b/stat/sampleuv/sample.go index 8fd3c1140..724a40634 100644 --- a/stat/sampleuv/sample.go +++ b/stat/sampleuv/sample.go @@ -13,9 +13,7 @@ import ( "gonum.org/v1/gonum/stat/distuv" ) -var ( - badLengthMismatch = "sample: slice length mismatch" -) +const badLengthMismatch = "sample: slice length mismatch" var ( _ Sampler = LatinHypercube{}