diff --git a/mat/symband.go b/mat/symband.go index 4eae3caf..f204dad3 100644 --- a/mat/symband.go +++ b/mat/symband.go @@ -7,6 +7,8 @@ package mat import ( "gonum.org/v1/gonum/blas" "gonum.org/v1/gonum/blas/blas64" + "gonum.org/v1/gonum/lapack" + "gonum.org/v1/gonum/lapack/lapack64" ) var ( @@ -242,6 +244,25 @@ func (s *SymBandDense) DoColNonZero(j int, fn func(i, j int, v float64)) { } } +// 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 *SymBandDense) 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.Lansb(lnorm, s.mat, work) + } + return lapack64.Lansb(lnorm, s.mat, nil) +} + // Trace returns the trace. func (s *SymBandDense) Trace() float64 { rb := s.RawSymBand()