github.com/gopherd/gonum@v0.0.4/blas/testblas/ztrmv.go (about) 1 // Copyright ©2017 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/gopherd/gonum/blas" 11 ) 12 13 var ztrmvTestCases = []struct { 14 uplo blas.Uplo 15 a []complex128 16 x []complex128 17 18 // Results with non-unit diagonal. 19 want []complex128 20 wantNeg []complex128 21 wantTrans []complex128 22 wantTransNeg []complex128 23 wantConjTrans []complex128 24 wantConjTransNeg []complex128 25 26 // Results with unit diagonal. 27 wantUnit []complex128 28 wantUnitNeg []complex128 29 wantUnitTrans []complex128 30 wantUnitTransNeg []complex128 31 wantUnitConjTrans []complex128 32 wantUnitConjTransNeg []complex128 33 }{ 34 {uplo: blas.Upper}, 35 {uplo: blas.Lower}, 36 { 37 uplo: blas.Upper, 38 a: []complex128{ 39 6 - 8i, -10 + 10i, -6 - 3i, -1 - 8i, 40 znan, 7 + 8i, -7 + 9i, 3 + 6i, 41 znan, znan, 6 - 4i, -2 - 5i, 42 znan, znan, znan, 4 - 8i, 43 }, 44 x: []complex128{ 45 10 - 5i, 46 -2 + 2i, 47 8 - 1i, 48 -7 + 9i, 49 }, 50 51 want: []complex128{ 52 48 - 121i, 53 -152 + 62i, 54 103 - 21i, 55 44 + 92i, 56 }, 57 wantNeg: []complex128{ 58 0 - 100i, 59 -49 - 20i, 60 120 + 70i, 61 -72 + 119i, 62 }, 63 wantTrans: []complex128{ 64 20 - 110i, 65 -80 + 148i, 66 -35 - 70i, 67 -45 - 27i, 68 }, 69 wantTransNeg: []complex128{ 70 123 - 2i, 71 18 + 66i, 72 44 - 103i, 73 30 + 110i, 74 }, 75 wantConjTrans: []complex128{ 76 100 + 50i, 77 -148 - 20i, 78 39 + 90i, 79 -75 + 125i, 80 }, 81 wantConjTransNeg: []complex128{ 82 27 - 70i, 83 -70 - 136i, 84 208 - 91i, 85 -114 - 2i, 86 }, 87 88 wantUnit: []complex128{ 89 38 - 16i, 90 -124 + 66i, 91 67 + 16i, 92 -7 + 9i, 93 }, 94 wantUnitNeg: []complex128{ 95 10 - 5i, 96 -47 - 38i, 97 64 + 12i, 98 -109 + 18i, 99 }, 100 wantUnitTrans: []complex128{ 101 10 - 5i, 102 -52 + 152i, 103 -71 - 33i, 104 -96 - 110i, 105 }, 106 wantUnitTransNeg: []complex128{ 107 133 + 93i, 108 20 + 48i, 109 -12 - 161i, 110 -7 + 9i, 111 }, 112 wantUnitConjTrans: []complex128{ 113 10 - 5i, 114 -152 - 48i, 115 -5 + 63i, 116 18 + 154i, 117 }, 118 wantUnitConjTransNeg: []complex128{ 119 -43 - 135i, 120 -52 - 138i, 121 168 - 21i, 122 -7 + 9i, 123 }, 124 }, 125 { 126 uplo: blas.Lower, 127 a: []complex128{ 128 10 - 8i, znan, znan, znan, 129 1 - 6i, -4 + 8i, znan, znan, 130 2 - 6i, 4 - 8i, 5 + 3i, znan, 131 -7 - 4i, 1 + 3i, -2 - 4i, 9 + 8i, 132 }, 133 x: []complex128{ 134 10 + 5i, 135 -7 + 1i, 136 3 - 1i, 137 9 + 10i, 138 }, 139 140 want: []complex128{ 141 140 - 30i, 142 60 - 115i, 143 48 + 14i, 144 -69 + 57i, 145 }, 146 wantNeg: []complex128{ 147 51 + 53i, 148 44 - 78i, 149 65 - 16i, 150 170 + 28i, 151 }, 152 wantTrans: []complex128{ 153 116 - 113i, 154 3 - 51i, 155 40 - 52i, 156 1 + 162i, 157 }, 158 wantTransNeg: []complex128{ 159 50 + 125i, 160 -38 - 66i, 161 -29 + 123i, 162 109 - 22i, 163 }, 164 wantConjTrans: []complex128{ 165 -44 + 71i, 166 95 + 55i, 167 -46 + 2i, 168 161 + 18i, 169 }, 170 wantConjTransNeg: []complex128{ 171 130 - 35i, 172 -72 + 56i, 173 -31 - 97i, 174 -91 + 154i, 175 }, 176 177 wantUnit: []complex128{ 178 10 + 5i, 179 33 - 54i, 180 33 + 9i, 181 -61 - 95i, 182 }, 183 wantUnitNeg: []complex128{ 184 11 - 67i, 185 75 - 61i, 186 72 - 45i, 187 9 + 10i, 188 }, 189 wantUnitTrans: []complex128{ 190 -14 - 78i, 191 -24 + 10i, 192 25 - 57i, 193 9 + 10i, 194 }, 195 wantUnitTransNeg: []complex128{ 196 10 + 5i, 197 -7 - 49i, 198 -22 + 94i, 199 -52 - 40i, 200 }, 201 wantUnitConjTrans: []complex128{ 202 -94 - 54i, 203 52 + 4i, 204 -55 + 15i, 205 9 + 10i, 206 }, 207 wantUnitConjTransNeg: []complex128{ 208 10 + 5i, 209 -47 + 31i, 210 -8 - 78i, 211 -92 - 8i, 212 }, 213 }, 214 } 215 216 type Ztrmver interface { 217 Ztrmv(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, n int, a []complex128, lda int, x []complex128, incX int) 218 } 219 220 func ZtrmvTest(t *testing.T, impl Ztrmver) { 221 for tc, test := range ztrmvTestCases { 222 n := len(test.x) 223 uplo := test.uplo 224 for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} { 225 for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} { 226 for _, incX := range []int{-11, -2, -1, 1, 2, 7} { 227 for _, lda := range []int{max(1, n), n + 11} { 228 a := makeZGeneral(test.a, n, n, lda) 229 if diag == blas.Unit { 230 for i := 0; i < n; i++ { 231 a[i*lda+i] = znan 232 } 233 } 234 aCopy := make([]complex128, len(a)) 235 copy(aCopy, a) 236 237 x := makeZVector(test.x, incX) 238 239 impl.Ztrmv(uplo, trans, diag, n, a, lda, x, incX) 240 241 if !zsame(a, aCopy) { 242 t.Errorf("Case %v (uplo=%v,trans=%v,diag=%v,lda=%v,incX=%v): unexpected modification of A", tc, uplo, trans, diag, lda, incX) 243 } 244 245 var want []complex128 246 if diag == blas.NonUnit { 247 switch { 248 case trans == blas.NoTrans && incX > 0: 249 want = makeZVector(test.want, incX) 250 case trans == blas.NoTrans && incX < 0: 251 want = makeZVector(test.wantNeg, incX) 252 case trans == blas.Trans && incX > 0: 253 want = makeZVector(test.wantTrans, incX) 254 case trans == blas.Trans && incX < 0: 255 want = makeZVector(test.wantTransNeg, incX) 256 case trans == blas.ConjTrans && incX > 0: 257 want = makeZVector(test.wantConjTrans, incX) 258 case trans == blas.ConjTrans && incX < 0: 259 want = makeZVector(test.wantConjTransNeg, incX) 260 } 261 } else { 262 switch { 263 case trans == blas.NoTrans && incX > 0: 264 want = makeZVector(test.wantUnit, incX) 265 case trans == blas.NoTrans && incX < 0: 266 want = makeZVector(test.wantUnitNeg, incX) 267 case trans == blas.Trans && incX > 0: 268 want = makeZVector(test.wantUnitTrans, incX) 269 case trans == blas.Trans && incX < 0: 270 want = makeZVector(test.wantUnitTransNeg, incX) 271 case trans == blas.ConjTrans && incX > 0: 272 want = makeZVector(test.wantUnitConjTrans, incX) 273 case trans == blas.ConjTrans && incX < 0: 274 want = makeZVector(test.wantUnitConjTransNeg, incX) 275 } 276 } 277 if !zsame(x, want) { 278 t.Errorf("Case %v (uplo=%v,trans=%v,diag=%v,lda=%v,incX=%v): unexpected result\nwant %v\ngot %v", tc, uplo, trans, diag, lda, incX, want, x) 279 } 280 } 281 } 282 } 283 } 284 } 285 }