github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/testlapack/dlaswp.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  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/jingcheng-WU/gonum/blas/blas64"
    12  )
    13  
    14  type Dlaswper interface {
    15  	Dlaswp(n int, a []float64, lda, k1, k2 int, ipiv []int, incX int)
    16  }
    17  
    18  func DlaswpTest(t *testing.T, impl Dlaswper) {
    19  	for ti, test := range []struct {
    20  		k1, k2 int
    21  		ipiv   []int
    22  		incX   int
    23  
    24  		want blas64.General
    25  	}{
    26  		{
    27  			k1:   0,
    28  			k2:   2,
    29  			ipiv: []int{0, 1, 2},
    30  			incX: 1,
    31  			want: blas64.General{
    32  				Rows:   4,
    33  				Cols:   3,
    34  				Stride: 3,
    35  				Data: []float64{
    36  					1, 2, 3,
    37  					4, 5, 6,
    38  					7, 8, 9,
    39  					10, 11, 12,
    40  				},
    41  			},
    42  		},
    43  		{
    44  			k1:   0,
    45  			k2:   2,
    46  			ipiv: []int{0, 1, 2},
    47  			incX: -1,
    48  			want: blas64.General{
    49  				Rows:   4,
    50  				Cols:   3,
    51  				Stride: 3,
    52  				Data: []float64{
    53  					1, 2, 3,
    54  					4, 5, 6,
    55  					7, 8, 9,
    56  					10, 11, 12,
    57  				},
    58  			},
    59  		},
    60  		{
    61  			k1:   0,
    62  			k2:   2,
    63  			ipiv: []int{1, 2, 3},
    64  			incX: 1,
    65  			want: blas64.General{
    66  				Rows:   5,
    67  				Cols:   3,
    68  				Stride: 3,
    69  				Data: []float64{
    70  					4, 5, 6,
    71  					7, 8, 9,
    72  					10, 11, 12,
    73  					1, 2, 3,
    74  					13, 14, 15,
    75  				},
    76  			},
    77  		},
    78  		{
    79  			k1:   0,
    80  			k2:   2,
    81  			ipiv: []int{1, 2, 3},
    82  			incX: -1,
    83  			want: blas64.General{
    84  				Rows:   5,
    85  				Cols:   3,
    86  				Stride: 3,
    87  				Data: []float64{
    88  					10, 11, 12,
    89  					1, 2, 3,
    90  					4, 5, 6,
    91  					7, 8, 9,
    92  					13, 14, 15,
    93  				},
    94  			},
    95  		},
    96  	} {
    97  		m := test.want.Rows
    98  		n := test.want.Cols
    99  		k1 := test.k1
   100  		k2 := test.k2
   101  		if len(test.ipiv) != k2+1 {
   102  			panic("bad length of ipiv")
   103  		}
   104  		incX := test.incX
   105  		for _, extra := range []int{0, 11} {
   106  			a := zeros(m, n, n+extra)
   107  			c := 1
   108  			for i := 0; i < m; i++ {
   109  				for j := 0; j < n; j++ {
   110  					a.Data[i*a.Stride+j] = float64(c)
   111  					c++
   112  				}
   113  			}
   114  
   115  			ipiv := make([]int, len(test.ipiv))
   116  			copy(ipiv, test.ipiv)
   117  
   118  			impl.Dlaswp(n, a.Data, a.Stride, k1, k2, ipiv, incX)
   119  
   120  			prefix := fmt.Sprintf("Case %v (m=%v,n=%v,k1=%v,k2=%v,extra=%v)", ti, m, n, k1, k2, extra)
   121  			if !generalOutsideAllNaN(a) {
   122  				t.Errorf("%v: out-of-range write to A", prefix)
   123  			}
   124  
   125  			if !equalApproxGeneral(a, test.want, 0) {
   126  				t.Errorf("%v: unexpected A\n%v\n%v", prefix, a, test.want)
   127  			}
   128  		}
   129  	}
   130  }