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/blas"
11 "gonum.org/v1/gonum/lapack"
14 // Dlansy computes the specified norm of an n×n symmetric matrix. If
15 // norm == lapack.MaxColumnSum or norm == lapackMaxRowSum work must have length
16 // at least n, otherwise work is unused.
17 func (impl Implementation) Dlansy(norm lapack.MatrixNorm, uplo blas.Uplo, n int, a []float64, lda int, work []float64) float64 {
18 checkMatrix(n, n, a, lda)
20 case lapack.MaxRowSum, lapack.MaxColumnSum, lapack.NormFrob, lapack.MaxAbs:
24 if (norm == lapack.MaxColumnSum || norm == lapack.MaxRowSum) && len(work) < n {
27 if uplo != blas.Upper && uplo != blas.Lower {
38 if uplo == blas.Upper {
40 for i := 0; i < n; i++ {
41 for j := i; j < n; j++ {
42 v := math.Abs(a[i*lda+j])
54 for i := 0; i < n; i++ {
55 for j := 0; j <= i; j++ {
56 v := math.Abs(a[i*lda+j])
66 case lapack.MaxRowSum, lapack.MaxColumnSum:
67 // A symmetric matrix has the same 1-norm and ∞-norm.
68 for i := 0; i < n; i++ {
71 if uplo == blas.Upper {
72 for i := 0; i < n; i++ {
73 work[i] += math.Abs(a[i*lda+i])
74 for j := i + 1; j < n; j++ {
75 v := math.Abs(a[i*lda+j])
81 for i := 0; i < n; i++ {
82 for j := 0; j < i; j++ {
83 v := math.Abs(a[i*lda+j])
87 work[i] += math.Abs(a[i*lda+i])
91 for i := 0; i < n; i++ {
101 case lapack.NormFrob:
102 if uplo == blas.Upper {
104 for i := 0; i < n; i++ {
107 for j := i + 1; j < n; j++ {
112 return math.Sqrt(sum)
115 for i := 0; i < n; i++ {
116 for j := 0; j < i; j++ {
123 return math.Sqrt(sum)