github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/testlapack/dlaset.go (about) 1 // Copyright ©2015 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 "fmt" 9 "math/rand" 10 "testing" 11 12 "github.com/gonum/blas" 13 ) 14 15 type Dlaseter interface { 16 Dlaset(uplo blas.Uplo, m, n int, alpha, beta float64, a []float64, lda int) 17 } 18 19 func DlasetTest(t *testing.T, impl Dlaseter) { 20 rnd := rand.New(rand.NewSource(1)) 21 for ti, test := range []struct { 22 m, n int 23 }{ 24 {0, 0}, 25 {1, 1}, 26 {1, 10}, 27 {10, 1}, 28 {2, 2}, 29 {2, 10}, 30 {10, 2}, 31 {11, 11}, 32 {11, 100}, 33 {100, 11}, 34 } { 35 m := test.m 36 n := test.n 37 for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower, blas.All} { 38 for _, extra := range []int{0, 10} { 39 a := randomGeneral(m, n, n+extra, rnd) 40 alpha := 1.0 41 beta := 2.0 42 43 impl.Dlaset(uplo, m, n, alpha, beta, a.Data, a.Stride) 44 45 prefix := fmt.Sprintf("Case #%v: m=%v,n=%v,uplo=%v,extra=%v", 46 ti, m, n, uplo, extra) 47 if !generalOutsideAllNaN(a) { 48 t.Errorf("%v: out-of-range write to A", prefix) 49 } 50 for i := 0; i < min(m, n); i++ { 51 if a.Data[i*a.Stride+i] != beta { 52 t.Errorf("%v: unexpected diagonal of A") 53 } 54 } 55 if uplo == blas.Upper || uplo == blas.All { 56 for i := 0; i < m; i++ { 57 for j := i + 1; j < n; j++ { 58 if a.Data[i*a.Stride+j] != alpha { 59 t.Errorf("%v: unexpected upper triangle of A") 60 } 61 } 62 } 63 } 64 if uplo == blas.Lower || uplo == blas.All { 65 for i := 1; i < m; i++ { 66 for j := 0; j < min(i, n); j++ { 67 if a.Data[i*a.Stride+j] != alpha { 68 t.Errorf("%v: unexpected lower triangle of A") 69 } 70 } 71 } 72 } 73 } 74 } 75 } 76 }