github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/level1double.go (about) 1 // Copyright ©2015 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 "fmt" 9 "math" 10 "testing" 11 12 "github.com/jingcheng-WU/gonum/blas" 13 "github.com/jingcheng-WU/gonum/floats" 14 ) 15 16 type DoubleOneVectorCase struct { 17 Name string 18 X []float64 19 Incx int 20 N int 21 Panic bool 22 Dasum float64 23 Dnrm2 float64 24 Idamax int 25 DscalCases []DScalCase 26 } 27 28 type DScalCase struct { 29 Alpha float64 30 Ans []float64 31 Name string 32 } 33 34 var DoubleOneVectorCases = []DoubleOneVectorCase{ 35 { 36 Name: "AllPositive", 37 X: []float64{6, 5, 4, 2, 6}, 38 Incx: 1, 39 N: 5, 40 Panic: false, 41 Dasum: 23, 42 Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, 43 Idamax: 0, 44 DscalCases: []DScalCase{ 45 { 46 Alpha: 0, 47 Ans: []float64{0, 0, 0, 0, 0}, 48 }, 49 { 50 Alpha: 1, 51 Ans: []float64{6, 5, 4, 2, 6}, 52 }, 53 { 54 Alpha: -2, 55 Ans: []float64{-12, -10, -8, -4, -12}, 56 }, 57 }, 58 }, 59 { 60 Name: "LeadingZero", 61 X: []float64{0, 1}, 62 Incx: 1, 63 N: 2, 64 Panic: false, 65 Dasum: 1, 66 Dnrm2: 1, 67 Idamax: 1, 68 DscalCases: []DScalCase{ 69 { 70 Alpha: 0, 71 Ans: []float64{0, 0}, 72 }, 73 { 74 Alpha: 1, 75 Ans: []float64{0, 1}, 76 }, 77 { 78 Alpha: -2, 79 Ans: []float64{0, -2}, 80 }, 81 }, 82 }, 83 { 84 Name: "MaxInMiddle", 85 X: []float64{6, 5, 9, 0, 6}, 86 Incx: 1, 87 N: 5, 88 Panic: false, 89 Dasum: 26, 90 Dnrm2: 13.34166406412633371248943627250846646911846482744007727141318, 91 Idamax: 2, 92 DscalCases: []DScalCase{ 93 { 94 Alpha: -2, 95 Ans: []float64{-12, -10, -18, 0, -12}, 96 }, 97 }, 98 }, 99 { 100 Name: "MaxAtEnd", 101 X: []float64{6, 5, -9, 0, 10}, 102 Incx: 1, 103 N: 5, 104 Panic: false, 105 Dasum: 30, 106 Dnrm2: 15.55634918610404553681857596630667886426639062914642880494347, 107 Idamax: 4, 108 DscalCases: []DScalCase{ 109 { 110 Alpha: -2, 111 Ans: []float64{-12, -10, 18, 0, -20}, 112 }, 113 }, 114 }, 115 { 116 Name: "AllNegative", 117 X: []float64{-6, -5, -4, -2, -6}, 118 Incx: 1, 119 N: 5, 120 Panic: false, 121 Dasum: 23, 122 Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, 123 Idamax: 0, 124 DscalCases: []DScalCase{ 125 { 126 Alpha: -2, 127 Ans: []float64{12, 10, 8, 4, 12}, 128 }, 129 }, 130 }, 131 { 132 Name: "AllMixed", 133 X: []float64{-6, 5, 4, -2, -6}, 134 Incx: 1, 135 N: 5, 136 Panic: false, 137 Dasum: 23, 138 Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, 139 Idamax: 0, 140 DscalCases: []DScalCase{ 141 { 142 Alpha: -2, 143 Ans: []float64{12, -10, -8, 4, 12}, 144 }, 145 }, 146 }, 147 { 148 Name: "ZeroN", 149 X: []float64{-6, 5, 4, -2, -6}, 150 Incx: 1, 151 N: 0, 152 Panic: false, 153 Dasum: 0, 154 Dnrm2: 0, 155 Idamax: -1, 156 DscalCases: []DScalCase{ 157 { 158 Alpha: -2, 159 Ans: []float64{-6, 5, 4, -2, -6}, 160 }, 161 }, 162 }, 163 { 164 Name: "OneN", 165 X: []float64{-6, 5, 4, -2, -6}, 166 Incx: 1, 167 N: 1, 168 Panic: false, 169 Dasum: 6, 170 Dnrm2: 6, 171 Idamax: 0, 172 DscalCases: []DScalCase{ 173 { 174 Alpha: -2, 175 Ans: []float64{12, 5, 4, -2, -6}, 176 }, 177 }, 178 }, 179 { 180 Name: "PositiveExactInc", 181 X: []float64{-6, 5, 10, -2, -5}, 182 Incx: 2, 183 N: 3, 184 Panic: false, 185 Dasum: 21, 186 Dnrm2: 12.68857754044952038019377274608948979173952662752515253090272, 187 Idamax: 1, 188 DscalCases: []DScalCase{ 189 { 190 Alpha: -2, 191 Ans: []float64{12, 5, -20, -2, 10}, 192 }, 193 }, 194 }, 195 { 196 Name: "PositiveOffInc", 197 X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 198 Incx: 3, 199 N: 3, 200 Panic: false, 201 Dasum: 18, 202 Dnrm2: 11.83215956619923208513465658312323409683100246158868064575943, 203 Idamax: 2, 204 DscalCases: []DScalCase{ 205 { 206 Alpha: -2, 207 Ans: []float64{12, 5, 4, 4, -6, 8, -20, 11}, 208 }, 209 }, 210 }, 211 { 212 Name: "PositiveShortInc", 213 X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 214 Incx: 3, 215 N: 2, 216 Panic: false, 217 Dasum: 8, 218 Dnrm2: 6.324555320336758663997787088865437067439110278650433653715009, 219 Idamax: 0, 220 DscalCases: []DScalCase{ 221 { 222 Alpha: -2, 223 Ans: []float64{12, 5, 4, 4, -6, 8, 10, 11}, 224 }, 225 }, 226 }, 227 { 228 Name: "NegativeInc", 229 X: []float64{-6, 5, 4, -2, -6}, 230 Incx: -1, 231 N: 5, 232 Panic: false, 233 Dasum: 0, 234 Dnrm2: 0, 235 Idamax: -1, 236 DscalCases: []DScalCase{ 237 { 238 Alpha: -2, 239 Ans: []float64{-6, 5, 4, -2, -6}, 240 }, 241 }, 242 }, 243 { 244 Name: "NegativeExactInc", 245 X: []float64{-6, 5, 4, -2, -6}, 246 Incx: -2, 247 N: 3, 248 Panic: false, 249 Dasum: 0, 250 Dnrm2: 0, 251 Idamax: -1, 252 DscalCases: []DScalCase{ 253 { 254 Alpha: -2, 255 Ans: []float64{-6, 5, 4, -2, -6}, 256 }, 257 }, 258 }, 259 { 260 Name: "NegativeOffInc", 261 X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 262 Incx: -3, 263 N: 2, 264 Panic: false, 265 Dasum: 0, 266 Dnrm2: 0, 267 Idamax: -1, 268 DscalCases: []DScalCase{ 269 { 270 Alpha: -2, 271 Ans: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 272 }, 273 }, 274 }, 275 { 276 Name: "NegativeShortInc", 277 X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 278 Incx: -3, 279 N: 2, 280 Panic: false, 281 Dasum: 0, 282 Dnrm2: 0, 283 Idamax: -1, 284 DscalCases: []DScalCase{ 285 { 286 Alpha: -2, 287 Ans: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, 288 }, 289 }, 290 }, 291 { 292 Name: "NegativeN", 293 X: []float64{-6, 5, 4, -2, -6}, 294 Incx: 2, 295 N: -5, 296 Panic: true, 297 DscalCases: []DScalCase{ 298 { 299 Alpha: -2, 300 Ans: []float64{-6, 5, 4, -2, -6}, 301 }, 302 }, 303 }, 304 { 305 Name: "ZeroInc", 306 X: []float64{-6, 5, 4, -2, -6}, 307 Incx: 0, 308 N: 5, 309 Panic: true, 310 DscalCases: []DScalCase{ 311 { 312 Alpha: -2, 313 Ans: []float64{-6, 5, 4, -2, -6}, 314 }, 315 }, 316 }, 317 { 318 Name: "OutOfBounds", 319 X: []float64{-6, 5, 4, -2, -6}, 320 Incx: 2, 321 N: 6, 322 Panic: true, 323 DscalCases: []DScalCase{ 324 { 325 Alpha: -2, 326 Ans: []float64{-6, 5, 4, -2, -6}, 327 }, 328 }, 329 }, 330 { 331 Name: "NegativeOutOfBounds", 332 X: []float64{-6, 5, 4, -2, -6}, 333 Incx: -2, 334 N: 6, 335 Panic: false, 336 Dasum: 0, 337 Dnrm2: 0, 338 Idamax: -1, 339 DscalCases: []DScalCase{ 340 { 341 Alpha: -2, 342 Ans: []float64{-6, 5, 4, -2, -6}, 343 }, 344 }, 345 }, 346 { 347 Name: "NaN", 348 X: []float64{math.NaN(), 2.0}, 349 Incx: 1, 350 N: 2, 351 Panic: false, 352 Dasum: math.NaN(), 353 Dnrm2: math.NaN(), 354 Idamax: 0, 355 DscalCases: []DScalCase{ 356 { 357 Alpha: -2, 358 Ans: []float64{math.NaN(), -4.0}, 359 }, 360 { 361 Alpha: 0, 362 Ans: []float64{0, 0}, 363 }, 364 }, 365 }, 366 { 367 Name: "NaNInc", 368 X: []float64{math.NaN(), math.NaN(), 2.0}, 369 Incx: 2, 370 N: 2, 371 Panic: false, 372 Dasum: math.NaN(), 373 Dnrm2: math.NaN(), 374 Idamax: 0, 375 DscalCases: []DScalCase{ 376 { 377 Alpha: -2, 378 Ans: []float64{math.NaN(), math.NaN(), -4.0}, 379 }, 380 { 381 Alpha: 0, 382 Ans: []float64{0, math.NaN(), 0}, 383 }, 384 }, 385 }, 386 { 387 Name: "Empty", 388 X: []float64{}, 389 Incx: 1, 390 N: 0, 391 Panic: false, 392 Dasum: 0, 393 Dnrm2: 0, 394 Idamax: -1, 395 DscalCases: []DScalCase{ 396 { 397 Alpha: -2, 398 Ans: []float64{}, 399 }, 400 { 401 Alpha: 0, 402 Ans: []float64{}, 403 }, 404 }, 405 }, 406 { 407 Name: "EmptyZeroInc", 408 X: []float64{}, 409 Incx: 0, 410 N: 0, 411 Panic: true, 412 Dasum: 0, 413 Dnrm2: 0, 414 Idamax: -1, 415 DscalCases: []DScalCase{ 416 { 417 Alpha: -2, 418 Ans: []float64{}, 419 }, 420 { 421 Alpha: 0, 422 Ans: []float64{}, 423 }, 424 }, 425 }, 426 { 427 Name: "EmptyReverse", 428 X: []float64{}, 429 Incx: -1, 430 N: 0, 431 Panic: false, 432 Dasum: 0, 433 Dnrm2: 0, 434 Idamax: -1, 435 DscalCases: []DScalCase{ 436 { 437 Alpha: -2, 438 Ans: []float64{}, 439 }, 440 { 441 Alpha: 0, 442 Ans: []float64{}, 443 }, 444 }, 445 }, 446 { 447 Name: "MultiInf", 448 X: []float64{5, math.Inf(1), math.Inf(-1), 8, 9}, 449 Incx: 1, 450 N: 5, 451 Panic: false, 452 Dasum: math.Inf(1), 453 Dnrm2: math.Inf(1), 454 Idamax: 1, 455 DscalCases: []DScalCase{ 456 { 457 Alpha: -2, 458 Ans: []float64{-10, math.Inf(-1), math.Inf(1), -16, -18}, 459 }, 460 { 461 Alpha: 0, 462 Ans: []float64{0, 0, 0, 0, 0}, 463 }, 464 }, 465 }, 466 { 467 Name: "NaNInf", 468 X: []float64{5, math.NaN(), math.Inf(-1), 8, 9}, 469 Incx: 1, 470 N: 5, 471 Panic: false, 472 Dasum: math.NaN(), 473 Dnrm2: math.NaN(), 474 Idamax: 2, 475 DscalCases: []DScalCase{ 476 { 477 Alpha: -2, 478 Ans: []float64{-10, math.NaN(), math.Inf(1), -16, -18}, 479 }, 480 { 481 Alpha: 0, 482 Ans: []float64{0, 0, 0, 0, 0}, 483 }, 484 }, 485 }, 486 { 487 Name: "InfNaN", 488 X: []float64{5, math.Inf(1), math.NaN(), 8, 9}, 489 Incx: 1, 490 N: 5, 491 Panic: false, 492 Dasum: math.NaN(), 493 Dnrm2: math.NaN(), 494 Idamax: 1, 495 DscalCases: []DScalCase{ 496 { 497 Alpha: -2, 498 Ans: []float64{-10, math.Inf(-1), math.NaN(), -16, -18}, 499 }, 500 { 501 Alpha: 0, 502 Ans: []float64{0, 0, 0, 0, 0}, 503 }, 504 }, 505 }, 506 } 507 508 type DoubleTwoVectorCase struct { 509 Name string 510 X []float64 511 Y []float64 512 XTmp []float64 513 YTmp []float64 514 Incx int 515 Incy int 516 N int 517 Panic bool 518 // For Daxpy 519 DaxpyCases []DaxpyCase 520 DdotAns float64 521 DswapAns DTwoVecAnswer 522 DcopyAns DTwoVecAnswer 523 DrotCases []DrotCase 524 DrotmCases []DrotmCase 525 } 526 527 type DaxpyCase struct { 528 Alpha float64 529 Ans []float64 530 } 531 532 type DrotCase struct { 533 C float64 534 S float64 535 XAns []float64 536 YAns []float64 537 } 538 539 type DrotmCase struct { 540 P blas.DrotmParams 541 XAns []float64 542 YAns []float64 543 Name string 544 } 545 546 type DTwoVecAnswer struct { 547 X []float64 548 Y []float64 549 } 550 551 var DoubleTwoVectorCases = []DoubleTwoVectorCase{ 552 { 553 Name: "UnitaryInc", 554 X: []float64{10, 15, -6, 3, 14, 7}, 555 Y: []float64{8, -2, 4, 7, 6, -3}, 556 XTmp: []float64{0, 0, 0, 0, 0, 0}, 557 YTmp: []float64{0, 0, 0, 0, 0, 0}, 558 Incx: 1, 559 Incy: 1, 560 N: 6, 561 Panic: false, 562 DaxpyCases: []DaxpyCase{ 563 { 564 Alpha: 1, 565 Ans: []float64{18, 13, -2, 10, 20, 4}, 566 }, 567 { 568 Alpha: 2, 569 Ans: []float64{28, 28, -8, 13, 34, 11}, 570 }, 571 { 572 Alpha: -3, 573 Ans: []float64{-22, -47, 22, -2, -36, -24}, 574 }, 575 { 576 Alpha: 0, 577 Ans: []float64{8, -2, 4, 7, 6, -3}, 578 }, 579 }, 580 DdotAns: 110, 581 DswapAns: DTwoVecAnswer{ 582 X: []float64{8, -2, 4, 7, 6, -3}, 583 Y: []float64{10, 15, -6, 3, 14, 7}, 584 }, 585 DcopyAns: DTwoVecAnswer{ 586 X: []float64{10, 15, -6, 3, 14, 7}, 587 Y: []float64{10, 15, -6, 3, 14, 7}, 588 }, 589 DrotCases: []DrotCase{ 590 { 591 C: math.Cos(0), 592 S: math.Sin(0), 593 XAns: []float64{10, 15, -6, 3, 14, 7}, 594 YAns: []float64{8, -2, 4, 7, 6, -3}, 595 }, 596 { 597 C: math.Cos(25 * math.Pi / 180), 598 S: math.Sin(25 * math.Pi / 180), 599 XAns: []float64{12.444023964292095, 12.749380282068351, -3.7473736752571014, 5.677251193294846, 15.224018588957296, 5.076299724034451}, 600 YAns: []float64{3.024279678886205, -8.151889500183792, 6.160940718590796, 5.076299724034451, -0.4788089421498931, -5.677251193294846}, 601 }, 602 { 603 C: math.Cos(0.5 * math.Pi), 604 S: math.Sin(0.5 * math.Pi), 605 XAns: []float64{8, -2, 4, 7, 6, -3}, 606 YAns: []float64{-10, -15, 6, -3, -14, -7}, 607 }, 608 { 609 C: math.Cos(math.Pi), 610 S: math.Sin(math.Pi), 611 XAns: []float64{-10, -15, 6, -3, -14, -7}, 612 YAns: []float64{-8, 2, -4, -7, -6, 3}, 613 }, 614 }, 615 DrotmCases: []DrotmCase{ 616 { 617 P: blas.DrotmParams{ 618 Flag: blas.Identity, 619 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 620 }, 621 XAns: []float64{10, 15, -6, 3, 14, 7}, 622 YAns: []float64{8, -2, 4, 7, 6, -3}, 623 Name: "Neg2Flag", 624 }, 625 { 626 P: blas.DrotmParams{ 627 Flag: blas.Rescaling, 628 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 629 }, 630 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, 631 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, 632 Name: "Neg1Flag", 633 }, 634 { 635 P: blas.DrotmParams{ 636 Flag: blas.OffDiagonal, 637 H: [4]float64{1, 0.1, -0.1, 1}, 638 }, 639 XAns: []float64{9.2, 15.2, -6.4, 2.3, 13.4, 7.3}, 640 YAns: []float64{9, -0.5, 3.4, 7.3, 7.4, -2.3}, 641 Name: "ZeroFlag", 642 }, 643 { 644 P: blas.DrotmParams{ 645 Flag: blas.Diagonal, 646 H: [4]float64{0.5, -1, 1, 0.7}, 647 }, 648 XAns: []float64{13, 5.5, 1, 8.5, 13, 0.5}, 649 YAns: []float64{-4.4, -16.4, 8.8, 1.9, -9.8, -9.1}, 650 Name: "OneFlag", 651 }, 652 }, 653 }, 654 { 655 Name: "UnitaryIncLong", 656 X: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, 657 Y: []float64{8, -2, 4, 7, 6, -3, 7, -6}, 658 XTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0}, 659 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 660 Incx: 1, 661 Incy: 1, 662 N: 6, 663 Panic: false, 664 DaxpyCases: []DaxpyCase{ 665 { 666 Alpha: 1, 667 Ans: []float64{18, 13, -2, 10, 20, 4, 7, -6}, 668 }, 669 { 670 Alpha: 2, 671 Ans: []float64{28, 28, -8, 13, 34, 11, 7, -6}, 672 }, 673 { 674 Alpha: -3, 675 Ans: []float64{-22, -47, 22, -2, -36, -24, 7, -6}, 676 }, 677 { 678 Alpha: 0, 679 Ans: []float64{8, -2, 4, 7, 6, -3, 7, -6}, 680 }, 681 }, 682 DdotAns: 110, 683 DswapAns: DTwoVecAnswer{ 684 X: []float64{8, -2, 4, 7, 6, -3, 8, -9, 10}, 685 Y: []float64{10, 15, -6, 3, 14, 7, 7, -6}, 686 }, 687 DcopyAns: DTwoVecAnswer{ 688 X: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, 689 Y: []float64{10, 15, -6, 3, 14, 7, 7, -6}, 690 }, 691 DrotCases: []DrotCase{ 692 { 693 C: math.Cos(0), 694 S: math.Sin(0), 695 XAns: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, 696 YAns: []float64{8, -2, 4, 7, 6, -3, 7, -6}, 697 }, 698 { 699 C: math.Cos(25 * math.Pi / 180), 700 S: math.Sin(25 * math.Pi / 180), 701 XAns: []float64{12.444023964292095, 12.749380282068351, -3.7473736752571014, 5.677251193294846, 15.224018588957296, 5.076299724034451, 8, -9, 10}, 702 YAns: []float64{3.024279678886205, -8.151889500183792, 6.160940718590796, 5.076299724034451, -0.4788089421498931, -5.677251193294846, 7, -6}, 703 }, 704 { 705 C: math.Cos(0.5 * math.Pi), 706 S: math.Sin(0.5 * math.Pi), 707 XAns: []float64{8, -2, 4, 7, 6, -3, 8, -9, 10}, 708 YAns: []float64{-10, -15, 6, -3, -14, -7, 7, -6}, 709 }, 710 { 711 C: math.Cos(math.Pi), 712 S: math.Sin(math.Pi), 713 XAns: []float64{-10, -15, 6, -3, -14, -7, 8, -9, 10}, 714 YAns: []float64{-8, 2, -4, -7, -6, 3, 7, -6}, 715 }, 716 }, 717 DrotmCases: []DrotmCase{ 718 { 719 P: blas.DrotmParams{ 720 Flag: blas.Identity, 721 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 722 }, 723 XAns: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, 724 YAns: []float64{8, -2, 4, 7, 6, -3, 7, -6}, 725 Name: "Neg2Flag", 726 }, 727 { 728 P: blas.DrotmParams{ 729 Flag: blas.Rescaling, 730 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 731 }, 732 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6, 8, -9, 10}, 733 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8, 7, -6}, 734 Name: "Neg1Flag", 735 }, 736 { 737 P: blas.DrotmParams{ 738 Flag: blas.OffDiagonal, 739 H: [4]float64{1, 0.1, -0.1, 1}, 740 }, 741 XAns: []float64{9.2, 15.2, -6.4, 2.3, 13.4, 7.3, 8, -9, 10}, 742 YAns: []float64{9, -0.5, 3.4, 7.3, 7.4, -2.3, 7, -6}, 743 Name: "ZeroFlag", 744 }, 745 { 746 P: blas.DrotmParams{ 747 Flag: blas.Diagonal, 748 H: [4]float64{0.5, -1, 1, 0.7}, 749 }, 750 XAns: []float64{13, 5.5, 1, 8.5, 13, 0.5, 8, -9, 10}, 751 YAns: []float64{-4.4, -16.4, 8.8, 1.9, -9.8, -9.1, 7, -6}, 752 Name: "OneFlag", 753 }, 754 }, 755 }, 756 { 757 Name: "PositiveInc", 758 X: []float64{10, 15, -6, 3, 14, 7}, 759 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 760 XTmp: []float64{0, 0, 0, 0, 0, 0}, 761 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 762 Incx: 2, 763 Incy: 3, 764 N: 3, 765 Panic: false, 766 DaxpyCases: []DaxpyCase{ 767 { 768 Alpha: 2, 769 Ans: []float64{28, -2, 4, -5, 6, -3, 24, 10}, 770 }, 771 }, 772 DdotAns: -18, 773 DswapAns: DTwoVecAnswer{ 774 X: []float64{8, 15, 7, 3, -4, 7}, 775 Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, 776 }, 777 DcopyAns: DTwoVecAnswer{ 778 X: []float64{10, 15, -6, 3, 14, 7}, 779 Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, 780 }, 781 DrotCases: []DrotCase{ 782 { 783 C: math.Cos(25 * math.Pi / 180), 784 S: math.Sin(25 * math.Pi / 180), 785 XAns: []float64{12.444023964292095, 15, -2.479518890035003, 3, 10.997835971550302, 7}, 786 YAns: []float64{3.024279678886205, -2, 4, 8.879864079700745, 6, -3, -9.541886812516392, 10}, 787 }, 788 }, 789 DrotmCases: []DrotmCase{ 790 { 791 P: blas.DrotmParams{ 792 Flag: blas.Rescaling, 793 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 794 }, 795 XAns: []float64{8.2, 15, -6.1, 3, 13, 7}, 796 YAns: []float64{5, -2, 4, 2.9, 6, -3, -0.6, 10}, 797 }, 798 { 799 P: blas.DrotmParams{ 800 Flag: blas.OffDiagonal, 801 H: [4]float64{1, 0.1, -0.1, 1}, 802 }, 803 XAns: []float64{9.2, 15, -6.7, 3, 14.4, 7}, 804 YAns: []float64{9, -2, 4, 6.4, 6, -3, -2.6, 10}, 805 }, 806 { 807 P: blas.DrotmParams{ 808 Flag: blas.Diagonal, 809 H: [4]float64{0.5, -1, 1, 0.7}, 810 }, 811 XAns: []float64{13, 15, 4, 3, 3, 7}, 812 YAns: []float64{-4.4, -2, 4, 10.9, 6, -3, -16.8, 10}, 813 }, 814 }, 815 }, 816 { 817 Name: "NegativeInc", 818 X: []float64{10, 15, -6, 3, 14, 7}, 819 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 820 XTmp: []float64{0, 0, 0, 0, 0, 0}, 821 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 822 Incx: -2, 823 Incy: -3, 824 N: 3, 825 Panic: false, 826 DaxpyCases: []DaxpyCase{ 827 { 828 Alpha: 2, 829 Ans: []float64{28, -2, 4, -5, 6, -3, 24, 10}, 830 }, 831 }, 832 DdotAns: -18, 833 DswapAns: DTwoVecAnswer{ 834 X: []float64{8, 15, 7, 3, -4, 7}, 835 Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, 836 }, 837 DcopyAns: DTwoVecAnswer{ 838 X: []float64{10, 15, -6, 3, 14, 7}, 839 Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, 840 }, 841 DrotCases: []DrotCase{ 842 { 843 C: math.Cos(25 * math.Pi / 180), 844 S: math.Sin(25 * math.Pi / 180), 845 XAns: []float64{12.444023964292095, 15, -2.479518890035003, 3, 10.997835971550302, 7}, 846 YAns: []float64{3.024279678886205, -2, 4, 8.879864079700745, 6, -3, -9.541886812516392, 10}, 847 }, 848 }, 849 DrotmCases: []DrotmCase{ 850 { 851 P: blas.DrotmParams{ 852 Flag: blas.Rescaling, 853 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 854 }, 855 XAns: []float64{8.2, 15, -6.1, 3, 13, 7}, 856 YAns: []float64{5, -2, 4, 2.9, 6, -3, -0.6, 10}, 857 }, 858 { 859 P: blas.DrotmParams{ 860 Flag: blas.OffDiagonal, 861 H: [4]float64{1, 0.1, -0.1, 1}, 862 }, 863 XAns: []float64{9.2, 15, -6.7, 3, 14.4, 7}, 864 YAns: []float64{9, -2, 4, 6.4, 6, -3, -2.6, 10}, 865 }, 866 { 867 P: blas.DrotmParams{ 868 Flag: blas.Diagonal, 869 H: [4]float64{0.5, -1, 1, 0.7}, 870 }, 871 XAns: []float64{13, 15, 4, 3, 3, 7}, 872 YAns: []float64{-4.4, -2, 4, 10.9, 6, -3, -16.8, 10}, 873 }, 874 }, 875 }, 876 { 877 Name: "MixedInc1", 878 X: []float64{10, 15, -6, 3, 14, 7}, 879 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 880 XTmp: []float64{0, 0, 0, 0, 0, 0}, 881 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 882 Incx: 2, 883 Incy: -3, 884 N: 3, 885 Panic: false, 886 DaxpyCases: []DaxpyCase{ 887 { 888 Alpha: 2, 889 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 890 }, 891 }, 892 DdotAns: 30, 893 DswapAns: DTwoVecAnswer{ 894 X: []float64{-4, 15, 7, 3, 8, 7}, 895 Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, 896 }, 897 DcopyAns: DTwoVecAnswer{ 898 X: []float64{10, 15, -6, 3, 14, 7}, 899 Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, 900 }, 901 DrotCases: []DrotCase{ 902 { 903 C: math.Cos(25 * math.Pi / 180), 904 S: math.Sin(25 * math.Pi / 180), 905 XAns: []float64{7.372604823403701, 15, -2.479518890035003, 3, 16.069255112438693, 7}, 906 YAns: []float64{1.333806631923407, -2, 4, 8.879864079700745, 6, -3, -7.851413765553595, 10}, 907 }, 908 }, 909 DrotmCases: []DrotmCase{ 910 { 911 P: blas.DrotmParams{ 912 Flag: blas.Rescaling, 913 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 914 }, 915 XAns: []float64{9.4, 15, -6.1, 3, 11.8, 7}, 916 YAns: []float64{5.4, -2, 4, 2.9, 6, -3, -1, 10}, 917 }, 918 { 919 P: blas.DrotmParams{ 920 Flag: blas.OffDiagonal, 921 H: [4]float64{1, 0.1, -0.1, 1}, 922 }, 923 XAns: []float64{10.4, 15, -6.7, 3, 13.2, 7}, 924 YAns: []float64{9.4, -2, 4, 6.4, 6, -3, -3, 10}, 925 }, 926 { 927 P: blas.DrotmParams{ 928 Flag: blas.Diagonal, 929 H: [4]float64{0.5, -1, 1, 0.7}, 930 }, 931 XAns: []float64{1, 15, 4, 3, 15, 7}, 932 YAns: []float64{-8.4, -2, 4, 10.9, 6, -3, -12.8, 10}, 933 }, 934 }, 935 }, 936 { 937 Name: "MixedInc2", 938 X: []float64{10, 15, -6, 3, 14, 7}, 939 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 940 XTmp: []float64{0, 0, 0, 0, 0, 0}, 941 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 942 Incx: -2, 943 Incy: 3, 944 N: 3, 945 Panic: false, 946 DaxpyCases: []DaxpyCase{ 947 { 948 Alpha: 2, 949 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 950 }, 951 }, 952 DdotAns: 30, 953 DswapAns: DTwoVecAnswer{ 954 X: []float64{-4, 15, 7, 3, 8, 7}, 955 Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, 956 }, 957 DcopyAns: DTwoVecAnswer{ 958 X: []float64{10, 15, -6, 3, 14, 7}, 959 Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, 960 }, 961 DrotCases: []DrotCase{ 962 { 963 C: math.Cos(25 * math.Pi / 180), 964 S: math.Sin(25 * math.Pi / 180), 965 XAns: []float64{7.372604823403701, 15, -2.479518890035003, 3, 16.069255112438693, 7}, 966 YAns: []float64{1.333806631923407, -2, 4, 8.879864079700745, 6, -3, -7.851413765553595, 10}, 967 }, 968 }, 969 DrotmCases: []DrotmCase{ 970 { 971 P: blas.DrotmParams{ 972 Flag: blas.Rescaling, 973 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 974 }, 975 XAns: []float64{9.4, 15, -6.1, 3, 11.8, 7}, 976 YAns: []float64{5.4, -2, 4, 2.9, 6, -3, -1, 10}, 977 }, 978 { 979 P: blas.DrotmParams{ 980 Flag: blas.OffDiagonal, 981 H: [4]float64{1, 0.1, -0.1, 1}, 982 }, 983 XAns: []float64{10.4, 15, -6.7, 3, 13.2, 7}, 984 YAns: []float64{9.4, -2, 4, 6.4, 6, -3, -3, 10}, 985 }, 986 { 987 P: blas.DrotmParams{ 988 Flag: blas.Diagonal, 989 H: [4]float64{0.5, -1, 1, 0.7}, 990 }, 991 XAns: []float64{1, 15, 4, 3, 15, 7}, 992 YAns: []float64{-8.4, -2, 4, 10.9, 6, -3, -12.8, 10}, 993 }, 994 }, 995 }, 996 { 997 Name: "ZeroN", 998 X: []float64{10, 15, -6, 3, 14, 7}, 999 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1000 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1001 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1002 Incx: -2, 1003 Incy: 3, 1004 N: 0, 1005 Panic: false, 1006 DaxpyCases: []DaxpyCase{ 1007 { 1008 Alpha: 2, 1009 Ans: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1010 }, 1011 }, 1012 DswapAns: DTwoVecAnswer{ 1013 X: []float64{10, 15, -6, 3, 14, 7}, 1014 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1015 }, 1016 DcopyAns: DTwoVecAnswer{ 1017 X: []float64{10, 15, -6, 3, 14, 7}, 1018 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1019 }, 1020 DrotCases: []DrotCase{ 1021 { 1022 C: math.Cos(25 * math.Pi / 180), 1023 S: math.Sin(25 * math.Pi / 180), 1024 XAns: []float64{10, 15, -6, 3, 14, 7}, 1025 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1026 }, 1027 }, 1028 DrotmCases: []DrotmCase{ 1029 { 1030 P: blas.DrotmParams{ 1031 Flag: blas.Rescaling, 1032 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1033 }, 1034 XAns: []float64{10, 15, -6, 3, 14, 7}, 1035 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1036 }, 1037 }, 1038 }, 1039 { 1040 Name: "NegativeN", 1041 X: []float64{10, 15, -6, 3, 14, 7}, 1042 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1043 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1044 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1045 Incx: -2, 1046 Incy: 3, 1047 N: -3, 1048 Panic: true, 1049 DaxpyCases: []DaxpyCase{ 1050 { 1051 Alpha: 2, 1052 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 1053 }, 1054 }, 1055 DrotCases: []DrotCase{ 1056 { 1057 C: math.Cos(25 * math.Pi / 180), 1058 S: math.Sin(25 * math.Pi / 180), 1059 XAns: []float64{10, 15, -6, 3, 14, 7}, 1060 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1061 }, 1062 }, 1063 DrotmCases: []DrotmCase{ 1064 { 1065 P: blas.DrotmParams{ 1066 Flag: blas.Rescaling, 1067 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1068 }, 1069 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, 1070 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, 1071 }, 1072 }, 1073 }, 1074 { 1075 Name: "ZeroIncX", 1076 X: []float64{10, 15, -6, 3, 14, 7}, 1077 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1078 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1079 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1080 Incx: 0, 1081 Incy: 3, 1082 N: 2, 1083 Panic: true, 1084 DaxpyCases: []DaxpyCase{ 1085 { 1086 Alpha: 2, 1087 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 1088 }, 1089 }, 1090 DrotCases: []DrotCase{ 1091 { 1092 C: math.Cos(25 * math.Pi / 180), 1093 S: math.Sin(25 * math.Pi / 180), 1094 XAns: []float64{10, 15, -6, 3, 14, 7}, 1095 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1096 }, 1097 }, 1098 DrotmCases: []DrotmCase{ 1099 { 1100 P: blas.DrotmParams{ 1101 Flag: blas.Rescaling, 1102 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1103 }, 1104 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, 1105 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, 1106 }, 1107 }, 1108 }, 1109 { 1110 Name: "ZeroIncY", 1111 X: []float64{10, 15, -6, 3, 14, 7}, 1112 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1113 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1114 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1115 Incx: 1, 1116 Incy: 0, 1117 N: 2, 1118 Panic: true, 1119 DaxpyCases: []DaxpyCase{ 1120 { 1121 Alpha: 2, 1122 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 1123 }, 1124 }, 1125 DrotCases: []DrotCase{ 1126 { 1127 C: math.Cos(25 * math.Pi / 180), 1128 S: math.Sin(25 * math.Pi / 180), 1129 XAns: []float64{10, 15, -6, 3, 14, 7}, 1130 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1131 }, 1132 }, 1133 DrotmCases: []DrotmCase{ 1134 { 1135 P: blas.DrotmParams{ 1136 Flag: blas.Rescaling, 1137 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1138 }, 1139 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, 1140 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, 1141 }, 1142 }, 1143 }, 1144 { 1145 Name: "OutOfBoundsX", 1146 X: []float64{10, 15, -6, 3, 14, 7}, 1147 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1148 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1149 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1150 Incx: 8, 1151 Incy: 2, 1152 N: 2, 1153 Panic: true, 1154 DaxpyCases: []DaxpyCase{ 1155 { 1156 Alpha: 2, 1157 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 1158 }, 1159 }, 1160 DrotCases: []DrotCase{ 1161 { 1162 C: math.Cos(25 * math.Pi / 180), 1163 S: math.Sin(25 * math.Pi / 180), 1164 XAns: []float64{10, 15, -6, 3, 14, 7}, 1165 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1166 }, 1167 }, 1168 DrotmCases: []DrotmCase{ 1169 { 1170 P: blas.DrotmParams{ 1171 Flag: blas.Rescaling, 1172 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1173 }, 1174 XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, 1175 YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, 1176 }, 1177 }, 1178 }, 1179 { 1180 Name: "OutOfBoundsY", 1181 X: []float64{10, 15, -6, 3, 14, 7}, 1182 Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1183 XTmp: []float64{0, 0, 0, 0, 0, 0}, 1184 YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, 1185 Incx: 2, 1186 Incy: 8, 1187 N: 2, 1188 Panic: true, 1189 DaxpyCases: []DaxpyCase{ 1190 { 1191 Alpha: 2, 1192 Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, 1193 }, 1194 }, 1195 DrotCases: []DrotCase{ 1196 { 1197 C: math.Cos(25 * math.Pi / 180), 1198 S: math.Sin(25 * math.Pi / 180), 1199 XAns: []float64{10, 15, -6, 3, 14, 7}, 1200 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1201 }, 1202 }, 1203 DrotmCases: []DrotmCase{ 1204 { 1205 P: blas.DrotmParams{ 1206 Flag: blas.Rescaling, 1207 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1208 }, 1209 XAns: []float64{10, 15, -6, 3, 14, 7}, 1210 YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, 1211 }, 1212 }, 1213 }, 1214 { 1215 Name: "Empty", 1216 X: []float64{}, 1217 Y: []float64{}, 1218 Incx: 1, 1219 Incy: 1, 1220 N: 0, 1221 Panic: false, 1222 DaxpyCases: []DaxpyCase{ 1223 { 1224 Alpha: 2, 1225 Ans: []float64{}, 1226 }, 1227 }, 1228 DrotCases: []DrotCase{ 1229 { 1230 C: math.Cos(25 * math.Pi / 180), 1231 S: math.Sin(25 * math.Pi / 180), 1232 XAns: []float64{}, 1233 YAns: []float64{}, 1234 }, 1235 }, 1236 DrotmCases: []DrotmCase{ 1237 { 1238 P: blas.DrotmParams{ 1239 Flag: blas.Rescaling, 1240 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1241 }, 1242 XAns: []float64{}, 1243 YAns: []float64{}, 1244 }, 1245 }, 1246 }, 1247 { 1248 Name: "EmptyZeroIncX", 1249 X: []float64{}, 1250 Y: []float64{}, 1251 Incx: 0, 1252 Incy: 1, 1253 N: 0, 1254 Panic: true, 1255 DaxpyCases: []DaxpyCase{ 1256 { 1257 Alpha: 2, 1258 Ans: []float64{}, 1259 }, 1260 }, 1261 DrotCases: []DrotCase{ 1262 { 1263 C: math.Cos(25 * math.Pi / 180), 1264 S: math.Sin(25 * math.Pi / 180), 1265 XAns: []float64{}, 1266 YAns: []float64{}, 1267 }, 1268 }, 1269 DrotmCases: []DrotmCase{ 1270 { 1271 P: blas.DrotmParams{ 1272 Flag: blas.Rescaling, 1273 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1274 }, 1275 XAns: []float64{}, 1276 YAns: []float64{}, 1277 }, 1278 }, 1279 }, 1280 { 1281 Name: "EmptyZeroIncY", 1282 X: []float64{}, 1283 Y: []float64{}, 1284 Incx: 1, 1285 Incy: 0, 1286 N: 0, 1287 Panic: true, 1288 DaxpyCases: []DaxpyCase{ 1289 { 1290 Alpha: 2, 1291 Ans: []float64{}, 1292 }, 1293 }, 1294 DrotCases: []DrotCase{ 1295 { 1296 C: math.Cos(25 * math.Pi / 180), 1297 S: math.Sin(25 * math.Pi / 180), 1298 XAns: []float64{}, 1299 YAns: []float64{}, 1300 }, 1301 }, 1302 DrotmCases: []DrotmCase{ 1303 { 1304 P: blas.DrotmParams{ 1305 Flag: blas.Rescaling, 1306 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1307 }, 1308 XAns: []float64{}, 1309 YAns: []float64{}, 1310 }, 1311 }, 1312 }, 1313 { 1314 Name: "EmptyReverse", 1315 X: []float64{}, 1316 Y: []float64{}, 1317 Incx: -1, 1318 Incy: -1, 1319 N: 0, 1320 Panic: false, 1321 DaxpyCases: []DaxpyCase{ 1322 { 1323 Alpha: 2, 1324 Ans: []float64{}, 1325 }, 1326 }, 1327 DrotCases: []DrotCase{ 1328 { 1329 C: math.Cos(25 * math.Pi / 180), 1330 S: math.Sin(25 * math.Pi / 180), 1331 XAns: []float64{}, 1332 YAns: []float64{}, 1333 }, 1334 }, 1335 DrotmCases: []DrotmCase{ 1336 { 1337 P: blas.DrotmParams{ 1338 Flag: blas.Rescaling, 1339 H: [4]float64{0.9, 0.1, -0.1, 0.5}, 1340 }, 1341 XAns: []float64{}, 1342 YAns: []float64{}, 1343 }, 1344 }, 1345 }, 1346 } 1347 1348 type Ddotter interface { 1349 Ddot(n int, x []float64, incX int, y []float64, incY int) float64 1350 } 1351 1352 func DdotTest(t *testing.T, d Ddotter) { 1353 ddot := d.Ddot 1354 for _, c := range DoubleTwoVectorCases { 1355 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 1356 if c.Panic { 1357 f := func() { ddot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } 1358 testpanics(f, c.Name, t) 1359 continue 1360 } 1361 dot := ddot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) 1362 if !dTolEqual(dot, c.DdotAns) { 1363 t.Errorf("ddot: mismatch %v: expected %v, found %v", c.Name, c.DdotAns, dot) 1364 } 1365 } 1366 1367 // check it works for 16-byte unaligned slices 1368 x := []float64{1, 1, 1, 1, 1} 1369 if n := ddot(4, x[:4], 1, x[1:], 1); n != 4 { 1370 t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 4, n) 1371 } 1372 if n := ddot(2, x[:4], 2, x[1:], 2); n != 2 { 1373 t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 2, n) 1374 } 1375 if n := ddot(2, x[:4], 3, x[1:], 3); n != 2 { 1376 t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 2, n) 1377 } 1378 } 1379 1380 type Dnrm2er interface { 1381 Dnrm2(n int, x []float64, incX int) float64 1382 } 1383 1384 func Dnrm2Test(t *testing.T, blasser Dnrm2er) { 1385 dnrm2 := blasser.Dnrm2 1386 for _, c := range DoubleOneVectorCases { 1387 if c.Panic { 1388 f := func() { dnrm2(c.N, c.X, c.Incx) } 1389 testpanics(f, c.Name, t) 1390 continue 1391 } 1392 v := dnrm2(c.N, c.X, c.Incx) 1393 if !dTolEqual(v, c.Dnrm2) { 1394 t.Errorf("dnrm2: mismatch %v: expected %v, found %v", c.Name, c.Dnrm2, v) 1395 } 1396 } 1397 } 1398 1399 type Dasumer interface { 1400 Dasum(n int, x []float64, incX int) float64 1401 } 1402 1403 func DasumTest(t *testing.T, blasser Dasumer) { 1404 dasum := blasser.Dasum 1405 for _, c := range DoubleOneVectorCases { 1406 if c.Panic { 1407 f := func() { dasum(c.N, c.X, c.Incx) } 1408 testpanics(f, c.Name, t) 1409 continue 1410 } 1411 v := dasum(c.N, c.X, c.Incx) 1412 if !dTolEqual(v, c.Dasum) { 1413 t.Errorf("dasum: mismatch %v: expected %v, found %v", c.Name, c.Dasum, v) 1414 } 1415 } 1416 } 1417 1418 type Idamaxer interface { 1419 Idamax(n int, x []float64, incX int) int 1420 } 1421 1422 func IdamaxTest(t *testing.T, blasser Idamaxer) { 1423 idamax := blasser.Idamax 1424 for _, c := range DoubleOneVectorCases { 1425 if c.Panic { 1426 f := func() { idamax(c.N, c.X, c.Incx) } 1427 testpanics(f, c.Name, t) 1428 continue 1429 } 1430 v := idamax(c.N, c.X, c.Incx) 1431 if v != c.Idamax { 1432 s := fmt.Sprintf("idamax: mismatch %v: expected %v, found %v", c.Name, c.Idamax, v) 1433 if floats.HasNaN(c.X) { 1434 t.Log(s) 1435 } else { 1436 t.Errorf(s) 1437 } 1438 } 1439 } 1440 } 1441 1442 type Dswapper interface { 1443 Dswap(n int, x []float64, incX int, y []float64, incY int) 1444 } 1445 1446 func DswapTest(t *testing.T, d Dswapper) { 1447 dswap := d.Dswap 1448 for _, c := range DoubleTwoVectorCases { 1449 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 1450 if c.Panic { 1451 f := func() { dswap(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } 1452 testpanics(f, c.Name, t) 1453 continue 1454 } 1455 dswap(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) 1456 if !dSliceTolEqual(c.XTmp, c.DswapAns.X) { 1457 t.Errorf("dswap: x mismatch %v: expected %v, found %v", c.Name, c.DswapAns.X, c.XTmp) 1458 } 1459 if !dSliceTolEqual(c.YTmp, c.DswapAns.Y) { 1460 t.Errorf("dswap: y mismatch %v: expected %v, found %v", c.Name, c.DswapAns.Y, c.YTmp) 1461 } 1462 } 1463 } 1464 1465 type Dcopier interface { 1466 Dcopy(n int, x []float64, incX int, y []float64, incY int) 1467 } 1468 1469 func DcopyTest(t *testing.T, d Dcopier) { 1470 dcopy := d.Dcopy 1471 for _, c := range DoubleTwoVectorCases { 1472 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 1473 if c.Panic { 1474 f := func() { dcopy(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } 1475 testpanics(f, c.Name, t) 1476 continue 1477 } 1478 dcopy(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) 1479 if !dSliceTolEqual(c.XTmp, c.DcopyAns.X) { 1480 t.Errorf("dswap: x mismatch %v: expected %v, found %v", c.Name, c.DcopyAns.X, c.XTmp) 1481 } 1482 if !dSliceTolEqual(c.YTmp, c.DcopyAns.Y) { 1483 t.Errorf("dswap: y mismatch %v: expected %v, found %v", c.Name, c.DcopyAns.Y, c.YTmp) 1484 } 1485 } 1486 } 1487 1488 type Daxpyer interface { 1489 Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) 1490 } 1491 1492 func DaxpyTest(t *testing.T, d Daxpyer) { 1493 daxpy := d.Daxpy 1494 for _, c := range DoubleTwoVectorCases { 1495 for _, kind := range c.DaxpyCases { 1496 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 1497 if c.Panic { 1498 f := func() { daxpy(c.N, kind.Alpha, c.XTmp, c.Incx, c.YTmp, c.Incy) } 1499 testpanics(f, c.Name, t) 1500 continue 1501 } 1502 daxpy(c.N, kind.Alpha, c.XTmp, c.Incx, c.YTmp, c.Incy) 1503 if !dSliceTolEqual(c.YTmp, kind.Ans) { 1504 t.Errorf("daxpy: mismatch %v: expected %v, found %v", c.Name, kind.Ans, c.YTmp) 1505 } 1506 } 1507 } 1508 } 1509 1510 type DrotgTestStruct struct { 1511 Name string 1512 A, B float64 1513 C, S, R, Z float64 1514 } 1515 1516 var DrotgTests = []DrotgTestStruct{ 1517 { 1518 Name: "ZeroAB", 1519 C: 1, 1520 }, 1521 { 1522 Name: "PosA_ZeroB", 1523 A: 0.5, 1524 C: 1, 1525 R: 0.5, 1526 }, 1527 { 1528 Name: "NegA_ZeroB", 1529 A: -4.6, 1530 C: 1, 1531 R: -4.6, 1532 }, 1533 { 1534 Name: "ZeroA_PosB", 1535 B: 3, 1536 S: 1, 1537 R: 3, 1538 Z: 1, 1539 }, 1540 { 1541 Name: "ZeroA_NegB", 1542 B: -0.3, 1543 S: 1, 1544 R: -0.3, 1545 Z: 1, 1546 }, 1547 { 1548 Name: "PosA_PosB_AGTB", 1549 A: 5, 1550 B: 0.3, 1551 C: 0.99820484546577868593549038000, 1552 S: 0.05989229072794672115612942280, 1553 R: 5.00899191454727744602429072688, 1554 Z: 0.05989229072794672115612942280, 1555 }, 1556 { 1557 Name: "PosA_PosB_ALTB", 1558 A: 3, 1559 B: 4, 1560 C: 3.0 / 5, 1561 S: 4.0 / 5, 1562 R: 5, 1563 Z: 5.0 / 3.0, 1564 }, 1565 1566 { 1567 Name: "PosA_NegB_AGTB", 1568 A: 2.6, 1569 B: -0.9, 1570 C: 0.94498607344025815971847507095, 1571 S: -0.32711056388316628605639521686, 1572 R: 2.751363298439520872718790879655, 1573 Z: -0.3271105638831662860563952168, 1574 }, 1575 { 1576 Name: "PosA_NegB_ALTB", 1577 A: 2.6, 1578 B: -2.9, 1579 C: -0.6675450157520258540548049558, 1580 S: 0.7445694406464903756765132200, 1581 R: -3.8948684188300893100043812234, 1582 Z: 1 / -0.6675450157520258540548049558, 1583 }, 1584 { 1585 Name: "NegA_PosB_AGTB", 1586 A: -11.4, 1587 B: 10.3, 1588 C: 0.7419981952497362418487847947, 1589 S: -0.6704018781642353764072353847, 1590 R: -15.363918770938617534070671122, 1591 Z: -0.6704018781642353764072353847, 1592 }, 1593 { 1594 Name: "NegA_PosB_ALTB", 1595 A: -1.4, 1596 B: 10.3, 1597 C: -0.1346838895922121112404717523, 1598 S: 0.9908886162855605326977564640, 1599 R: 10.394710193170370442523552032, 1600 Z: 1 / -0.1346838895922121112404717523, 1601 }, 1602 { 1603 Name: "NegA_NegB_AGTB", 1604 A: -11.4, 1605 B: 10.3, 1606 C: 0.7419981952497362418487847947, 1607 S: -0.6704018781642353764072353847, 1608 R: -15.363918770938617534070671122, 1609 Z: -0.6704018781642353764072353847, 1610 }, 1611 { 1612 Name: "NegA_NegB_ALTB", 1613 A: -1.4, 1614 B: -10.3, 1615 C: 0.1346838895922121112404717523, 1616 S: 0.9908886162855605326977564640, 1617 R: -10.394710193170370442523552032, 1618 Z: 1 / 0.1346838895922121112404717523, 1619 }, 1620 } 1621 1622 type Drotger interface { 1623 Drotg(a, b float64) (c, s, r, z float64) 1624 } 1625 1626 func DrotgTest(t *testing.T, d Drotger) { 1627 drotg := d.Drotg 1628 for _, test := range DrotgTests { 1629 c, s, r, z := drotg(test.A, test.B) 1630 if !dTolEqual(c, test.C) { 1631 t.Errorf("drotg: c mismatch %v: expected %v, found %v", test.Name, test.C, c) 1632 } 1633 if !dTolEqual(s, test.S) { 1634 t.Errorf("drotg: s mismatch %v: expected %v, found %v", test.Name, test.S, s) 1635 } 1636 if !dTolEqual(r, test.R) { 1637 t.Errorf("drotg: r mismatch %v: expected %v, found %v", test.Name, test.R, r) 1638 } 1639 if !dTolEqual(z, test.Z) { 1640 t.Errorf("drotg: z mismatch %v: expected %v, found %v", test.Name, test.Z, z) 1641 } 1642 } 1643 } 1644 1645 type DrotmgTestStruct struct { 1646 Name string 1647 D1, D2, X1, Y1 float64 1648 P *blas.DrotmParams 1649 Rd1, Rd2, Rx1 float64 1650 } 1651 1652 var DrotmgTests = []DrotmgTestStruct{ 1653 { 1654 Name: "NegD1", 1655 P: &blas.DrotmParams{ 1656 Flag: blas.Rescaling, 1657 }, 1658 D1: -4, 1659 D2: 6, 1660 X1: 8, 1661 Y1: -4, 1662 }, 1663 { 1664 Name: "ZeroD2", 1665 P: &blas.DrotmParams{ 1666 Flag: blas.Identity, 1667 }, 1668 D1: 4, 1669 X1: 8, 1670 Y1: -5, 1671 Rd1: 4, 1672 Rx1: 8, 1673 }, 1674 { 1675 Name: "ZeroY1", 1676 P: &blas.DrotmParams{ 1677 Flag: blas.Identity, 1678 }, 1679 D1: 4, 1680 D2: -6, 1681 X1: 8, 1682 Rd1: 4, 1683 Rd2: -6, 1684 Rx1: 8, 1685 }, 1686 { 1687 Name: "NegQ2_and_AQ1_LT_AQ2", 1688 P: &blas.DrotmParams{ 1689 Flag: blas.Rescaling, 1690 }, 1691 D1: 8, 1692 D2: -6, 1693 X1: 4, 1694 Y1: 8, 1695 Rd1: 0, 1696 Rd2: 0, 1697 Rx1: 0, 1698 }, 1699 { 1700 Name: "ZeroD1", 1701 P: &blas.DrotmParams{ 1702 Flag: blas.Diagonal, 1703 H: [4]float64{0, 0, 0, 0}, 1704 }, 1705 D1: 0, 1706 D2: 2, 1707 X1: 8, 1708 Y1: 4, 1709 Rd1: 2, 1710 Rd2: 0, 1711 Rx1: 4, 1712 }, 1713 { 1714 Name: "AbsQ1_GT_AbsQU__D2_Pos", 1715 P: &blas.DrotmParams{ 1716 Flag: blas.OffDiagonal, 1717 H: [4]float64{0, -0.625, 0.9375, 0}, 1718 }, 1719 D1: 2, 1720 D2: 3, 1721 X1: 8, 1722 Y1: 5, 1723 Rd1: 1.2610837438423645, 1724 Rd2: 1.8916256157635467, 1725 Rx1: 12.6875, 1726 }, 1727 { 1728 Name: "AbsQ1_GT_AbsQU__D2_Neg", 1729 P: &blas.DrotmParams{ 1730 Flag: blas.OffDiagonal, 1731 H: [4]float64{0, -0.625, -0.9375, 0}, 1732 }, 1733 D1: 2, 1734 D2: -3, 1735 X1: 8, 1736 Y1: 5, 1737 Rd1: 4.830188679245283, 1738 Rd2: -7.245283018867925, 1739 Rx1: 3.3125, 1740 }, 1741 { 1742 Name: "AbsQ1_LT_AbsQU__D2_Pos", 1743 P: &blas.DrotmParams{ 1744 Flag: blas.Diagonal, 1745 H: [4]float64{5.0 / 12, 0, 0, 0.625}, 1746 }, 1747 D1: 2, 1748 D2: 3, 1749 X1: 5, 1750 Y1: 8, 1751 Rd1: 2.3801652892561984, 1752 Rd2: 1.586776859504132, 1753 Rx1: 121.0 / 12, 1754 }, 1755 { 1756 Name: "D1=D2_X1=X2", 1757 P: &blas.DrotmParams{ 1758 Flag: blas.Diagonal, 1759 H: [4]float64{1, 0, 0, 1}, 1760 }, 1761 D1: 2, 1762 D2: 2, 1763 X1: 8, 1764 Y1: 8, 1765 Rd1: 1, 1766 Rd2: 1, 1767 Rx1: 16, 1768 }, 1769 { 1770 Name: "RD1_Big_RD2_Big_Flag_0", 1771 P: &blas.DrotmParams{ 1772 Flag: blas.Rescaling, 1773 H: [4]float64{4096, -3584, 1792, 4096}, 1774 }, 1775 D1: 1600000000, 1776 D2: 800000000, 1777 X1: 8, 1778 Y1: 7, 1779 Rd1: 68.96627824858757, 1780 Rd2: 34.483139124293785, 1781 Rx1: 45312, 1782 }, 1783 { 1784 Name: "RD1_Big_RD2_Big_Flag_1", 1785 P: &blas.DrotmParams{ 1786 Flag: blas.Rescaling, 1787 H: [4]float64{2340.5714285714284, -4096, 4096, 4681.142857142857}, 1788 }, 1789 D1: 800000000, 1790 D2: 1600000000, 1791 X1: 8, 1792 Y1: 7, 1793 Rd1: 57.6914092640818, 1794 Rd2: 28.8457046320409, 1795 Rx1: 47396.57142857142, 1796 }, 1797 { 1798 Name: "RD1_Big_RD2_Med_Flag_0", 1799 P: &blas.DrotmParams{ 1800 Flag: blas.Rescaling, 1801 H: [4]float64{4096, -1, 0.0004096, 1}, 1802 }, 1803 D1: 20000000, 1804 D2: 2, 1805 X1: 8, 1806 Y1: 8, 1807 Rd1: 1.1920927762985347, 1808 Rd2: 1.9999998000000199, 1809 Rx1: 32768.0032768, 1810 }, 1811 { 1812 Name: "RD1_Big_RD2_Med_Flag_1", 1813 P: &blas.DrotmParams{ 1814 Flag: blas.Rescaling, 1815 H: [4]float64{4.096e-17, -1, 4096, 1e-10}, 1816 }, 1817 D1: 2, 1818 D2: 20000000000, 1819 X1: 8, 1820 Y1: 80000000000, 1821 Rd1: 1192.0928955078125, 1822 Rd2: 2, 1823 Rx1: 3.2768e+14, 1824 }, 1825 1826 // TODO: Add D1 big, D2 small, Flag = 0 1827 { 1828 Name: "D1_Big_D2_Small_Flag_1", 1829 P: &blas.DrotmParams{ 1830 Flag: blas.Rescaling, 1831 H: [4]float64{2.8671999999999997e-26, -0.000244140625, 4096, 2.44140625e-16}, 1832 }, 1833 D1: 0.000000014, 1834 D2: 2000000000, 1835 X1: 0.000008, 1836 Y1: 8000000, 1837 Rd1: 119.20928955078125, 1838 Rd2: 0.234881024, 1839 Rx1: 3.2768e+10, 1840 }, 1841 1842 { 1843 Name: "RD1_Med_RD2_Big_Flag_0", 1844 P: &blas.DrotmParams{ 1845 Flag: blas.Rescaling, 1846 H: [4]float64{1, -0.0004096, 1000, 4096}, 1847 }, 1848 D1: 2, 1849 D2: 20000000000, 1850 X1: 80000000, 1851 Y1: 8, 1852 Rd1: 1.9998000199980002, 1853 Rd2: 1191.9736981379988, 1854 Rx1: 8.0008e+07, 1855 }, 1856 { 1857 Name: "D1_Med_D2_Big_Flag_1", 1858 P: &blas.DrotmParams{ 1859 Flag: blas.Rescaling, 1860 H: [4]float64{50, -4096, 1, 4.096e-06}, 1861 }, 1862 D1: 20000000000, 1863 D2: 0.4, 1864 X1: 80000000, 1865 Y1: 80000000000000000, 1866 Rd1: 0.39999998000000103, 1867 Rd2: 1192.092835903171, 1868 Rx1: 8.0000004e+16, 1869 }, 1870 { 1871 Name: "RD1_Med_RD2_Small_Flag_0", 1872 P: &blas.DrotmParams{ 1873 Flag: blas.Rescaling, 1874 H: [4]float64{1, -0.0007233796296296296, 1.1111111111111111e-10, 0.000244140625}, 1875 }, 1876 D1: 1.2, 1877 D2: 0.000000000045, 1878 X1: 2.7, 1879 Y1: 8, 1880 Rd1: 1.1999999996049382, 1881 Rd2: 0.0007549747197514486, 1882 Rx1: 2.700000000888889, 1883 }, 1884 { 1885 Name: "RD1_Med_RD2_Small_Flag_1", 1886 P: &blas.DrotmParams{ 1887 Flag: blas.Rescaling, 1888 H: [4]float64{0.0002197265625, -1, 0.000244140625, 3.375e-11}, 1889 }, 1890 D1: 1.2, 1891 D2: 0.000000000045, 1892 X1: 2.7, 1893 Y1: 80000000000, 1894 Rd1: 0.0007549747199770676, 1895 Rd2: 1.19999999996355, 1896 Rx1: 1.9531250000593264e+07, 1897 }, 1898 // TODO: Add Small, Big, 0 case 1899 { 1900 Name: "D1_Small_D2_Big_Flag_1", 1901 P: &blas.DrotmParams{ 1902 Flag: blas.Rescaling, 1903 H: [4]float64{2.3731773997569866e+10, -1.6777216e+07, 0.000244140625, 1.6777216e-07}, 1904 }, 1905 D1: 120000000000000000, 1906 D2: 0.000000000012345, 1907 X1: 0.08, 1908 Y1: 8000000000000, 1909 Rd1: 0.00010502490698765249, 1910 Rd2: 216.1836123957717, 1911 Rx1: 3.8516669198055897e+09, 1912 }, 1913 { 1914 Name: "RD1_Small_RD2_Med_Flag_0", 1915 P: &blas.DrotmParams{ 1916 Flag: blas.Rescaling, 1917 H: [4]float64{0.000244140625, -1e-08, 0.24414062499999997, 1}, 1918 }, 1919 D1: 0.0000000002, 1920 D2: 20, 1921 X1: 0.8, 1922 Y1: 0.000000008, 1923 Rd1: 0.003355409645903541, 1924 Rd2: 19.99980000199998, 1925 Rx1: 0.000195314453125, 1926 }, 1927 { 1928 Name: "RD1_Small_RD2_Med_Flag_1", 1929 P: &blas.DrotmParams{ 1930 Flag: blas.Rescaling, 1931 H: [4]float64{0.0012207031250000002, -1, 0.000244140625, 1e-09}, 1932 }, 1933 D1: 0.02, 1934 D2: 0.000000000004, 1935 X1: 0.008, 1936 Y1: 8000000, 1937 Rd1: 6.710886366445568e-05, 1938 Rd2: 0.019999999900000003, 1939 Rx1: 1953.125009765625, 1940 }, 1941 { 1942 // Values consistent with the low precision output posted at the OpenBLAS issue. 1943 // See https://github.com/xianyi/OpenBLAS/issues/1452. 1944 Name: "OpenBLAS#1452", 1945 P: &blas.DrotmParams{ 1946 Flag: blas.Rescaling, 1947 H: [4]float64{1.6110934624105326e-06, -0.000244140625, 0.000244140625, 1.6276041666666668e-06}, 1948 }, 1949 D1: 5.9e-8, 1950 D2: 5.960464e-8, 1951 X1: 1, 1952 Y1: 150, 1953 Rd1: 0.9999559282289687, 1954 Rd2: 0.9898121986058326, 1955 Rx1: 0.03662270484346241, 1956 }, 1957 { 1958 Name: "netlib/BLAS/TESTING#1", 1959 P: &blas.DrotmParams{ 1960 Flag: blas.OffDiagonal, 1961 H: [4]float64{0, -0.16666666666666669, 0.5, 0}, 1962 }, 1963 D1: 0.10000000000000001, 1964 D2: 0.29999999999999999, 1965 X1: 1.2000000000000000, 1966 Y1: 0.20000000000000001, 1967 Rd1: 9.2307692307692313e-2, 1968 Rd2: 0.27692307692307694, 1969 Rx1: 1.2999999999999998, 1970 }, 1971 { 1972 Name: "netlib/BLAS/TESTING#2", 1973 P: &blas.DrotmParams{ 1974 Flag: blas.Diagonal, 1975 H: [4]float64{0.5, 0, 0, 0.14285714285714285}, 1976 }, 1977 D1: 0.69999999999999996, 1978 D2: 0.20000000000000001, 1979 X1: 0.59999999999999998, 1980 Y1: 4.2000000000000002, 1981 Rd1: 0.18666666666666668, 1982 Rd2: 0.65333333333333332, 1983 Rx1: 4.5000000000000000, 1984 }, 1985 { 1986 Name: "netlib/BLAS/TESTING#3", 1987 P: &blas.DrotmParams{ 1988 Flag: blas.Identity, 1989 H: [4]float64{0, 0, 0, 0}, 1990 }, 1991 D1: 0, 1992 D2: 0, 1993 X1: 0, 1994 Y1: 0, 1995 Rd1: 0, 1996 Rd2: 0, 1997 Rx1: 0, 1998 }, 1999 { 2000 Name: "netlib/BLAS/TESTING#4", 2001 P: &blas.DrotmParams{ 2002 Flag: blas.Rescaling, 2003 H: [4]float64{0, 0, 0, 0}, 2004 }, 2005 D1: 4, 2006 D2: -1, 2007 X1: 2, 2008 Y1: 4, 2009 Rd1: 0, 2010 Rd2: 0, 2011 Rx1: 0, 2012 }, 2013 { 2014 Name: "netlib/BLAS/TESTING#5", 2015 P: &blas.DrotmParams{ 2016 Flag: blas.Rescaling, 2017 H: [4]float64{0.244140625e-03, -0.1e-3, 0.8138020833333334, 1}, 2018 }, 2019 D1: 6e-10, 2020 D2: 2e-2, 2021 X1: 100000, 2022 Y1: 10, 2023 Rd1: 7.5497471999999991e-3, 2024 Rd2: 1.4999999999999999e-2, 2025 Rx1: 32.552083333333336, 2026 }, 2027 { 2028 Name: "netlib/BLAS/TESTING#6", 2029 P: &blas.DrotmParams{ 2030 Flag: blas.Rescaling, 2031 H: [4]float64{4096, -999999.99999999988, 2.0479999999999999e-3, 1}, 2032 }, 2033 D1: 40000000000, 2034 D2: 2e-2, 2035 X1: 1.0000000000000001e-5, 2036 Y1: 10, 2037 Rd1: 1589.4571940104167, 2038 Rd2: 1.3333333333333334e-2, 2039 Rx1: 6.1440000000000008e-2, 2040 }, 2041 { 2042 Name: "netlib/BLAS/TESTING#7", 2043 P: &blas.DrotmParams{ 2044 Flag: blas.Rescaling, 2045 H: [4]float64{0.5e-4, -0.2441406250e-3, 1, 2.441406250}, 2046 }, 2047 D1: 2.0000000000000001e-10, 2048 D2: 4.0000000000000001e-2, 2049 X1: 100000, 2050 Y1: 10, 2051 Rd1: 2.6666666666666668e-2, 2052 Rd2: 2.2369621333333334e-3, 2053 Rx1: 15, 2054 }, 2055 { 2056 Name: "netlib/BLAS/TESTING#8", 2057 P: &blas.DrotmParams{ 2058 Flag: blas.Rescaling, 2059 H: [4]float64{500000, -4096, 1, 4.096e-3}, 2060 }, 2061 D1: 20000000000, 2062 D2: 4.0000000000000001e-2, 2063 X1: 1.0000000000000001e-5, 2064 Y1: 10, 2065 Rd1: 2.6666666666666668e-2, 2066 Rd2: 794.72859700520837, 2067 Rx1: 15, 2068 }, 2069 // TODO: Add Small, Small, 0 case 2070 // TODO: Add Small, Small, 1 case 2071 } 2072 2073 type Drotmger interface { 2074 Drotmg(d1, d2, x1, y1 float64) (p blas.DrotmParams, rd1, rd2, rx1 float64) 2075 Drotmer 2076 } 2077 2078 func DrotmgTest(t *testing.T, d Drotmger) { 2079 for _, test := range DrotmgTests { 2080 2081 p, rd1, rd2, rx1 := d.Drotmg(test.D1, test.D2, test.X1, test.Y1) 2082 2083 if p.Flag != test.P.Flag { 2084 t.Errorf("drotmg flag mismatch %v: expected %v, found %v", test.Name, test.P.Flag, p.Flag) 2085 } 2086 for i, val := range p.H { 2087 if !dTolEqual(test.P.H[i], val) { 2088 t.Errorf("drotmg H mismatch %v: expected %v, found %v", test.Name, test.P.H, p.H) 2089 break 2090 } 2091 } 2092 if !dTolEqual(rd1, test.Rd1) { 2093 t.Errorf("drotmg rd1 mismatch %v: expected %v, found %v", test.Name, test.Rd1, rd1) 2094 } 2095 if !dTolEqual(rd2, test.Rd2) { 2096 t.Errorf("drotmg rd2 mismatch %v: expected %v, found %v", test.Name, test.Rd2, rd2) 2097 } 2098 if !dTolEqual(rx1, test.Rx1) { 2099 t.Errorf("drotmg rx1 mismatch %v: expected %v, found %v", test.Name, test.Rx1, rx1) 2100 } 2101 2102 // Drotmg routines compute the components of a modified Givens transformation 2103 // matrix H that zeros the y-component of the resulting vector, 2104 // 2105 // [x1; 0] := H[x1 sqrt(d1); y1 sqrt(d2)]. 2106 // 2107 // Drotm performs a modified Givens rotation of points in the plane, 2108 // 2109 // [x1; y1] := H[x1; y1]. 2110 y := []float64{test.Y1} 2111 d.Drotm(1, []float64{test.X1}, 1, y, 1, p) 2112 for i, v := range y { 2113 if rd2 >= 0 { 2114 v *= math.Sqrt(rd2) 2115 } 2116 if !dTolEqual(v, 0) { 2117 t.Errorf("drotm y_%d mismatch %v: expected 0, found %v", i, test.Name, v) 2118 } 2119 } 2120 } 2121 } 2122 2123 type Droter interface { 2124 Drot(n int, x []float64, incX int, y []float64, incY int, c, s float64) 2125 } 2126 2127 func DrotTest(t *testing.T, d Droter) { 2128 drot := d.Drot 2129 for _, c := range DoubleTwoVectorCases { 2130 for _, kind := range c.DrotCases { 2131 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 2132 if c.Panic { 2133 f := func() { drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) } 2134 testpanics(f, c.Name, t) 2135 continue 2136 } 2137 drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) 2138 if !dSliceTolEqual(c.XTmp, kind.XAns) { 2139 t.Errorf("drot: x mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) 2140 } 2141 if !dSliceTolEqual(c.YTmp, kind.YAns) { 2142 t.Errorf("drot: y mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) 2143 } 2144 } 2145 } 2146 } 2147 2148 type Drotmer interface { 2149 Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) 2150 } 2151 2152 func DrotmTest(t *testing.T, d Drotmer) { 2153 drotm := d.Drotm 2154 for _, c := range DoubleTwoVectorCases { 2155 for _, kind := range c.DrotmCases { 2156 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 2157 if c.Panic { 2158 f := func() { drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) } 2159 testpanics(f, c.Name+", "+kind.Name, t) 2160 continue 2161 } 2162 drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) 2163 if !dSliceTolEqual(c.XTmp, kind.XAns) { 2164 t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) 2165 } 2166 if !dSliceTolEqual(c.YTmp, kind.YAns) { 2167 t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) 2168 } 2169 } 2170 } 2171 } 2172 2173 type Dscaler interface { 2174 Dscal(n int, alpha float64, x []float64, incX int) 2175 } 2176 2177 func DscalTest(t *testing.T, blasser Dscaler) { 2178 dscal := blasser.Dscal 2179 for _, c := range DoubleOneVectorCases { 2180 for _, kind := range c.DscalCases { 2181 xTmp := make([]float64, len(c.X)) 2182 copy(xTmp, c.X) 2183 if c.Panic { 2184 f := func() { dscal(c.N, kind.Alpha, xTmp, c.Incx) } 2185 testpanics(f, c.Name, t) 2186 continue 2187 } 2188 dscal(c.N, kind.Alpha, xTmp, c.Incx) 2189 if !dSliceTolEqual(xTmp, kind.Ans) { 2190 t.Errorf("dscal: mismatch %v, %v: expected %v, found %v", c.Name, kind.Name, kind.Ans, xTmp) 2191 } 2192 } 2193 } 2194 }