github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/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 native 6 7 import ( 8 "math" 9 10 "github.com/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 if len(d) < n { 18 panic(badD) 19 } 20 if len(e) < n-1 { 21 panic(badE) 22 } 23 if n <= 0 { 24 return 0 25 } 26 switch norm { 27 default: 28 panic(badNorm) 29 case lapack.MaxAbs: 30 anorm := math.Abs(d[n-1]) 31 for i := 0; i < n-1; i++ { 32 sum := math.Abs(d[i]) 33 if anorm < sum || math.IsNaN(sum) { 34 anorm = sum 35 } 36 sum = math.Abs(e[i]) 37 if anorm < sum || math.IsNaN(sum) { 38 anorm = sum 39 } 40 } 41 return anorm 42 case lapack.MaxColumnSum, lapack.MaxRowSum: 43 if n == 1 { 44 return math.Abs(d[0]) 45 } 46 anorm := math.Abs(d[0]) + math.Abs(e[0]) 47 sum := math.Abs(e[n-2]) + math.Abs(d[n-1]) 48 if anorm < sum || math.IsNaN(sum) { 49 anorm = sum 50 } 51 for i := 1; i < n-1; i++ { 52 sum := math.Abs(d[i]) + math.Abs(e[i]) + math.Abs(e[i-1]) 53 if anorm < sum || math.IsNaN(sum) { 54 anorm = sum 55 } 56 } 57 return anorm 58 case lapack.NormFrob: 59 var scale float64 60 sum := 1.0 61 if n > 1 { 62 scale, sum = impl.Dlassq(n-1, e, 1, scale, sum) 63 sum = 2 * sum 64 } 65 scale, sum = impl.Dlassq(n, d, 1, scale, sum) 66 return scale * math.Sqrt(sum) 67 } 68 }