mirror of
https://github.com/gonum/gonum.git
synced 2025-10-07 16:11:03 +08:00
all: remove redundant bad prefix and make panic strings const
This commit is contained in:
@@ -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)
|
||||
|
@@ -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 (
|
||||
|
@@ -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):
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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?
|
||||
|
||||
|
@@ -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"
|
||||
|
@@ -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"
|
||||
|
@@ -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)
|
||||
|
@@ -4,4 +4,4 @@
|
||||
|
||||
package distmat
|
||||
|
||||
var badDim = "distmat: dimension mismatch"
|
||||
const badDim = "distmat: dimension mismatch"
|
||||
|
@@ -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"
|
||||
|
@@ -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
|
||||
|
@@ -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 (
|
||||
|
@@ -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]
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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{}
|
||||
|
Reference in New Issue
Block a user