mat: add SymDense.Norm

This commit is contained in:
Vladimir Chalupecky
2021-05-05 13:52:01 +02:00
committed by Vladimír Chalupecký
parent 35f38e4c0a
commit c935d6f1aa

View File

@@ -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.