github.com/gopherd/gonum@v0.0.4/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/gopherd/gonum/blas" 13 "github.com/gopherd/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 const ( 1645 ulp = 0x1p-52 1646 safmin = 0x1p-1022 1647 safmax = 1 / safmin 1648 tol = 20 * ulp 1649 ) 1650 values := []float64{ 1651 -safmax, 1652 -1 / ulp, 1653 -1, 1654 -1.0 / 3, 1655 -ulp, 1656 -safmin, 1657 0, 1658 safmin, 1659 ulp, 1660 1.0 / 3, 1661 1, 1662 1 / ulp, 1663 safmax, 1664 math.Inf(-1), 1665 math.Inf(1), 1666 math.NaN(), 1667 } 1668 for _, f := range values { 1669 for _, g := range values { 1670 name := fmt.Sprintf("Case f=%v,g=%v", f, g) 1671 1672 // Generate a plane rotation so that 1673 // [ cs sn] * [f] = [r] 1674 // [-sn cs] [g] = [0] 1675 // where cs*cs + sn*sn = 1. 1676 cs, sn, r, _ := drotg(f, g) 1677 1678 switch { 1679 case math.IsNaN(f) || math.IsNaN(g): 1680 if !math.IsNaN(r) { 1681 t.Errorf("%v: unexpected r=%v; want NaN", name, r) 1682 } 1683 case math.IsInf(f, 0) || math.IsInf(g, 0): 1684 if !math.IsNaN(r) && !math.IsInf(r, 0) { 1685 t.Errorf("%v: unexpected r=%v; want NaN or Inf", name, r) 1686 } 1687 default: 1688 d := math.Max(math.Abs(f), math.Abs(g)) 1689 d = math.Min(math.Max(safmin, d), safmax) 1690 fs := f / d 1691 gs := g / d 1692 rs := r / d 1693 1694 // Check that cs*f + sn*g = r. 1695 rnorm := math.Abs(rs) 1696 if rnorm == 0 { 1697 rnorm = math.Max(math.Abs(fs), math.Abs(gs)) 1698 if rnorm == 0 { 1699 rnorm = 1 1700 } 1701 } 1702 resid := math.Abs(rs-(cs*fs+sn*gs)) / rnorm 1703 if resid > tol { 1704 t.Errorf("%v: cs*f + sn*g != r; resid=%v", name, resid) 1705 } 1706 1707 // Check that -sn*f + cs*g = 0. 1708 resid = math.Abs(-sn*fs + cs*gs) 1709 if resid > tol { 1710 t.Errorf("%v: -sn*f + cs*g != 0; resid=%v", name, resid) 1711 } 1712 1713 // Check that cs*cs + sn*sn = 1. 1714 resid = math.Abs(1 - (cs*cs + sn*sn)) 1715 if resid > tol { 1716 t.Errorf("%v: cs*cs + sn*sn != 1; resid=%v", name, resid) 1717 } 1718 1719 // Check that cs is non-negative. 1720 if math.Abs(f) > math.Abs(g) { 1721 if cs < 0 { 1722 t.Errorf("%v: cs is negative; cs=%v", name, cs) 1723 } 1724 } else { 1725 if cs*math.Copysign(1, f)*math.Copysign(1, g) < 0 { 1726 t.Errorf("%v: sign of cs doesn't match sign of f and g; cs=%v, sign(f)=%v, sign(g)=%v", 1727 name, cs, math.Copysign(1, f), math.Copysign(1, g)) 1728 } 1729 } 1730 } 1731 } 1732 } 1733 } 1734 1735 type DrotmgTestStruct struct { 1736 Name string 1737 D1, D2, X1, Y1 float64 1738 P *blas.DrotmParams 1739 Rd1, Rd2, Rx1 float64 1740 } 1741 1742 var DrotmgTests = []DrotmgTestStruct{ 1743 { 1744 Name: "NegD1", 1745 P: &blas.DrotmParams{ 1746 Flag: blas.Rescaling, 1747 }, 1748 D1: -4, 1749 D2: 6, 1750 X1: 8, 1751 Y1: -4, 1752 }, 1753 { 1754 Name: "ZeroD2", 1755 P: &blas.DrotmParams{ 1756 Flag: blas.Identity, 1757 }, 1758 D1: 4, 1759 X1: 8, 1760 Y1: -5, 1761 Rd1: 4, 1762 Rx1: 8, 1763 }, 1764 { 1765 Name: "ZeroY1", 1766 P: &blas.DrotmParams{ 1767 Flag: blas.Identity, 1768 }, 1769 D1: 4, 1770 D2: -6, 1771 X1: 8, 1772 Rd1: 4, 1773 Rd2: -6, 1774 Rx1: 8, 1775 }, 1776 { 1777 Name: "NegQ2_and_AQ1_LT_AQ2", 1778 P: &blas.DrotmParams{ 1779 Flag: blas.Rescaling, 1780 }, 1781 D1: 8, 1782 D2: -6, 1783 X1: 4, 1784 Y1: 8, 1785 Rd1: 0, 1786 Rd2: 0, 1787 Rx1: 0, 1788 }, 1789 { 1790 Name: "ZeroD1", 1791 P: &blas.DrotmParams{ 1792 Flag: blas.Diagonal, 1793 H: [4]float64{0, 0, 0, 0}, 1794 }, 1795 D1: 0, 1796 D2: 2, 1797 X1: 8, 1798 Y1: 4, 1799 Rd1: 2, 1800 Rd2: 0, 1801 Rx1: 4, 1802 }, 1803 { 1804 Name: "AbsQ1_GT_AbsQU__D2_Pos", 1805 P: &blas.DrotmParams{ 1806 Flag: blas.OffDiagonal, 1807 H: [4]float64{0, -0.625, 0.9375, 0}, 1808 }, 1809 D1: 2, 1810 D2: 3, 1811 X1: 8, 1812 Y1: 5, 1813 Rd1: 1.2610837438423645, 1814 Rd2: 1.8916256157635467, 1815 Rx1: 12.6875, 1816 }, 1817 { 1818 Name: "AbsQ1_GT_AbsQU__D2_Neg", 1819 P: &blas.DrotmParams{ 1820 Flag: blas.OffDiagonal, 1821 H: [4]float64{0, -0.625, -0.9375, 0}, 1822 }, 1823 D1: 2, 1824 D2: -3, 1825 X1: 8, 1826 Y1: 5, 1827 Rd1: 4.830188679245283, 1828 Rd2: -7.245283018867925, 1829 Rx1: 3.3125, 1830 }, 1831 { 1832 Name: "AbsQ1_LT_AbsQU__D2_Pos", 1833 P: &blas.DrotmParams{ 1834 Flag: blas.Diagonal, 1835 H: [4]float64{5.0 / 12, 0, 0, 0.625}, 1836 }, 1837 D1: 2, 1838 D2: 3, 1839 X1: 5, 1840 Y1: 8, 1841 Rd1: 2.3801652892561984, 1842 Rd2: 1.586776859504132, 1843 Rx1: 121.0 / 12, 1844 }, 1845 { 1846 Name: "D1=D2_X1=X2", 1847 P: &blas.DrotmParams{ 1848 Flag: blas.Diagonal, 1849 H: [4]float64{1, 0, 0, 1}, 1850 }, 1851 D1: 2, 1852 D2: 2, 1853 X1: 8, 1854 Y1: 8, 1855 Rd1: 1, 1856 Rd2: 1, 1857 Rx1: 16, 1858 }, 1859 { 1860 Name: "RD1_Big_RD2_Big_Flag_0", 1861 P: &blas.DrotmParams{ 1862 Flag: blas.Rescaling, 1863 H: [4]float64{4096, -3584, 1792, 4096}, 1864 }, 1865 D1: 1600000000, 1866 D2: 800000000, 1867 X1: 8, 1868 Y1: 7, 1869 Rd1: 68.96627824858757, 1870 Rd2: 34.483139124293785, 1871 Rx1: 45312, 1872 }, 1873 { 1874 Name: "RD1_Big_RD2_Big_Flag_1", 1875 P: &blas.DrotmParams{ 1876 Flag: blas.Rescaling, 1877 H: [4]float64{2340.5714285714284, -4096, 4096, 4681.142857142857}, 1878 }, 1879 D1: 800000000, 1880 D2: 1600000000, 1881 X1: 8, 1882 Y1: 7, 1883 Rd1: 57.6914092640818, 1884 Rd2: 28.8457046320409, 1885 Rx1: 47396.57142857142, 1886 }, 1887 { 1888 Name: "RD1_Big_RD2_Med_Flag_0", 1889 P: &blas.DrotmParams{ 1890 Flag: blas.Rescaling, 1891 H: [4]float64{4096, -1, 0.0004096, 1}, 1892 }, 1893 D1: 20000000, 1894 D2: 2, 1895 X1: 8, 1896 Y1: 8, 1897 Rd1: 1.1920927762985347, 1898 Rd2: 1.9999998000000199, 1899 Rx1: 32768.0032768, 1900 }, 1901 { 1902 Name: "RD1_Big_RD2_Med_Flag_1", 1903 P: &blas.DrotmParams{ 1904 Flag: blas.Rescaling, 1905 H: [4]float64{4.096e-17, -1, 4096, 1e-10}, 1906 }, 1907 D1: 2, 1908 D2: 20000000000, 1909 X1: 8, 1910 Y1: 80000000000, 1911 Rd1: 1192.0928955078125, 1912 Rd2: 2, 1913 Rx1: 3.2768e+14, 1914 }, 1915 1916 // TODO: Add D1 big, D2 small, Flag = 0 1917 { 1918 Name: "D1_Big_D2_Small_Flag_1", 1919 P: &blas.DrotmParams{ 1920 Flag: blas.Rescaling, 1921 H: [4]float64{2.8671999999999997e-26, -0.000244140625, 4096, 2.44140625e-16}, 1922 }, 1923 D1: 0.000000014, 1924 D2: 2000000000, 1925 X1: 0.000008, 1926 Y1: 8000000, 1927 Rd1: 119.20928955078125, 1928 Rd2: 0.234881024, 1929 Rx1: 3.2768e+10, 1930 }, 1931 1932 { 1933 Name: "RD1_Med_RD2_Big_Flag_0", 1934 P: &blas.DrotmParams{ 1935 Flag: blas.Rescaling, 1936 H: [4]float64{1, -0.0004096, 1000, 4096}, 1937 }, 1938 D1: 2, 1939 D2: 20000000000, 1940 X1: 80000000, 1941 Y1: 8, 1942 Rd1: 1.9998000199980002, 1943 Rd2: 1191.9736981379988, 1944 Rx1: 8.0008e+07, 1945 }, 1946 { 1947 Name: "D1_Med_D2_Big_Flag_1", 1948 P: &blas.DrotmParams{ 1949 Flag: blas.Rescaling, 1950 H: [4]float64{50, -4096, 1, 4.096e-06}, 1951 }, 1952 D1: 20000000000, 1953 D2: 0.4, 1954 X1: 80000000, 1955 Y1: 80000000000000000, 1956 Rd1: 0.39999998000000103, 1957 Rd2: 1192.092835903171, 1958 Rx1: 8.0000004e+16, 1959 }, 1960 { 1961 Name: "RD1_Med_RD2_Small_Flag_0", 1962 P: &blas.DrotmParams{ 1963 Flag: blas.Rescaling, 1964 H: [4]float64{1, -0.0007233796296296296, 1.1111111111111111e-10, 0.000244140625}, 1965 }, 1966 D1: 1.2, 1967 D2: 0.000000000045, 1968 X1: 2.7, 1969 Y1: 8, 1970 Rd1: 1.1999999996049382, 1971 Rd2: 0.0007549747197514486, 1972 Rx1: 2.700000000888889, 1973 }, 1974 { 1975 Name: "RD1_Med_RD2_Small_Flag_1", 1976 P: &blas.DrotmParams{ 1977 Flag: blas.Rescaling, 1978 H: [4]float64{0.0002197265625, -1, 0.000244140625, 3.375e-11}, 1979 }, 1980 D1: 1.2, 1981 D2: 0.000000000045, 1982 X1: 2.7, 1983 Y1: 80000000000, 1984 Rd1: 0.0007549747199770676, 1985 Rd2: 1.19999999996355, 1986 Rx1: 1.9531250000593264e+07, 1987 }, 1988 // TODO: Add Small, Big, 0 case 1989 { 1990 Name: "D1_Small_D2_Big_Flag_1", 1991 P: &blas.DrotmParams{ 1992 Flag: blas.Rescaling, 1993 H: [4]float64{2.3731773997569866e+10, -1.6777216e+07, 0.000244140625, 1.6777216e-07}, 1994 }, 1995 D1: 120000000000000000, 1996 D2: 0.000000000012345, 1997 X1: 0.08, 1998 Y1: 8000000000000, 1999 Rd1: 0.00010502490698765249, 2000 Rd2: 216.1836123957717, 2001 Rx1: 3.8516669198055897e+09, 2002 }, 2003 { 2004 Name: "RD1_Small_RD2_Med_Flag_0", 2005 P: &blas.DrotmParams{ 2006 Flag: blas.Rescaling, 2007 H: [4]float64{0.000244140625, -1e-08, 0.24414062499999997, 1}, 2008 }, 2009 D1: 0.0000000002, 2010 D2: 20, 2011 X1: 0.8, 2012 Y1: 0.000000008, 2013 Rd1: 0.003355409645903541, 2014 Rd2: 19.99980000199998, 2015 Rx1: 0.000195314453125, 2016 }, 2017 { 2018 Name: "RD1_Small_RD2_Med_Flag_1", 2019 P: &blas.DrotmParams{ 2020 Flag: blas.Rescaling, 2021 H: [4]float64{0.0012207031250000002, -1, 0.000244140625, 1e-09}, 2022 }, 2023 D1: 0.02, 2024 D2: 0.000000000004, 2025 X1: 0.008, 2026 Y1: 8000000, 2027 Rd1: 6.710886366445568e-05, 2028 Rd2: 0.019999999900000003, 2029 Rx1: 1953.125009765625, 2030 }, 2031 { 2032 // Values consistent with the low precision output posted at the OpenBLAS issue. 2033 // See https://github.com/xianyi/OpenBLAS/issues/1452. 2034 Name: "OpenBLAS#1452", 2035 P: &blas.DrotmParams{ 2036 Flag: blas.Rescaling, 2037 H: [4]float64{1.6110934624105326e-06, -0.000244140625, 0.000244140625, 1.6276041666666668e-06}, 2038 }, 2039 D1: 5.9e-8, 2040 D2: 5.960464e-8, 2041 X1: 1, 2042 Y1: 150, 2043 Rd1: 0.9999559282289687, 2044 Rd2: 0.9898121986058326, 2045 Rx1: 0.03662270484346241, 2046 }, 2047 { 2048 Name: "netlib/BLAS/TESTING#1", 2049 P: &blas.DrotmParams{ 2050 Flag: blas.OffDiagonal, 2051 H: [4]float64{0, -0.16666666666666669, 0.5, 0}, 2052 }, 2053 D1: 0.10000000000000001, 2054 D2: 0.29999999999999999, 2055 X1: 1.2000000000000000, 2056 Y1: 0.20000000000000001, 2057 Rd1: 9.2307692307692313e-2, 2058 Rd2: 0.27692307692307694, 2059 Rx1: 1.2999999999999998, 2060 }, 2061 { 2062 Name: "netlib/BLAS/TESTING#2", 2063 P: &blas.DrotmParams{ 2064 Flag: blas.Diagonal, 2065 H: [4]float64{0.5, 0, 0, 0.14285714285714285}, 2066 }, 2067 D1: 0.69999999999999996, 2068 D2: 0.20000000000000001, 2069 X1: 0.59999999999999998, 2070 Y1: 4.2000000000000002, 2071 Rd1: 0.18666666666666668, 2072 Rd2: 0.65333333333333332, 2073 Rx1: 4.5000000000000000, 2074 }, 2075 { 2076 Name: "netlib/BLAS/TESTING#3", 2077 P: &blas.DrotmParams{ 2078 Flag: blas.Identity, 2079 H: [4]float64{0, 0, 0, 0}, 2080 }, 2081 D1: 0, 2082 D2: 0, 2083 X1: 0, 2084 Y1: 0, 2085 Rd1: 0, 2086 Rd2: 0, 2087 Rx1: 0, 2088 }, 2089 { 2090 Name: "netlib/BLAS/TESTING#4", 2091 P: &blas.DrotmParams{ 2092 Flag: blas.Rescaling, 2093 H: [4]float64{0, 0, 0, 0}, 2094 }, 2095 D1: 4, 2096 D2: -1, 2097 X1: 2, 2098 Y1: 4, 2099 Rd1: 0, 2100 Rd2: 0, 2101 Rx1: 0, 2102 }, 2103 { 2104 Name: "netlib/BLAS/TESTING#5", 2105 P: &blas.DrotmParams{ 2106 Flag: blas.Rescaling, 2107 H: [4]float64{0.244140625e-03, -0.1e-3, 0.8138020833333334, 1}, 2108 }, 2109 D1: 6e-10, 2110 D2: 2e-2, 2111 X1: 100000, 2112 Y1: 10, 2113 Rd1: 7.5497471999999991e-3, 2114 Rd2: 1.4999999999999999e-2, 2115 Rx1: 32.552083333333336, 2116 }, 2117 { 2118 Name: "netlib/BLAS/TESTING#6", 2119 P: &blas.DrotmParams{ 2120 Flag: blas.Rescaling, 2121 H: [4]float64{4096, -999999.99999999988, 2.0479999999999999e-3, 1}, 2122 }, 2123 D1: 40000000000, 2124 D2: 2e-2, 2125 X1: 1.0000000000000001e-5, 2126 Y1: 10, 2127 Rd1: 1589.4571940104167, 2128 Rd2: 1.3333333333333334e-2, 2129 Rx1: 6.1440000000000008e-2, 2130 }, 2131 { 2132 Name: "netlib/BLAS/TESTING#7", 2133 P: &blas.DrotmParams{ 2134 Flag: blas.Rescaling, 2135 H: [4]float64{0.5e-4, -0.2441406250e-3, 1, 2.441406250}, 2136 }, 2137 D1: 2.0000000000000001e-10, 2138 D2: 4.0000000000000001e-2, 2139 X1: 100000, 2140 Y1: 10, 2141 Rd1: 2.6666666666666668e-2, 2142 Rd2: 2.2369621333333334e-3, 2143 Rx1: 15, 2144 }, 2145 { 2146 Name: "netlib/BLAS/TESTING#8", 2147 P: &blas.DrotmParams{ 2148 Flag: blas.Rescaling, 2149 H: [4]float64{500000, -4096, 1, 4.096e-3}, 2150 }, 2151 D1: 20000000000, 2152 D2: 4.0000000000000001e-2, 2153 X1: 1.0000000000000001e-5, 2154 Y1: 10, 2155 Rd1: 2.6666666666666668e-2, 2156 Rd2: 794.72859700520837, 2157 Rx1: 15, 2158 }, 2159 // TODO: Add Small, Small, 0 case 2160 // TODO: Add Small, Small, 1 case 2161 } 2162 2163 type Drotmger interface { 2164 Drotmg(d1, d2, x1, y1 float64) (p blas.DrotmParams, rd1, rd2, rx1 float64) 2165 Drotmer 2166 } 2167 2168 func DrotmgTest(t *testing.T, d Drotmger) { 2169 for _, test := range DrotmgTests { 2170 2171 p, rd1, rd2, rx1 := d.Drotmg(test.D1, test.D2, test.X1, test.Y1) 2172 2173 if p.Flag != test.P.Flag { 2174 t.Errorf("drotmg flag mismatch %v: expected %v, found %v", test.Name, test.P.Flag, p.Flag) 2175 } 2176 for i, val := range p.H { 2177 if !dTolEqual(test.P.H[i], val) { 2178 t.Errorf("drotmg H mismatch %v: expected %v, found %v", test.Name, test.P.H, p.H) 2179 break 2180 } 2181 } 2182 if !dTolEqual(rd1, test.Rd1) { 2183 t.Errorf("drotmg rd1 mismatch %v: expected %v, found %v", test.Name, test.Rd1, rd1) 2184 } 2185 if !dTolEqual(rd2, test.Rd2) { 2186 t.Errorf("drotmg rd2 mismatch %v: expected %v, found %v", test.Name, test.Rd2, rd2) 2187 } 2188 if !dTolEqual(rx1, test.Rx1) { 2189 t.Errorf("drotmg rx1 mismatch %v: expected %v, found %v", test.Name, test.Rx1, rx1) 2190 } 2191 2192 // Drotmg routines compute the components of a modified Givens transformation 2193 // matrix H that zeros the y-component of the resulting vector, 2194 // 2195 // [x1; 0] := H[x1 sqrt(d1); y1 sqrt(d2)]. 2196 // 2197 // Drotm performs a modified Givens rotation of points in the plane, 2198 // 2199 // [x1; y1] := H[x1; y1]. 2200 y := []float64{test.Y1} 2201 d.Drotm(1, []float64{test.X1}, 1, y, 1, p) 2202 for i, v := range y { 2203 if rd2 >= 0 { 2204 v *= math.Sqrt(rd2) 2205 } 2206 if !dTolEqual(v, 0) { 2207 t.Errorf("drotm y_%d mismatch %v: expected 0, found %v", i, test.Name, v) 2208 } 2209 } 2210 } 2211 } 2212 2213 type Droter interface { 2214 Drot(n int, x []float64, incX int, y []float64, incY int, c, s float64) 2215 } 2216 2217 func DrotTest(t *testing.T, d Droter) { 2218 drot := d.Drot 2219 for _, c := range DoubleTwoVectorCases { 2220 for _, kind := range c.DrotCases { 2221 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 2222 if c.Panic { 2223 f := func() { drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) } 2224 testpanics(f, c.Name, t) 2225 continue 2226 } 2227 drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) 2228 if !dSliceTolEqual(c.XTmp, kind.XAns) { 2229 t.Errorf("drot: x mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) 2230 } 2231 if !dSliceTolEqual(c.YTmp, kind.YAns) { 2232 t.Errorf("drot: y mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) 2233 } 2234 } 2235 } 2236 } 2237 2238 type Drotmer interface { 2239 Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) 2240 } 2241 2242 func DrotmTest(t *testing.T, d Drotmer) { 2243 drotm := d.Drotm 2244 for _, c := range DoubleTwoVectorCases { 2245 for _, kind := range c.DrotmCases { 2246 dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) 2247 if c.Panic { 2248 f := func() { drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) } 2249 testpanics(f, c.Name+", "+kind.Name, t) 2250 continue 2251 } 2252 drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) 2253 if !dSliceTolEqual(c.XTmp, kind.XAns) { 2254 t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) 2255 } 2256 if !dSliceTolEqual(c.YTmp, kind.YAns) { 2257 t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) 2258 } 2259 } 2260 } 2261 } 2262 2263 type Dscaler interface { 2264 Dscal(n int, alpha float64, x []float64, incX int) 2265 } 2266 2267 func DscalTest(t *testing.T, blasser Dscaler) { 2268 dscal := blasser.Dscal 2269 for _, c := range DoubleOneVectorCases { 2270 for _, kind := range c.DscalCases { 2271 xTmp := make([]float64, len(c.X)) 2272 copy(xTmp, c.X) 2273 if c.Panic { 2274 f := func() { dscal(c.N, kind.Alpha, xTmp, c.Incx) } 2275 testpanics(f, c.Name, t) 2276 continue 2277 } 2278 dscal(c.N, kind.Alpha, xTmp, c.Incx) 2279 if !dSliceTolEqual(xTmp, kind.Ans) { 2280 t.Errorf("dscal: mismatch %v, %v: expected %v, found %v", c.Name, kind.Name, kind.Ans, xTmp) 2281 } 2282 } 2283 } 2284 }