github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dsymm.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 "math" 9 "testing" 10 11 "github.com/jingcheng-WU/gonum/blas" 12 "github.com/jingcheng-WU/gonum/floats" 13 ) 14 15 type Dsymmer interface { 16 Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) 17 } 18 19 func DsymmTest(t *testing.T, blasser Dsymmer) { 20 for i, test := range []struct { 21 m int 22 n int 23 side blas.Side 24 ul blas.Uplo 25 a [][]float64 26 b [][]float64 27 c [][]float64 28 alpha float64 29 beta float64 30 ans [][]float64 31 }{ 32 { 33 side: blas.Left, 34 ul: blas.Upper, 35 m: 3, 36 n: 4, 37 a: [][]float64{ 38 {2, 3, 4}, 39 {0, 6, 7}, 40 {0, 0, 10}, 41 }, 42 b: [][]float64{ 43 {2, 3, 4, 8}, 44 {5, 6, 7, 15}, 45 {8, 9, 10, 20}, 46 }, 47 c: [][]float64{ 48 {8, 12, 2, 1}, 49 {9, 12, 9, 9}, 50 {12, 1, -1, 5}, 51 }, 52 alpha: 2, 53 beta: 3, 54 ans: [][]float64{ 55 {126, 156, 144, 285}, 56 {211, 252, 275, 535}, 57 {282, 291, 327, 689}, 58 }, 59 }, 60 { 61 side: blas.Left, 62 ul: blas.Upper, 63 m: 4, 64 n: 3, 65 a: [][]float64{ 66 {2, 3, 4, 8}, 67 {0, 6, 7, 9}, 68 {0, 0, 10, 10}, 69 {0, 0, 0, 11}, 70 }, 71 b: [][]float64{ 72 {2, 3, 4}, 73 {5, 6, 7}, 74 {8, 9, 10}, 75 {2, 1, 1}, 76 }, 77 c: [][]float64{ 78 {8, 12, 2}, 79 {9, 12, 9}, 80 {12, 1, -1}, 81 {1, 9, 5}, 82 }, 83 alpha: 2, 84 beta: 3, 85 ans: [][]float64{ 86 {158, 172, 160}, 87 {247, 270, 293}, 88 {322, 311, 347}, 89 {329, 385, 427}, 90 }, 91 }, 92 { 93 side: blas.Left, 94 ul: blas.Lower, 95 m: 3, 96 n: 4, 97 a: [][]float64{ 98 {2, 0, 0}, 99 {3, 6, 0}, 100 {4, 7, 10}, 101 }, 102 b: [][]float64{ 103 {2, 3, 4, 8}, 104 {5, 6, 7, 15}, 105 {8, 9, 10, 20}, 106 }, 107 c: [][]float64{ 108 {8, 12, 2, 1}, 109 {9, 12, 9, 9}, 110 {12, 1, -1, 5}, 111 }, 112 alpha: 2, 113 beta: 3, 114 ans: [][]float64{ 115 {126, 156, 144, 285}, 116 {211, 252, 275, 535}, 117 {282, 291, 327, 689}, 118 }, 119 }, 120 { 121 side: blas.Left, 122 ul: blas.Lower, 123 m: 4, 124 n: 3, 125 a: [][]float64{ 126 {2, 0, 0, 0}, 127 {3, 6, 0, 0}, 128 {4, 7, 10, 0}, 129 {8, 9, 10, 11}, 130 }, 131 b: [][]float64{ 132 {2, 3, 4}, 133 {5, 6, 7}, 134 {8, 9, 10}, 135 {2, 1, 1}, 136 }, 137 c: [][]float64{ 138 {8, 12, 2}, 139 {9, 12, 9}, 140 {12, 1, -1}, 141 {1, 9, 5}, 142 }, 143 alpha: 2, 144 beta: 3, 145 ans: [][]float64{ 146 {158, 172, 160}, 147 {247, 270, 293}, 148 {322, 311, 347}, 149 {329, 385, 427}, 150 }, 151 }, 152 { 153 side: blas.Right, 154 ul: blas.Upper, 155 m: 3, 156 n: 4, 157 a: [][]float64{ 158 {2, 0, 0, 0}, 159 {3, 6, 0, 0}, 160 {4, 7, 10, 0}, 161 {3, 4, 5, 6}, 162 }, 163 b: [][]float64{ 164 {2, 3, 4, 9}, 165 {5, 6, 7, -3}, 166 {8, 9, 10, -2}, 167 }, 168 c: [][]float64{ 169 {8, 12, 2, 10}, 170 {9, 12, 9, 10}, 171 {12, 1, -1, 10}, 172 }, 173 alpha: 2, 174 beta: 3, 175 ans: [][]float64{ 176 {32, 72, 86, 138}, 177 {47, 108, 167, -6}, 178 {68, 111, 197, 6}, 179 }, 180 }, 181 { 182 side: blas.Right, 183 ul: blas.Upper, 184 m: 4, 185 n: 3, 186 a: [][]float64{ 187 {2, 0, 0}, 188 {3, 6, 0}, 189 {4, 7, 10}, 190 }, 191 b: [][]float64{ 192 {2, 3, 4}, 193 {5, 6, 7}, 194 {8, 9, 10}, 195 {2, 1, 1}, 196 }, 197 c: [][]float64{ 198 {8, 12, 2}, 199 {9, 12, 9}, 200 {12, 1, -1}, 201 {1, 9, 5}, 202 }, 203 alpha: 2, 204 beta: 3, 205 ans: [][]float64{ 206 {32, 72, 86}, 207 {47, 108, 167}, 208 {68, 111, 197}, 209 {11, 39, 35}, 210 }, 211 }, 212 { 213 side: blas.Right, 214 ul: blas.Lower, 215 m: 3, 216 n: 4, 217 a: [][]float64{ 218 {2, 0, 0, 0}, 219 {3, 6, 0, 0}, 220 {4, 7, 10, 0}, 221 {3, 4, 5, 6}, 222 }, 223 b: [][]float64{ 224 {2, 3, 4, 2}, 225 {5, 6, 7, 1}, 226 {8, 9, 10, 1}, 227 }, 228 c: [][]float64{ 229 {8, 12, 2, 1}, 230 {9, 12, 9, 9}, 231 {12, 1, -1, 5}, 232 }, 233 alpha: 2, 234 beta: 3, 235 ans: [][]float64{ 236 {94, 156, 164, 103}, 237 {145, 244, 301, 187}, 238 {208, 307, 397, 247}, 239 }, 240 }, 241 { 242 side: blas.Right, 243 ul: blas.Lower, 244 m: 4, 245 n: 3, 246 a: [][]float64{ 247 {2, 0, 0}, 248 {3, 6, 0}, 249 {4, 7, 10}, 250 }, 251 b: [][]float64{ 252 {2, 3, 4}, 253 {5, 6, 7}, 254 {8, 9, 10}, 255 {2, 1, 1}, 256 }, 257 c: [][]float64{ 258 {8, 12, 2}, 259 {9, 12, 9}, 260 {12, 1, -1}, 261 {1, 9, 5}, 262 }, 263 alpha: 2, 264 beta: 3, 265 ans: [][]float64{ 266 {82, 140, 144}, 267 {139, 236, 291}, 268 {202, 299, 387}, 269 {25, 65, 65}, 270 }, 271 }, 272 273 { 274 side: blas.Left, 275 ul: blas.Upper, 276 m: 3, 277 n: 4, 278 a: [][]float64{ 279 {2, 3, 4}, 280 {0, 6, 7}, 281 {0, 0, 10}, 282 }, 283 b: [][]float64{ 284 {2, 3, 4, 8}, 285 {5, 6, 7, 15}, 286 {8, 9, 10, 20}, 287 }, 288 c: [][]float64{ 289 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 290 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 291 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 292 }, 293 alpha: 2, 294 ans: [][]float64{ 295 {102, 120, 138, 282}, 296 {184, 216, 248, 508}, 297 {246, 288, 330, 674}, 298 }, 299 }, 300 { 301 side: blas.Left, 302 ul: blas.Upper, 303 m: 4, 304 n: 3, 305 a: [][]float64{ 306 {2, 3, 4, 8}, 307 {0, 6, 7, 9}, 308 {0, 0, 10, 10}, 309 {0, 0, 0, 11}, 310 }, 311 b: [][]float64{ 312 {2, 3, 4}, 313 {5, 6, 7}, 314 {8, 9, 10}, 315 {2, 1, 1}, 316 }, 317 c: [][]float64{ 318 {math.NaN(), math.NaN(), math.NaN()}, 319 {math.NaN(), math.NaN(), math.NaN()}, 320 {math.NaN(), math.NaN(), math.NaN()}, 321 {math.NaN(), math.NaN(), math.NaN()}, 322 }, 323 alpha: 2, 324 ans: [][]float64{ 325 {134, 136, 154}, 326 {220, 234, 266}, 327 {286, 308, 350}, 328 {326, 358, 412}, 329 }, 330 }, 331 { 332 side: blas.Left, 333 ul: blas.Lower, 334 m: 3, 335 n: 4, 336 a: [][]float64{ 337 {2, 0, 0}, 338 {3, 6, 0}, 339 {4, 7, 10}, 340 }, 341 b: [][]float64{ 342 {2, 3, 4, 8}, 343 {5, 6, 7, 15}, 344 {8, 9, 10, 20}, 345 }, 346 c: [][]float64{ 347 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 348 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 349 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 350 }, 351 alpha: 2, 352 ans: [][]float64{ 353 {102, 120, 138, 282}, 354 {184, 216, 248, 508}, 355 {246, 288, 330, 674}, 356 }, 357 }, 358 { 359 side: blas.Left, 360 ul: blas.Lower, 361 m: 4, 362 n: 3, 363 a: [][]float64{ 364 {2, 0, 0, 0}, 365 {3, 6, 0, 0}, 366 {4, 7, 10, 0}, 367 {8, 9, 10, 11}, 368 }, 369 b: [][]float64{ 370 {2, 3, 4}, 371 {5, 6, 7}, 372 {8, 9, 10}, 373 {2, 1, 1}, 374 }, 375 c: [][]float64{ 376 {math.NaN(), math.NaN(), math.NaN()}, 377 {math.NaN(), math.NaN(), math.NaN()}, 378 {math.NaN(), math.NaN(), math.NaN()}, 379 {math.NaN(), math.NaN(), math.NaN()}, 380 }, 381 alpha: 2, 382 ans: [][]float64{ 383 {134, 136, 154}, 384 {220, 234, 266}, 385 {286, 308, 350}, 386 {326, 358, 412}, 387 }, 388 }, 389 { 390 side: blas.Right, 391 ul: blas.Upper, 392 m: 3, 393 n: 4, 394 a: [][]float64{ 395 {2, 0, 0, 0}, 396 {3, 6, 0, 0}, 397 {4, 7, 10, 0}, 398 {3, 4, 5, 6}, 399 }, 400 b: [][]float64{ 401 {2, 3, 4, 9}, 402 {5, 6, 7, -3}, 403 {8, 9, 10, -2}, 404 }, 405 c: [][]float64{ 406 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 407 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 408 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 409 }, 410 alpha: 2, 411 ans: [][]float64{ 412 {8, 36, 80, 108}, 413 {20, 72, 140, -36}, 414 {32, 108, 200, -24}, 415 }, 416 }, 417 { 418 side: blas.Right, 419 ul: blas.Upper, 420 m: 4, 421 n: 3, 422 a: [][]float64{ 423 {2, 0, 0}, 424 {3, 6, 0}, 425 {4, 7, 10}, 426 }, 427 b: [][]float64{ 428 {2, 3, 4}, 429 {5, 6, 7}, 430 {8, 9, 10}, 431 {2, 1, 1}, 432 }, 433 c: [][]float64{ 434 {math.NaN(), math.NaN(), math.NaN()}, 435 {math.NaN(), math.NaN(), math.NaN()}, 436 {math.NaN(), math.NaN(), math.NaN()}, 437 {math.NaN(), math.NaN(), math.NaN()}, 438 }, 439 alpha: 2, 440 ans: [][]float64{ 441 {8, 36, 80, 20}, 442 {72, 140, 32, 108}, 443 {200, 8, 12, 20}, 444 }, 445 }, 446 { 447 side: blas.Right, 448 ul: blas.Lower, 449 m: 3, 450 n: 4, 451 a: [][]float64{ 452 {2, 0, 0, 0}, 453 {3, 6, 0, 0}, 454 {4, 7, 10, 0}, 455 {3, 4, 5, 6}, 456 }, 457 b: [][]float64{ 458 {2, 3, 4, 2}, 459 {5, 6, 7, 1}, 460 {8, 9, 10, 1}, 461 }, 462 c: [][]float64{ 463 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 464 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 465 {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 466 }, 467 alpha: 2, 468 ans: [][]float64{ 469 {70, 120, 158, 100}, 470 {118, 208, 274, 160}, 471 {172, 304, 400, 232}, 472 }, 473 }, 474 { 475 side: blas.Right, 476 ul: blas.Lower, 477 m: 4, 478 n: 3, 479 a: [][]float64{ 480 {2, 0, 0}, 481 {3, 6, 0}, 482 {4, 7, 10}, 483 }, 484 b: [][]float64{ 485 {2, 3, 4}, 486 {5, 6, 7}, 487 {8, 9, 10}, 488 {2, 1, 1}, 489 }, 490 c: [][]float64{ 491 {math.NaN(), math.NaN(), math.NaN()}, 492 {math.NaN(), math.NaN(), math.NaN()}, 493 {math.NaN(), math.NaN(), math.NaN()}, 494 {math.NaN(), math.NaN(), math.NaN()}, 495 }, 496 alpha: 2, 497 ans: [][]float64{ 498 {58, 104, 138}, 499 {112, 200, 264}, 500 {166, 296, 390}, 501 {22, 38, 50}, 502 }, 503 }, 504 } { 505 aFlat := flatten(test.a) 506 bFlat := flatten(test.b) 507 cFlat := flatten(test.c) 508 ansFlat := flatten(test.ans) 509 blasser.Dsymm(test.side, test.ul, test.m, test.n, test.alpha, aFlat, len(test.a[0]), bFlat, test.n, test.beta, cFlat, test.n) 510 if !floats.EqualApprox(cFlat, ansFlat, 1e-14) { 511 t.Errorf("Case %v: Want %v, got %v.", i, ansFlat, cFlat) 512 } 513 } 514 }