mat: add DiagDense.Norm
MODIFY
mat/diagonal.go
mat/diagonal.go
package mat
import (
+ "math"
+
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
)
@@ -324,3 +326,25 @@ func (d *DiagDense) Trace() float64 {
return tr
}
+
+// Norm returns the specified norm of the receiver. Valid norms are:
+// 1 or Inf - The maximum diagonal element magnitude
+// 2 - The Frobenius norm, the square root of the sum of the squares of
+// the diagonal elements
+//
+// Norm will panic with ErrNormOrder if an illegal norm is specified and with
+// ErrZeroLength if the receiver has zero size.
+func (d *DiagDense) Norm(norm float64) float64 {
+ if d.IsEmpty() {
+ panic(ErrZeroLength)
+ }
+ switch norm {
+ default:
+ panic(ErrNormOrder)
+ case 1, math.Inf(1):
+ imax := blas64.Iamax(d.mat)
+ return math.Abs(d.at(imax, imax))
+ case 2:
+ return blas64.Nrm2(d.mat)
+ }
+}

MODIFY
mat/matrix.go
mat/matrix.go
@@ -44,6 +44,7 @@ type allMatrix interface {
type denseMatrix interface {
DiagView() Diagonal
Tracer
+ Normer
}
var (

mat: add DiagDense.Norm