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