github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/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 testlapack 6 7 import ( 8 "math" 9 "math/rand" 10 "testing" 11 12 "github.com/gonum/lapack" 13 ) 14 15 type Dlanster interface { 16 Dlanst(norm lapack.MatrixNorm, n int, d, e []float64) float64 17 Dlanger 18 } 19 20 func DlanstTest(t *testing.T, impl Dlanster) { 21 rnd := rand.New(rand.NewSource(1)) 22 for _, norm := range []lapack.MatrixNorm{lapack.MaxAbs, lapack.MaxColumnSum, lapack.MaxRowSum, lapack.NormFrob} { 23 for _, n := range []int{1, 3, 10, 100} { 24 for cas := 0; cas < 100; cas++ { 25 d := make([]float64, n) 26 for i := range d { 27 d[i] = rnd.NormFloat64() 28 } 29 e := make([]float64, n-1) 30 for i := range e { 31 e[i] = rnd.NormFloat64() 32 } 33 34 m := n 35 lda := n 36 a := make([]float64, m*lda) 37 for i := 0; i < n; i++ { 38 a[i*lda+i] = d[i] 39 } 40 for i := 0; i < n-1; i++ { 41 a[i*lda+i+1] = e[i] 42 a[(i+1)*lda+i] = e[i] 43 } 44 work := make([]float64, n) 45 syNorm := impl.Dlanst(norm, n, d, e) 46 geNorm := impl.Dlange(norm, m, n, a, lda, work) 47 if math.Abs(syNorm-geNorm) > 1e-12 { 48 t.Errorf("Norm mismatch: norm = %v, cas = %v, n = %v. Want %v, got %v.", string(norm), cas, n, geNorm, syNorm) 49 } 50 } 51 } 52 } 53 }