gonum.org/v1/gonum@v0.14.0/lapack/gonum/dlanst.go (about) 1 // Copyright ©2016 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. 4 5 package gonum 6 7 import ( 8 "math" 9 10 "gonum.org/v1/gonum/lapack" 11 ) 12 13 // Dlanst computes the specified norm of a symmetric tridiagonal matrix A. 14 // The diagonal elements of A are stored in d and the off-diagonal elements 15 // are stored in e. 16 func (impl Implementation) Dlanst(norm lapack.MatrixNorm, n int, d, e []float64) float64 { 17 switch { 18 case norm != lapack.MaxRowSum && norm != lapack.MaxColumnSum && norm != lapack.Frobenius && norm != lapack.MaxAbs: 19 panic(badNorm) 20 case n < 0: 21 panic(nLT0) 22 } 23 if n == 0 { 24 return 0 25 } 26 switch { 27 case len(d) < n: 28 panic(shortD) 29 case len(e) < n-1: 30 panic(shortE) 31 } 32 33 switch norm { 34 default: 35 panic(badNorm) 36 case lapack.MaxAbs: 37 anorm := math.Abs(d[n-1]) 38 for i := 0; i < n-1; i++ { 39 sum := math.Abs(d[i]) 40 if anorm < sum || math.IsNaN(sum) { 41 anorm = sum 42 } 43 sum = math.Abs(e[i]) 44 if anorm < sum || math.IsNaN(sum) { 45 anorm = sum 46 } 47 } 48 return anorm 49 case lapack.MaxColumnSum, lapack.MaxRowSum: 50 if n == 1 { 51 return math.Abs(d[0]) 52 } 53 anorm := math.Abs(d[0]) + math.Abs(e[0]) 54 sum := math.Abs(e[n-2]) + math.Abs(d[n-1]) 55 if anorm < sum || math.IsNaN(sum) { 56 anorm = sum 57 } 58 for i := 1; i < n-1; i++ { 59 sum := math.Abs(d[i]) + math.Abs(e[i]) + math.Abs(e[i-1]) 60 if anorm < sum || math.IsNaN(sum) { 61 anorm = sum 62 } 63 } 64 return anorm 65 case lapack.Frobenius: 66 var scale float64 67 sum := 1.0 68 if n > 1 { 69 scale, sum = impl.Dlassq(n-1, e, 1, scale, sum) 70 sum = 2 * sum 71 } 72 scale, sum = impl.Dlassq(n, d, 1, scale, sum) 73 return scale * math.Sqrt(sum) 74 } 75 }