Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Add TestNormZero and make it pass
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-ch committed Oct 9, 2015
1 parent 94809a6 commit a30becb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mat64/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ func Norm(a Matrix, norm float64) float64 {
}
return lapack64.Lansy(n, rm, work)
case *Vector:
if rma.isZero() {
return 0
}
rv := rma.RawVector()
switch norm {
default:
Expand Down
19 changes: 19 additions & 0 deletions mat64/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"fmt"
"math"
"testing"

"github.com/gonum/blas"
"github.com/gonum/blas/blas64"
)

var inf = math.Inf(1)
Expand Down Expand Up @@ -253,6 +256,22 @@ func TestNorm(t *testing.T) {
testOneInputFunc(t, "Norm_inf", f, denseComparison, sameAnswerFloatApprox, isAnyType, isAnySize)
}

func TestNormZero(t *testing.T) {
for _, a := range []Matrix{
&Dense{},
&SymDense{mat: blas64.Symmetric{Uplo: blas.Upper}},
&TriDense{mat: blas64.Triangular{Uplo: blas.Upper, Diag: blas.NonUnit}},
&Vector{},
} {
for _, norm := range []float64{1, 2, math.Inf(1)} {
panicked, message := panics(func() { Norm(a, norm) })
if panicked {
t.Errorf("unexpected panic for Norm(&%T{}, %v): %v", a, norm, message)
}
}
}
}

func TestSum(t *testing.T) {
f := func(a Matrix) interface{} {
return Sum(a)
Expand Down

0 comments on commit a30becb

Please sign in to comment.