github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dgbmv.go (about) 1 // Copyright ©2014 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 testblas 6 7 import ( 8 "testing" 9 10 "github.com/jingcheng-WU/gonum/blas" 11 ) 12 13 type Dgbmver interface { 14 Dgbmv(tA blas.Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) 15 } 16 17 func DgbmvTest(t *testing.T, blasser Dgbmver) { 18 for i, test := range []struct { 19 tA blas.Transpose 20 m, n int 21 kL, kU int 22 alpha float64 23 a [][]float64 24 lda int 25 x []float64 26 beta float64 27 y []float64 28 ans []float64 29 }{ 30 { 31 tA: blas.NoTrans, 32 m: 9, 33 n: 6, 34 lda: 4, 35 kL: 2, 36 kU: 1, 37 alpha: 3.0, 38 beta: 2.0, 39 a: [][]float64{ 40 {5, 3, 0, 0, 0, 0}, 41 {-1, 2, 9, 0, 0, 0}, 42 {4, 8, 3, 6, 0, 0}, 43 {0, -1, 8, 2, 1, 0}, 44 {0, 0, 9, 9, 9, 5}, 45 {0, 0, 0, 2, -3, 2}, 46 {0, 0, 0, 0, 1, 5}, 47 {0, 0, 0, 0, 0, 6}, 48 }, 49 x: []float64{1, 2, 3, 4, 5, 6}, 50 y: []float64{-1, -2, -3, -4, -5, -6, -7, -8, -9}, 51 ans: []float64{31, 86, 153, 97, 404, 3, 91, 92, -18}, 52 }, 53 { 54 tA: blas.Trans, 55 m: 9, 56 n: 6, 57 lda: 4, 58 kL: 2, 59 kU: 1, 60 alpha: 3.0, 61 beta: 2.0, 62 a: [][]float64{ 63 {5, 3, 0, 0, 0, 0}, 64 {-1, 2, 9, 0, 0, 0}, 65 {4, 8, 3, 6, 0, 0}, 66 {0, -1, 8, 2, 1, 0}, 67 {0, 0, 9, 9, 9, 5}, 68 {0, 0, 0, 2, -3, 2}, 69 {0, 0, 0, 0, 1, 5}, 70 {0, 0, 0, 0, 0, 6}, 71 }, 72 x: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, 73 y: []float64{-1, -2, -3, -4, -5, -6}, 74 ans: []float64{43, 77, 306, 241, 104, 348}, 75 }, 76 { 77 tA: blas.NoTrans, 78 m: 6, 79 n: 3, 80 lda: 1, 81 kL: 0, 82 kU: 0, 83 alpha: 2.0, 84 beta: 1.0, 85 a: [][]float64{ 86 {1, 0, 0}, 87 {0, 1, 0}, 88 {0, 0, 1}, 89 }, 90 x: []float64{1, 2, 3}, 91 y: []float64{-1, -2, -3, -4, -5, -6}, 92 ans: []float64{1, 2, 3, -4, -5, -6}, 93 }, 94 { 95 tA: blas.Trans, 96 m: 6, 97 n: 3, 98 lda: 1, 99 kL: 0, 100 kU: 0, 101 alpha: 2.0, 102 beta: 1.0, 103 a: [][]float64{ 104 {1, 0, 0}, 105 {0, 1, 0}, 106 {0, 0, 1}, 107 {0, 0, 0}, 108 {0, 0, 0}, 109 {0, 0, 0}, 110 }, 111 x: []float64{1, 2, 3, 4, 5, 6}, 112 y: []float64{-1, -2, -3}, 113 ans: []float64{1, 2, 3}, 114 }, 115 { 116 tA: blas.NoTrans, 117 m: 3, 118 n: 5, 119 lda: 4, 120 kL: 1, 121 kU: 2, 122 alpha: 2.0, 123 beta: 1.0, 124 a: [][]float64{ 125 {1, 2, 3, 0, 0}, 126 {1, 3, 6, 9, 0}, 127 {0, 1, 1, 1, 1}, 128 }, 129 x: []float64{1, 2, 3, 4, 5}, 130 y: []float64{-1, -2, -3}, 131 ans: []float64{-1 + 2*(1+4+9), -2 + 2*(1+6+18+36), -3 + 2*(2+3+4+5)}, 132 }, 133 } { 134 extra := 3 135 aFlat := flattenBanded(test.a, test.kU, test.kL) 136 incTest := func(incX, incY, extra int) { 137 xnew := makeIncremented(test.x, incX, extra) 138 ynew := makeIncremented(test.y, incY, extra) 139 ans := makeIncremented(test.ans, incY, extra) 140 blasser.Dgbmv(test.tA, test.m, test.n, test.kL, test.kU, test.alpha, aFlat, test.lda, xnew, incX, test.beta, ynew, incY) 141 if !dSliceTolEqual(ans, ynew) { 142 t.Errorf("Case %v: Want %v, got %v", i, ans, ynew) 143 } 144 } 145 incTest(1, 1, extra) 146 incTest(1, 3, extra) 147 incTest(1, -3, extra) 148 incTest(2, 3, extra) 149 incTest(2, -3, extra) 150 incTest(3, 2, extra) 151 incTest(-3, 2, extra) 152 } 153 }