mat: clean up lint

This commit is contained in:
Dan Kortschak
2019-11-02 14:17:29 +10:30
parent ad7fbd52c6
commit 455f782e4c
10 changed files with 93 additions and 40 deletions

View File

@@ -134,7 +134,10 @@ func TestCholeskySolveTo(t *testing.T) {
}
var x Dense
chol.SolveTo(&x, test.b)
err := chol.SolveTo(&x, test.b)
if err != nil {
t.Errorf("unexpected error from Cholesky solve: %v", err)
}
if !EqualApprox(&x, test.ans, 1e-12) {
t.Error("incorrect Cholesky solve solution")
}
@@ -195,13 +198,19 @@ func TestCholeskySolveCholTo(t *testing.T) {
}
var x Dense
chola.SolveCholTo(&x, &cholb)
err := chola.SolveCholTo(&x, &cholb)
if err != nil {
t.Errorf("unexpected error from Cholesky solve: %v", err)
}
var ans Dense
ans.Mul(test.a, &x)
if !EqualApprox(&ans, test.b, 1e-12) {
var y Dense
y.Solve(test.a, test.b)
err := y.Solve(test.a, test.b)
if err != nil {
t.Errorf("unexpected error from dense solve: %v", err)
}
t.Errorf("incorrect Cholesky solve solution product\ngot solution:\n%.4v\nwant solution\n%.4v",
Formatted(&x), Formatted(&y))
}
@@ -239,7 +248,10 @@ func TestCholeskySolveVecTo(t *testing.T) {
}
var x VecDense
chol.SolveVecTo(&x, test.b)
err := chol.SolveVecTo(&x, test.b)
if err != nil {
t.Errorf("unexpected error from Cholesky solve: %v", err)
}
if !EqualApprox(&x, test.ans, 1e-12) {
t.Error("incorrect Cholesky solve solution")
}
@@ -326,7 +338,10 @@ func TestCholeskyInverseTo(t *testing.T) {
}
var sInv SymDense
chol.InverseTo(&sInv)
err := chol.InverseTo(&sInv)
if err != nil {
t.Errorf("unexpected error from Cholesky inverse: %v", err)
}
var ans Dense
ans.Mul(&sInv, &s)
@@ -672,7 +687,10 @@ func BenchmarkCholeskyInverseTo(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
chol.InverseTo(dst)
err := chol.InverseTo(dst)
if err != nil {
b.Fatalf("unexpected error from Cholesky inverse: %v", err)
}
}
})
}

View File

