gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/lapack/testlapack/dlanhs.go (about) 1 // Copyright ©2023 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 "testing" 10 11 "golang.org/x/exp/rand" 12 13 "gonum.org/v1/gonum/lapack" 14 ) 15 16 type Dlanhser interface { 17 Dlanhs(norm lapack.MatrixNorm, n int, a []float64, lda int, work []float64) float64 18 } 19 20 func DlanhsTest(t *testing.T, impl Dlanhser) { 21 const tol = 1e-15 22 rnd := rand.New(rand.NewSource(1)) 23 for _, n := range []int{0, 1, 2, 4, 9} { 24 for _, lda := range []int{max(1, n), n + 5} { 25 a := randomGeneral(n, n, lda, rnd) 26 for _, norm := range []lapack.MatrixNorm{lapack.MaxAbs, lapack.MaxRowSum, lapack.MaxColumnSum, lapack.Frobenius} { 27 var work []float64 28 if norm == lapack.MaxColumnSum { 29 work = nanSlice(n) 30 } 31 32 got := impl.Dlanhs(norm, a.Rows, a.Data, lda, work) 33 34 // Zero out A below the first subdiagonal. 35 for i := 2; i < n; i++ { 36 for j := 0; j < max(0, i-1); j++ { 37 a.Data[i*a.Stride+j] = 0 38 } 39 } 40 want := dlange(norm, a.Rows, a.Cols, a.Data, a.Stride) 41 42 if math.Abs(want-got) > tol*want { 43 t.Errorf("Case n=%v,lda=%v,norm=%v: unexpected result. Want %v, got %v.", n, lda, normToString(norm), want, got) 44 } 45 } 46 } 47 } 48 }