github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/matgen_test.go (about) 1 // Copyright ©2017 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/blas/blas64" 13 ) 14 15 func TestDlagsy(t *testing.T) { 16 const tol = 1e-14 17 rnd := rand.New(rand.NewSource(1)) 18 for _, n := range []int{0, 1, 2, 3, 4, 5, 10, 50} { 19 for _, lda := range []int{0, 2*n + 1} { 20 if lda == 0 { 21 lda = max(1, n) 22 } 23 d := make([]float64, n) 24 for i := range d { 25 d[i] = 1 26 } 27 a := blas64.General{ 28 Rows: n, 29 Cols: n, 30 Stride: lda, 31 Data: nanSlice(n * lda), 32 } 33 work := make([]float64, a.Rows+a.Cols) 34 35 Dlagsy(a.Rows, 0, d, a.Data, a.Stride, rnd, work) 36 37 isIdentity := true 38 identityLoop: 39 for i := 0; i < n; i++ { 40 for j := 0; j < n; j++ { 41 aij := a.Data[i*a.Stride+j] 42 if math.IsNaN(aij) { 43 isIdentity = false 44 } 45 if i == j && math.Abs(aij-1) > tol { 46 isIdentity = false 47 } 48 if i != j && math.Abs(aij) > tol { 49 isIdentity = false 50 } 51 if !isIdentity { 52 break identityLoop 53 } 54 } 55 } 56 if !isIdentity { 57 t.Errorf("Case n=%v,lda=%v: unexpected result", n, lda) 58 } 59 } 60 } 61 } 62 63 func TestDlagge(t *testing.T) { 64 rnd := rand.New(rand.NewSource(1)) 65 for _, n := range []int{0, 1, 2, 3, 4, 5, 10, 50} { 66 for _, lda := range []int{0, 2*n + 1} { 67 if lda == 0 { 68 lda = max(1, n) 69 } 70 d := make([]float64, n) 71 for i := range d { 72 d[i] = 1 73 } 74 a := blas64.General{ 75 Rows: n, 76 Cols: n, 77 Stride: lda, 78 Data: nanSlice(n * lda), 79 } 80 work := make([]float64, a.Rows+a.Cols) 81 82 Dlagge(a.Rows, a.Cols, 0, 0, d, a.Data, a.Stride, rnd, work) 83 84 if !isOrthonormal(a) { 85 t.Errorf("Case n=%v,lda=%v: unexpected result", n, lda) 86 } 87 } 88 } 89 90 }