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