all: simplify code identified by gosimple
MODIFY
graph/encoding/dot/dot_test.go
graph/encoding/dot/dot_test.go
@@ -363,7 +363,7 @@ type subGraph struct {
func (g subGraph) ID() int { return g.id }
func (g subGraph) Subgraph() graph.Graph {
- return namedGraph{id: g.id, Graph: g.Graph}
+ return namedGraph(g)
}
func undirectedSubGraphFrom(g []intset, s map[int][]intset) graph.Graph {

MODIFY
graph/path/dijkstra_test.go
graph/path/dijkstra_test.go
@@ -143,7 +143,7 @@ func TestDijkstraAllPaths(t *testing.T) {
}
np, weight, unique := pt.Between(test.NoPathFor.From(), test.NoPathFor.To())
- if np != nil || !math.IsInf(weight, 1) || unique != false {
+ if np != nil || !math.IsInf(weight, 1) || unique {
t.Errorf("%q: unexpected path:\ngot: path=%v weight=%f unique=%t\nwant:path=<nil> weight=+Inf unique=false",
test.Name, np, weight, unique)
}

MODIFY
graph/path/floydwarshall_test.go
graph/path/floydwarshall_test.go
@@ -67,7 +67,7 @@ func TestFloydWarshall(t *testing.T) {
}
np, weight, unique := pt.Between(test.NoPathFor.From(), test.NoPathFor.To())
- if np != nil || !math.IsInf(weight, 1) || unique != false {
+ if np != nil || !math.IsInf(weight, 1) || unique {
t.Errorf("%q: unexpected path:\ngot: path=%v weight=%f unique=%t\nwant:path=<nil> weight=+Inf unique=false",
test.Name, np, weight, unique)
}

MODIFY
graph/path/johnson_apsp_test.go
graph/path/johnson_apsp_test.go
@@ -67,7 +67,7 @@ func TestJohnsonAllPaths(t *testing.T) {
}
np, weight, unique := pt.Between(test.NoPathFor.From(), test.NoPathFor.To())
- if np != nil || !math.IsInf(weight, 1) || unique != false {
+ if np != nil || !math.IsInf(weight, 1) || unique {
t.Errorf("%q: unexpected path:\ngot: path=%v weight=%f unique=%t\nwant:path=<nil> weight=+Inf unique=false",
test.Name, np, weight, unique)
}

MODIFY
lapack/testlapack/general.go
lapack/testlapack/general.go
@@ -1135,10 +1135,9 @@ func isRightEigenvectorOf(a blas64.General, xRe, xIm []float64, lambda complex12
lambdax := make([]float64, n)
floats.AddScaled(lambdax, real(lambda), xRe)
- if floats.Distance(xReAns, lambdax, math.Inf(1)) > tol {
- return false
- }
- return true
+ // This is expressed as the inverse to catch the case
+ // xReAns_i = Inf and lambdax_i = Inf of the same sign.
+ return !(floats.Distance(xReAns, lambdax, math.Inf(1)) > tol)
}
// Complex eigenvector, and real or complex eigenvalue.
@@ -1195,10 +1194,9 @@ func isLeftEigenvectorOf(a blas64.General, yRe, yIm []float64, lambda complex128
lambday := make([]float64, n)
floats.AddScaled(lambday, real(lambda), yRe)
- if floats.Distance(yReAns, lambday, math.Inf(1)) > tol {
- return false
- }
- return true
+ // This is expressed as the inverse to catch the case
+ // yReAns_i = Inf and lambday_i = Inf of the same sign.
+ return !(floats.Distance(yReAns, lambday, math.Inf(1)) > tol)
}
// Complex eigenvector, and real or complex eigenvalue.

MODIFY
stat/distuv/general_test.go
stat/distuv/general_test.go
@@ -29,10 +29,9 @@ type UniProbDist interface {
}
func absEq(a, b float64) bool {
- if math.Abs(a-b) > 1e-14 {
- return false
- }
- return true
+ // This is expressed as the inverse to catch the
+ // case a = Inf and b = Inf of the same sign.
+ return !(math.Abs(a-b) > 1e-14)
}
// TODO: Implement a better test for Quantile

MODIFY
stat/distuv/laplace.go
stat/distuv/laplace.go
@@ -105,7 +105,6 @@ func (l Laplace) MarshalParameters(p []Parameter) {
p[0].Value = l.Mu
p[1].Name = "Scale"
p[1].Value = l.Scale
- return
}
// Mean returns the mean of the probability distribution.

MODIFY
stat/distuv/uniform.go
stat/distuv/uniform.go
@@ -66,7 +66,6 @@ func (u Uniform) MarshalParameters(p []Parameter) {
p[0].Value = u.Min
p[1].Name = "Max"
p[1].Value = u.Max
- return
}
// Mean returns the mean of the probability distribution.

MODIFY
stat/samplemv/sample_test.go
stat/samplemv/sample_test.go
@@ -47,7 +47,7 @@ func TestLatinHypercube(t *testing.T) {
allPresent := true
for i := 0; i < nSamples; i++ {
for j := 0; j < dim; j++ {
- if present[i][j] == false {
+ if !present[i][j] {
allPresent = false
}
}

MODIFY
stat/samplemv/samplemv.go
stat/samplemv/samplemv.go
@@ -111,9 +111,7 @@ func LatinHypercube(batch *mat.Dense, q distmv.Quantiler, src *rand.Rand) {
for i := 0; i < c; i++ {
p := perm(r)
for j := 0; j < r; j++ {
- var v float64
- v = f64()
- v = v/r64 + float64(j)/r64
+ v := f64()/r64 + float64(j)/r64
batch.Set(p[j], i, v)
}
}

all: simplify code identified by gosimple