mat: add SymDense.Norm
MODIFY
mat/symmetric.go
mat/symmetric.go
@@ -9,6 +9,8 @@ import (
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
+ "gonum.org/v1/gonum/lapack"
+ "gonum.org/v1/gonum/lapack/lapack64"
)
var (
@@ -577,6 +579,25 @@ func (s *SymDense) sliceSym(i, k int) *SymDense {
return &v
}
+// Norm returns the specified norm of the receiver. Valid norms are:
+// 1 - The maximum absolute column sum
+// 2 - The Frobenius norm, the square root of the sum of the squares of the elements
+// Inf - The maximum absolute row sum
+//
+// Norm will panic with ErrNormOrder if an illegal norm is specified.
+func (s *SymDense) Norm(norm float64) float64 {
+ if s.IsEmpty() {
+ panic(ErrZeroLength)
+ }
+ lnorm := normLapack(norm, false)
+ if lnorm == lapack.MaxColumnSum || lnorm == lapack.MaxRowSum {
+ work := getFloats(s.mat.N, false)
+ defer putFloats(work)
+ return lapack64.Lansy(lnorm, s.mat, work)
+ }
+ return lapack64.Lansy(lnorm, s.mat, nil)
+}
+
// Trace returns the trace of the matrix.
func (s *SymDense) Trace() float64 {
// TODO(btracey): could use internal asm sum routine.

mat: add SymDense.Norm