@@ -545,7 +545,7 @@ func (m *Dense) Exp(a Matrix) {
vpu.Add(v, u)
vmu.Sub(v, u)
m.Solve(vmu, vpu)
_ = m.Solve(vmu, vpu)
return
}
@@ -615,7 +615,7 @@ func (m *Dense) Exp(a Matrix) {
vpu.Add(v, u)
vmu.Sub(v, u)
m.Solve(vmu, vpu)
_ = m.Solve(vmu, vpu)
for ; s > 0; s-- {
m.Mul(m, m)

View File

@@ -584,7 +584,10 @@ func marshalBinaryBenchDense(b *testing.B, size int) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
m.MarshalBinary()
_, err := m.MarshalBinary()
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -606,7 +609,10 @@ func unmarshalBinaryBenchDense(b *testing.B, size int) {
for n := 0; n < b.N; n++ {
var m Dense
m.UnmarshalBinary(buf)
err := m.UnmarshalBinary(buf)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -625,7 +631,10 @@ func marshalBinaryToBenchDense(b *testing.B, size int) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
m.MarshalBinaryTo(w)
_, err := m.MarshalBinaryTo(w)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -663,7 +672,10 @@ func unmarshalBinaryFromBenchDense(b *testing.B, size int) {
for n := 0; n < b.N; n++ {
var m Dense
m.UnmarshalBinaryFrom(r)
_, err := m.UnmarshalBinaryFrom(r)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
r.reset()
}
}
@@ -682,7 +694,10 @@ func marshalBinaryBenchVecDense(b *testing.B, size int) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
vec.MarshalBinary()
_, err := vec.MarshalBinary()
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -704,7 +719,10 @@ func unmarshalBinaryBenchVecDense(b *testing.B, size int) {
for n := 0; n < b.N; n++ {
var vec VecDense
vec.UnmarshalBinary(buf)
err := vec.UnmarshalBinary(buf)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -723,7 +741,10 @@ func marshalBinaryToBenchVecDense(b *testing.B, size int) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
vec.MarshalBinaryTo(w)
_, err := vec.MarshalBinaryTo(w)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
@@ -746,7 +767,10 @@ func unmarshalBinaryFromBenchVecDense(b *testing.B, size int) {
for n := 0; n < b.N; n++ {
var vec VecDense
vec.UnmarshalBinaryFrom(r)
_, err := vec.UnmarshalBinaryFrom(r)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
r.reset()
}
}

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//nolint:deadcode,unused
package mat
import (

View File

@@ -79,7 +79,10 @@ func TestLQSolveTo(t *testing.T) {
var x Dense
lq := &LQ{}
lq.Factorize(a)
lq.SolveTo(&x, trans, b)
err := lq.SolveTo(&x, trans, b)
if err != nil {
t.Errorf("unexpected error from LQ solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b if !trans
@@ -132,7 +135,10 @@ func TestLQSolveToVec(t *testing.T) {
var x VecDense
lq := &LQ{}
lq.Factorize(a)
lq.SolveVecTo(&x, trans, b)
err := lq.SolveVecTo(&x, trans, b)
if err != nil {
t.Errorf("unexpected error from LQ solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b if !trans

View File

@@ -103,7 +103,10 @@ func TestQRSolveTo(t *testing.T) {
var x Dense
var qr QR
qr.Factorize(a)
qr.SolveTo(&x, trans, b)
err := qr.SolveTo(&x, trans, b)
if err != nil {
t.Errorf("unexpected error from QR solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b if !trans
@@ -156,7 +159,10 @@ func TestQRSolveVecTo(t *testing.T) {
var x VecDense
var qr QR
qr.Factorize(a)
qr.SolveVecTo(&x, trans, b)
err := qr.SolveVecTo(&x, trans, b)
if err != nil {
t.Errorf("unexpected error from QR solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b if !trans

View File

@@ -214,7 +214,10 @@ func TestSolve(t *testing.T) {
}
}
var x Dense
x.Solve(a, b)
err := x.Solve(a, b)
if err != nil {
t.Errorf("unexpected error from dense solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b
@@ -233,10 +236,10 @@ func TestSolve(t *testing.T) {
Solve(a, b Matrix) error
}
rd := receiver.(Solver)
rd.Solve(a, b)
_ = rd.Solve(a, b)
}
denseComparison := func(receiver, a, b *Dense) {
receiver.Solve(a, b)
_ = receiver.Solve(a, b)
}
testTwoInput(t, "Solve", &Dense{}, method, denseComparison, legalTypesAll, legalSizeSolve, 1e-7)
}
@@ -269,7 +272,10 @@ func TestSolveVec(t *testing.T) {
b.SetVec(i, rand.Float64())
}
var x VecDense
x.SolveVec(a, b)
err := x.SolveVec(a, b)
if err != nil {
t.Errorf("unexpected error from dense vector solve: %v", err)
}
// Test that the normal equations hold.
// Aᵀ * A * x = Aᵀ * b
@@ -288,10 +294,10 @@ func TestSolveVec(t *testing.T) {
SolveVec(a Matrix, b Vector) error
}
rd := receiver.(SolveVecer)
rd.SolveVec(a, b.(Vector))
_ = rd.SolveVec(a, b.(Vector))
}
denseComparison := func(receiver, a, b *Dense) {
receiver.Solve(a, b)
_ = receiver.Solve(a, b)
}
testTwoInput(t, "SolveVec", &VecDense{}, method, denseComparison, legalTypesMatrixVector, legalSizeSolve, 1e-12)
}

View File

@@ -630,8 +630,8 @@ func (s *SymDense) GrowSym(n int) Symmetric {
// PowPSD computes a^pow where a is a positive symmetric definite matrix.
//
// PowPSD returns an error if the matrix is not not positive symmetric definite
// or the Eigendecomposition is not successful.
// PowPSD returns an error if the matrix is not not positive symmetric definite
// or the Eigen decomposition is not successful.
func (s *SymDense) PowPSD(a Symmetric, pow float64) error {
dim := a.Symmetric()
s.reuseAsNonZeroed(dim)

View File

@@ -724,7 +724,10 @@ func TestPowPSD(t *testing.T) {
mat.SymOuterK(1, a)
var sym SymDense
sym.PowPSD(&mat, float64(pow))
err := sym.PowPSD(&mat, float64(pow))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
var dense Dense
dense.Pow(&mat, pow)

View File

@@ -178,17 +178,6 @@ func isUpperUplo(u blas.Uplo) bool {
}
}
func uploToTriKind(u blas.Uplo) TriKind {
switch u {
case blas.Upper:
return Upper
case blas.Lower:
return Lower
default:
panic(badTriangle)
}
}
// asSymBlas returns the receiver restructured as a blas64.Symmetric with the
// same backing memory. Panics if the receiver is unit.
// This returns a blas64.Symmetric and not a *SymDense because SymDense can only