1 // Copyright ©2015 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "gonum.org/v1/gonum/lapack"
13 // Dlange computes the matrix norm of the general m×n matrix a. The input norm
14 // specifies the norm computed.
15 // lapack.MaxAbs: the maximum absolute value of an element.
16 // lapack.MaxColumnSum: the maximum column sum of the absolute values of the entries.
17 // lapack.MaxRowSum: the maximum row sum of the absolute values of the entries.
18 // lapack.NormFrob: the square root of the sum of the squares of the entries.
19 // If norm == lapack.MaxColumnSum, work must be of length n, and this function will panic otherwise.
20 // There are no restrictions on work for the other matrix norms.
21 func (impl Implementation) Dlange(norm lapack.MatrixNorm, m, n int, a []float64, lda int, work []float64) float64 {
22 // TODO(btracey): These should probably be refactored to use BLAS calls.
23 checkMatrix(m, n, a, lda)
25 case lapack.MaxRowSum, lapack.MaxColumnSum, lapack.NormFrob, lapack.MaxAbs:
29 if norm == lapack.MaxColumnSum && len(work) < n {
35 if norm == lapack.MaxAbs {
37 for i := 0; i < m; i++ {
38 for j := 0; j < n; j++ {
39 value = math.Max(value, math.Abs(a[i*lda+j]))
44 if norm == lapack.MaxColumnSum {
48 for i := 0; i < n; i++ {
51 for i := 0; i < m; i++ {
52 for j := 0; j < n; j++ {
53 work[j] += math.Abs(a[i*lda+j])
57 for i := 0; i < n; i++ {
58 value = math.Max(value, work[i])
62 if norm == lapack.MaxRowSum {
64 for i := 0; i < m; i++ {
66 for j := 0; j < n; j++ {
67 sum += math.Abs(a[i*lda+j])
69 value = math.Max(value, sum)
73 if norm == lapack.NormFrob {
77 for i := 0; i < m; i++ {
78 scale, sum = impl.Dlassq(n, a[i*lda:], 1, scale, sum)
80 value = scale * math.Sqrt(sum)
83 panic("lapack: bad matrix norm")