1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
/*
* Copyright (c) 2011, Michael Lehn * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1) Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2) Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3) Neither the name of the FLENS development group nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Based on * SUBROUTINE DLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ, $ IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T, $ LDT, NV, WV, LDWV, WORK, LWORK ) * * -- LAPACK auxiliary routine (version 3.2.2) -- * Univ. of Tennessee, Univ. of California Berkeley, * Univ. of Colorado Denver and NAG Ltd.. * -- June 2010 -- * */ #ifndef FLENS_LAPACK_LA_LAQR3_TCC #define FLENS_LAPACK_LA_LAQR3_TCC 1 #include <flens/blas/blas.h> #include <flens/lapack/lapack.h> namespace flens { namespace lapack { //== generic lapack implementation ============================================= namespace generic { template <typename IndexType, typename MT> IndexType laqr3_wsq_impl(IndexType kTop, IndexType kBot, IndexType nw, const GeMatrix<MT> &T) { using std::max; using std::min; typedef typename GeMatrix<MT>::ElementType ElementType; const Underscore<IndexType> _; // // ==== Estimate optimal workspace. ==== // IndexType jw = min(nw, kBot-kTop+1); auto _T = T(_(1,jw),_(1,jw)); IndexType lWorkOpt; if (jw<=2) { lWorkOpt = 1; } else { // // ==== Workspace query call to DGEHRD ==== // IndexType lWork1 = hrd_wsq(IndexType(1), jw-1, _T); // // ==== Workspace query call to DORMHR ==== // IndexType lWork2 = ormhr_wsq(Right, NoTrans, IndexType(1), jw-1, _T); // // ==== Workspace query call to DLAQR4 ==== // IndexType lWork3 = laqr4_wsq(true, true, IndexType(1), jw, _T); // // ==== Optimal workspace ==== // lWorkOpt = max(jw+max(lWork1,lWork2), lWork3); } return lWorkOpt; } template <typename IndexType, typename MH, typename MZ, typename VSR, typename VSI, typename MV, typename MT, typename MWV, typename VWORK> void laqr3_impl(bool wantT, bool wantZ, IndexType kTop, IndexType kBot, IndexType nw, GeMatrix<MH> &H, IndexType iLoZ, IndexType iHiZ, GeMatrix<MZ> &Z, IndexType &ns, IndexType &nd, DenseVector<VSR> &sr, DenseVector<VSI> &si, GeMatrix<MV> &V, GeMatrix<MT> &T, GeMatrix<MWV> &WV, DenseVector<VWORK> &work) { using std::abs; using std::max; using std::min; typedef typename GeMatrix<MH>::ElementType ElementType; const Underscore<IndexType> _; const ElementType Zero(0), One(1); const IndexType n = H.numRows(); const IndexType nh = T.numCols(); const IndexType nv = WV.numRows(); // // ==== Estimate optimal workspace. ==== // IndexType jw = min(nw, kBot-kTop+1); auto T_jw = T(_(1,jw),_(1,jw)); auto V_jw = V(_(1,jw),_(1,jw)); IndexType lWorkOpt; if (jw<=2) { lWorkOpt = 1; } else { // // ==== Workspace query call to DGEHRD ==== // IndexType lWork1 = hrd_wsq(IndexType(1), jw-1, T_jw); // // ==== Workspace query call to DORMHR ==== // IndexType lWork2 = ormhr_wsq(Right, NoTrans, IndexType(1), jw-1, V_jw); // // ==== Workspace query call to DLAQR4 ==== // IndexType lWork3 = laqr4_wsq(true, true, IndexType(1), jw, T_jw); // // ==== Optimal workspace ==== // lWorkOpt = max(jw+max(lWork1,lWork2), lWork3); } // // ==== Apply worksize query ==== // if (work.length()==0) { work.resize(lWorkOpt); } const IndexType lWork = work.length(); // // ==== Nothing to do ... // ... for an empty active block ... ==== ns = 0; nd = 0; work(1) = One; if (kTop>kBot) { return; } // ... nor for an empty deflation window. ==== if (nw<1) { return; } // // ==== Machine constants ==== // ElementType safeMin = lamch<ElementType>(SafeMin); ElementType safeMax = One / safeMin; labad(safeMin, safeMax); const ElementType ulp = lamch<ElementType>(Precision); const ElementType smallNum = safeMin*(ElementType(n)/ulp); // // ==== Setup deflation window ==== // IndexType kwTop = kBot - jw + 1; auto sr_kw = sr(_(kwTop,kBot)); auto si_kw = si(_(kwTop,kBot)); auto H_kw = H(_(kwTop,kBot),_(kwTop,kBot)); ElementType s; if( kwTop==kTop) { s = Zero; } else { s = H(kwTop, kwTop-1); } if (kBot==kwTop) { // // ==== 1-by-1 deflation window: not much to do ==== // sr(kwTop) = H(kwTop,kwTop); si(kwTop) = Zero; ns = 1; nd = 0; if (abs(s)<=max(smallNum,ulp*abs(H(kwTop,kwTop)))) { ns = 0; nd = 1; if (kwTop>kTop) { H(kwTop, kwTop-1) = Zero; } } work(1) = One; return; } // // ==== Convert to spike-triangular form. (In case of a // . rare QR failure, this routine continues to do // . aggressive early deflation using that part of // . the deflation window that converged using INFQR // . here and there to keep track.) ==== // T_jw.upper() = H_kw.upper(); T_jw.diag(-1) = H_kw.diag(-1); V_jw = Zero; V_jw.diag(0) = One; IndexType nMin = ilaenv<ElementType>(12, "LAQR3", "SV", jw, 1, jw, lWork); IndexType infoQR; if (jw>nMin) { infoQR = laqr4(true, true, IndexType(1), jw, T_jw, sr_kw, si_kw, IndexType(1), jw, V_jw, work); } else { infoQR = lahqr(true, true, IndexType(1), jw, T_jw, sr_kw, si_kw, IndexType(1), jw, V_jw); } // // ==== DTREXC needs a clean margin near the diagonal ==== // for (IndexType j=1; j<=jw-3; ++j) { T(j+2, j) = Zero; T(j+3, j) = Zero; } if (jw>2) { T(jw,jw-2) = Zero; } // // ==== Deflation detection loop ==== // ns = jw; IndexType iFirst; IndexType iLast = infoQR + 1; while (iLast<=ns) { bool bulge; if (ns==1) { bulge = false; } else { bulge = T(ns,ns-1)!=Zero; } // // ==== Small spike tip test for deflation ==== // if (!bulge) { // // ==== Real eigenvalue ==== // ElementType foo = abs(T(ns,ns)); if (foo==Zero) { foo = abs(s); } if (abs(s*V(1,ns))<=max(smallNum,ulp*foo)) { // // ==== Deflatable ==== // ns = ns - 1; } else { // // ==== Undeflatable. Move it up out of the way. // . (DTREXC can not fail in this case.) ==== // iFirst = ns; trexc(true, T_jw, V_jw, iFirst, iLast, work(_(1,jw))); ++iLast; } } else { // // ==== Complex conjugate pair ==== // ElementType foo = abs(T(ns,ns)) + sqrt(abs(T(ns,ns-1)))*sqrt(abs(T(ns-1,ns))); if (foo==Zero) { foo = abs(s); } if (max(abs(s*V(1,ns)), abs(s*V(1,ns-1)))<=max(smallNum,ulp*foo)) { // // ==== Deflatable ==== // ns -= 2; } else { // // ==== Undeflatable. Move them up out of the way. // . Fortunately, DTREXC does the right thing with // . ILST in case of a rare exchange failure. ==== // iFirst = ns; trexc(true, T_jw, V_jw, iFirst, iLast, work(_(1,jw))); iLast += 2; } } // // ==== End deflation detection loop ==== // } // // ==== Return to Hessenberg form ==== // if (ns==0) { s = Zero; } if (ns<jw) { // // ==== sorting diagonal blocks of T improves accuracy for // . graded matrices. Bubble sort deals well with // . exchange failures. ==== // bool sorted = false; IndexType i = ns + 1; while (!sorted) { sorted = true; IndexType kEnd = i - 1; i = infoQR + 1; IndexType k; if (i==ns) { k = i + 1; } else if (T(i+1,i)==Zero) { k = i + 1; } else { k = i + 2; } while (k<=kEnd) { ElementType evi, evk; if (k==i+1) { evi = abs(T(i,i)); } else { evi = abs(T(i,i)) + sqrt(abs(T(i+1,i)))*sqrt(abs(T(i,i+1))); } if (k==kEnd) { evk = abs(T(k,k)); } else if(T(k+1,k)==Zero) { evk = abs(T(k,k)); } else { evk = abs(T(k,k)) + sqrt(abs(T(k+1,k)))*sqrt(abs(T(k,k+1))); } if (evi>=evk) { i = k; } else { sorted = false; iFirst = i; iLast = k; IndexType info = trexc(true, T_jw, V_jw, iFirst, iLast, work(_(1,jw))); if (info==0) { i = iLast; } else { i = k; } } if (i==kEnd) { k = i + 1; } else if (T(i+1,i)==Zero) { k = i + 1; } else { k = i + 2; } } } } // // ==== Restore shift/eigenvalue array from T ==== // IndexType i = jw; while (i>=infoQR+1) { if (i==infoQR+1) { sr(kwTop+i-1) = T(i,i); si(kwTop+i-1) = Zero; i = i - 1; } else if (T(i,i-1)==Zero) { sr(kwTop+i-1 ) = T(i,i); si(kwTop+i-1 ) = Zero; i = i - 1; } else { ElementType aa = T(i-1,i-1); ElementType cc = T(i, i-1); ElementType bb = T(i-1,i ); ElementType dd = T(i, i ); ElementType cs, sn; lanv2(aa, bb, cc, dd, sr(kwTop+i-2), si(kwTop+i-2), sr(kwTop+i-1), si(kwTop+i-1), cs, sn); i -= 2; } } if (ns<jw || s==Zero) { if (ns>1 && s!=Zero) { // // ==== Reflect spike back into lower triangle ==== // work(_(1,ns)) = V(1,_(1,ns)); ElementType beta = work(1); ElementType tau; larfg(ns, beta, work(_(2,ns)), tau); work(1) = One; T(_(3,jw),_(1,jw-2)).lower() = Zero; const auto _v = work(_(1,ns)); larf(Left, _v, tau, T(_(1,ns),_(1,jw)), work(_(jw+1,jw+jw))); larf(Right, _v, tau, T(_(1,ns),_(1,ns)), work(_(jw+1,jw+ns))); larf(Right, _v, tau, V(_(1,jw),_(1,ns)), work(_(jw+1,jw+jw))); hrd(IndexType(1), ns, T_jw, work(_(1,jw-1)), work(_(jw+1,lWork))); } // // ==== Copy updated reduced window into place ==== // if (kwTop>1) { H(kwTop,kwTop-1) = s*V(1,1); } H_kw.upper() = T_jw.upper(); H_kw.diag(-1) = T_jw.diag(-1); // // ==== Accumulate orthogonal matrix in order update // . H and Z, if requested. ==== // if (ns>1 && s!=Zero) { ormhr(Right, NoTrans, IndexType(1), ns, T(_(1,ns),_(1,ns)), work(_(1,ns-1)), V(_(1,jw),_(1,ns)), work(_(jw+1,lWork))); } // // ==== Update vertical slab in H ==== // const IndexType lTop = (wantT) ? 1 : kTop; for (IndexType kRow=lTop; kRow<=kwTop-1; kRow+=nv) { const IndexType kLn = min(nv,kwTop-kRow); blas::mm(NoTrans, NoTrans, One, H(_(kRow,kRow+kLn-1),_(kwTop,kBot)), V(_(1,jw),_(1,jw)), Zero, WV(_(1,kLn),_(1,jw))); H(_(kRow,kRow+kLn-1),_(kwTop,kBot)) = WV(_(1,kLn),_(1,jw)); } // // ==== Update horizontal slab in H ==== // if (wantT) { for (IndexType kCol=kBot+1; kCol<=n; kCol+=nh) { const IndexType kLn = min(nh,n-kCol+1); blas::mm(ConjTrans, NoTrans, One, V(_(1,jw),_(1,jw)), H(_(kwTop,kBot),_(kCol,kCol+kLn-1)), Zero, T(_(1,jw),_(1,kLn))); H(_(kwTop,kBot),_(kCol,kCol+kLn-1)) = T(_(1,jw),_(1,kLn)); } } // // ==== Update vertical slab in Z ==== // if (wantZ) { for (IndexType kRow=iLoZ; kRow<=iHiZ; kRow+=nv) { const IndexType kLn = min(nv,iHiZ-kRow+1); blas::mm(NoTrans, NoTrans, One, Z(_(kRow,kRow+kLn-1),_(kwTop,kBot)), V(_(1,jw),_(1,jw)), Zero, WV(_(1,kLn),_(1,jw))); Z(_(kRow,kRow+kLn-1), _(kwTop,kBot)) = WV(_(1,kLn),_(1,jw)); } } } // // ==== Return the number of deflations ... ==== // nd = jw - ns; // // ==== ... and the number of shifts. (Subtracting // . INFQR from the spike length takes care // . of the case of a rare QR failure while // . calculating eigenvalues of the deflation // . window.) ==== // ns = ns - infoQR; // // ==== Return optimal workspace. ==== // work(1) = lWorkOpt; } } // namespace generic //== interface for native lapack =============================================== #ifdef USE_CXXLAPACK namespace external { template <typename IndexType, typename MT> IndexType laqr3_wsq_impl(IndexType kTop, IndexType kBot, IndexType nw, const GeMatrix<MT> &T) { typedef typename GeMatrix<MT>::ElementType ElementType; IndexType NS; IndexType ND; ElementType WORK; const IndexType LWORK = -1; ElementType DUMMY; cxxlapack::laqr3<IndexType>(false, // wantT false, // wantZ IndexType(1), // n kTop, kBot, nw, &DUMMY, // H IndexType(1), // ldH IndexType(1), // iLoZ IndexType(1), // iHiZ &DUMMY, // Z IndexType(1), // ldZ NS, // dummy output parameter ND, // dummy output parameter &DUMMY, // sr &DUMMY, // si &DUMMY, // V nw, // ldV T.numCols(), // nh &DUMMY, // T.data() T.leadingDimension(), nw, // nv = nw &DUMMY, // WV nw, // ldWV &WORK, LWORK); return WORK; } template <typename IndexType, typename MH, typename MZ, typename VSR, typename VSI, typename MV, typename MT, typename MWV, typename VWORK> void laqr3_impl(bool wantT, bool wantZ, IndexType kTop, IndexType kBot, IndexType nw, GeMatrix<MH> &H, IndexType iLoZ, IndexType iHiZ, GeMatrix<MZ> &Z, IndexType &ns, IndexType &nd, DenseVector<VSR> &sr, DenseVector<VSI> &si, GeMatrix<MV> &V, GeMatrix<MT> &T, GeMatrix<MWV> &WV, DenseVector<VWORK> &work) { cxxlapack::laqr3<IndexType>(wantT, wantZ, H.numRows(), kTop, kBot, nw, H.data(), H.leadingDimension(), iLoZ, iHiZ, Z.data(), Z.leadingDimension(), ns, nd, sr.data(), si.data(), V.data(), V.leadingDimension(), T.numCols(), T.data(), T.leadingDimension(), WV.numRows(), WV.data(), WV.leadingDimension(), work.data(), work.length()); } } // namespace external #endif // USE_CXXLAPACK //== public interface ========================================================== template <typename IndexType, typename MT> IndexType laqr3_wsq(IndexType kTop, IndexType kBot, IndexType nw, const GeMatrix<MT> &T) { using std::max; // // Test the input parameters // # ifndef NDEBUG ASSERT(T.firstRow()==1); ASSERT(T.firstCol()==1); ASSERT(T.numRows()==T.numCols()); # endif // // Call implementation // // TODO: call generic implementation IndexType info = LAPACK_SELECT::laqr3_wsq_impl(kTop, kBot, nw, T); # ifdef CHECK_CXXLAPACK // // Compare results // IndexType _info = external::laqr3_wsq_impl(kTop, kBot, nw, T); if (info!=_info) { std::cerr << "CXXLAPACK: info = " << info << std::endl; std::cerr << "F77LAPACK: _info = " << _info << std::endl; ASSERT(0); } # endif return info; } template <typename IndexType, typename MH, typename MZ, typename VSR, typename VSI, typename MV, typename MT, typename MWV, typename VWORK> void laqr3(bool wantT, bool wantZ, IndexType kTop, IndexType kBot, IndexType nw, GeMatrix<MH> &H, IndexType iLoZ, IndexType iHiZ, GeMatrix<MZ> &Z, IndexType &ns, IndexType &nd, DenseVector<VSR> &sr, DenseVector<VSI> &si, GeMatrix<MV> &V, GeMatrix<MT> &T, GeMatrix<MWV> &WV, DenseVector<VWORK> &work) { LAPACK_DEBUG_OUT("laqr3"); using std::max; // // Test the input parameters // # ifndef NDEBUG ASSERT(H.firstRow()==1); ASSERT(H.firstCol()==1); ASSERT(H.numRows()==H.numCols()); const IndexType n = H.numRows(); if (wantZ) { ASSERT(1<=iLoZ); ASSERT(iLoZ<=iHiZ); ASSERT(iHiZ<=n); ASSERT(Z.firstRow()==1); ASSERT(Z.firstCol()==1); ASSERT(Z.numRows()==n); ASSERT(Z.numCols()==n); } ASSERT(sr.length()==kBot); ASSERT(si.length()==kBot); ASSERT(V.firstRow()==1); ASSERT(V.firstCol()==1); ASSERT(V.numRows()==nw); ASSERT(V.numCols()==nw); const IndexType nh = T.numCols(); ASSERT(nh>=nw); ASSERT(T.firstRow()==1); ASSERT(T.firstCol()==1); const IndexType nv = WV.numRows(); ASSERT(nv>=nw); ASSERT((work.length()==0) || (work.length()>=n)); # endif // // Make copies of output arguments // # ifdef CHECK_CXXLAPACK typename GeMatrix<MH>::NoView H_org = H; typename GeMatrix<MZ>::NoView Z_org = Z; IndexType ns_org = ns; IndexType nd_org = nd; typename DenseVector<VSR>::NoView sr_org = sr; typename DenseVector<VSI>::NoView si_org = si; typename GeMatrix<MV>::NoView V_org = V; typename GeMatrix<MT>::NoView T_org = T; typename GeMatrix<MWV>::NoView WV_org = WV; typename DenseVector<VWORK>::NoView work_org = work; # endif // // Call implementation // LAPACK_SELECT::laqr3_impl(wantT, wantZ, kTop, kBot, nw, H, iLoZ, iHiZ, Z, ns, nd, sr, si, V, T, WV, work); # ifdef CHECK_CXXLAPACK // // Make copies of results computed by the generic implementation // typename GeMatrix<MH>::NoView H_generic = H; typename GeMatrix<MZ>::NoView Z_generic = Z; IndexType ns_generic = ns; IndexType nd_generic = nd; typename DenseVector<VSR>::NoView sr_generic = sr; typename DenseVector<VSI>::NoView si_generic = si; typename GeMatrix<MV>::NoView V_generic = V; typename GeMatrix<MT>::NoView T_generic = T; typename GeMatrix<MWV>::NoView WV_generic = WV; typename DenseVector<VWORK>::NoView work_generic = work; // // restore output arguments // H = H_org; Z = Z_org; ns = ns_org; nd = nd_org; sr = sr_org; si = si_org; V = V_org; T = T_org; WV = WV_org; work = work_org; // // Compare generic results with results from the native implementation // external::laqr3_impl(wantT, wantZ, kTop, kBot, nw, H, iLoZ, iHiZ, Z, ns, nd, sr, si, V, T, WV, work); bool failed = false; if (! isIdentical(H_generic, H, "H_generic", "H")) { std::cerr << "CXXLAPACK: H_generic = " << H_generic << std::endl; std::cerr << "F77LAPACK: H = " << H << std::endl; std::cerr << "Original: H_org = " << H_org << std::endl; failed = true; } if (! isIdentical(Z_generic, Z, "Z_generic", "Z")) { std::cerr << "CXXLAPACK: Z = " << Z_generic << std::endl; std::cerr << "F77LAPACK: Z = " << Z << std::endl; failed = true; } if (! isIdentical(ns_generic, ns, "ns_generic", "ns")) { std::cerr << "CXXLAPACK: ns_generic = " << ns_generic << std::endl; std::cerr << "F77LAPACK: ns = " << ns << std::endl; failed = true; } if (! isIdentical(nd_generic, nd, "nd_generic", "nd")) { std::cerr << "CXXLAPACK: nd_generic = " << nd_generic << std::endl; std::cerr << "F77LAPACK: nd = " << nd << std::endl; failed = true; } if (! isIdentical(sr_generic, sr, "sr_generic", "sr")) { std::cerr << "CXXLAPACK: sr_generic = " << sr_generic << std::endl; std::cerr << "F77LAPACK: sr = " << sr << std::endl; failed = true; } if (! isIdentical(si_generic, si, "si_generic", "si")) { std::cerr << "CXXLAPACK: si_generic = " << si_generic << std::endl; std::cerr << "F77LAPACK: si = " << si << std::endl; failed = true; } if (! isIdentical(V_generic, V, " V_generic", "V")) { std::cerr << "CXXLAPACK: V_generic = " << V_generic << std::endl; std::cerr << "F77LAPACK: V = " << V << std::endl; failed = true; } if (! isIdentical(T_generic, T, "T_generic", "T")) { std::cerr << "CXXLAPACK: T_generic = " << T_generic << std::endl; std::cerr << "F77LAPACK: T = " << T << std::endl; failed = true; } if (! isIdentical(WV_generic, WV, "WV_generic", "WV")) { std::cerr << "CXXLAPACK: WV_generic = " << WV_generic << std::endl; std::cerr << "F77LAPACK: WV = " << WV << std::endl; failed = true; } if (! isIdentical(work_generic, work, "work_generic", "work")) { std::cerr << "CXXLAPACK: work_generic = " << work_generic << std::endl; std::cerr << "F77LAPACK: work = " << work << std::endl; failed = true; } if (failed) { std::cerr << "error in: laqr3.tcc" << std::endl; ASSERT(0); } else { // std::cerr << "passed: laqr3.tcc" << std::endl; } # endif } //-- forwarding ---------------------------------------------------------------- template <typename IndexType, typename MT> IndexType laqr3_wsq(IndexType kTop, IndexType kBot, IndexType nw, const MT &&T) { CHECKPOINT_ENTER; const IndexType info = laqr3_wsq(kTop, kBot, nw, T); CHECKPOINT_LEAVE; return info; } template <typename IndexType, typename MH, typename MZ, typename VSR, typename VSI, typename MV, typename MT, typename MWV, typename VWORK> void laqr3(bool wantT, bool wantZ, IndexType kTop, IndexType kBot, IndexType nw, MH &&H, IndexType iLoZ, IndexType iHiZ, MZ &&Z, IndexType &ns, IndexType &nd, VSR &&sr, VSI &&si, MV &&V, MT &&T, MWV &&WV, VWORK &&work) { CHECKPOINT_ENTER; laqr3(wantT, wantZ, kTop, kBot, nw, H, iLoZ, iHiZ, Z, ns, nd, sr, si, V, T, WV, work); CHECKPOINT_LEAVE; } } } // namespace lapack, flens #endif // FLENS_LAPACK_LA_LAQR3_TCC |