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