zlalsd.c
Go to the documentation of this file.
00001 /* zlalsd.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static doublecomplex c_b1 = {0.,0.};
00019 static integer c__1 = 1;
00020 static integer c__0 = 0;
00021 static doublereal c_b10 = 1.;
00022 static doublereal c_b35 = 0.;
00023 
00024 /* Subroutine */ int zlalsd_(char *uplo, integer *smlsiz, integer *n, integer 
00025         *nrhs, doublereal *d__, doublereal *e, doublecomplex *b, integer *ldb, 
00026          doublereal *rcond, integer *rank, doublecomplex *work, doublereal *
00027         rwork, integer *iwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00031     doublereal d__1;
00032     doublecomplex z__1;
00033 
00034     /* Builtin functions */
00035     double d_imag(doublecomplex *), log(doublereal), d_sign(doublereal *, 
00036             doublereal *);
00037 
00038     /* Local variables */
00039     integer c__, i__, j, k;
00040     doublereal r__;
00041     integer s, u, z__;
00042     doublereal cs;
00043     integer bx;
00044     doublereal sn;
00045     integer st, vt, nm1, st1;
00046     doublereal eps;
00047     integer iwk;
00048     doublereal tol;
00049     integer difl, difr;
00050     doublereal rcnd;
00051     integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu, jimag;
00052     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, 
00053             integer *, doublereal *, doublereal *, integer *, doublereal *, 
00054             integer *, doublereal *, doublereal *, integer *);
00055     integer jreal, irwib, poles, sizei, irwrb, nsize;
00056     extern /* Subroutine */ int zdrot_(integer *, doublecomplex *, integer *, 
00057             doublecomplex *, integer *, doublereal *, doublereal *), zcopy_(
00058             integer *, doublecomplex *, integer *, doublecomplex *, integer *)
00059             ;
00060     integer irwvt, icmpq1, icmpq2;
00061     extern doublereal dlamch_(char *);
00062     extern /* Subroutine */ int dlasda_(integer *, integer *, integer *, 
00063             integer *, doublereal *, doublereal *, doublereal *, integer *, 
00064             doublereal *, integer *, doublereal *, doublereal *, doublereal *, 
00065              doublereal *, integer *, integer *, integer *, integer *, 
00066             doublereal *, doublereal *, doublereal *, doublereal *, integer *, 
00067              integer *), dlascl_(char *, integer *, integer *, doublereal *, 
00068             doublereal *, integer *, integer *, doublereal *, integer *, 
00069             integer *);
00070     extern integer idamax_(integer *, doublereal *, integer *);
00071     extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer 
00072             *, integer *, integer *, doublereal *, doublereal *, doublereal *, 
00073              integer *, doublereal *, integer *, doublereal *, integer *, 
00074             doublereal *, integer *), dlaset_(char *, integer *, 
00075             integer *, doublereal *, doublereal *, doublereal *, integer *), dlartg_(doublereal *, doublereal *, doublereal *, 
00076             doublereal *, doublereal *), xerbla_(char *, integer *);
00077     integer givcol;
00078     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00079     extern /* Subroutine */ int zlalsa_(integer *, integer *, integer *, 
00080             integer *, doublecomplex *, integer *, doublecomplex *, integer *, 
00081              doublereal *, integer *, doublereal *, integer *, doublereal *, 
00082             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00083             integer *, integer *, doublereal *, doublereal *, doublereal *, 
00084             doublereal *, integer *, integer *), zlascl_(char *, integer *, 
00085             integer *, doublereal *, doublereal *, integer *, integer *, 
00086             doublecomplex *, integer *, integer *), dlasrt_(char *, 
00087             integer *, doublereal *, integer *), zlacpy_(char *, 
00088             integer *, integer *, doublecomplex *, integer *, doublecomplex *, 
00089              integer *), zlaset_(char *, integer *, integer *, 
00090             doublecomplex *, doublecomplex *, doublecomplex *, integer *);
00091     doublereal orgnrm;
00092     integer givnum, givptr, nrwork, irwwrk, smlszp;
00093 
00094 
00095 /*  -- LAPACK routine (version 3.2) -- */
00096 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00097 /*     November 2006 */
00098 
00099 /*     .. Scalar Arguments .. */
00100 /*     .. */
00101 /*     .. Array Arguments .. */
00102 /*     .. */
00103 
00104 /*  Purpose */
00105 /*  ======= */
00106 
00107 /*  ZLALSD uses the singular value decomposition of A to solve the least */
00108 /*  squares problem of finding X to minimize the Euclidean norm of each */
00109 /*  column of A*X-B, where A is N-by-N upper bidiagonal, and X and B */
00110 /*  are N-by-NRHS. The solution X overwrites B. */
00111 
00112 /*  The singular values of A smaller than RCOND times the largest */
00113 /*  singular value are treated as zero in solving the least squares */
00114 /*  problem; in this case a minimum norm solution is returned. */
00115 /*  The actual singular values are returned in D in ascending order. */
00116 
00117 /*  This code makes very mild assumptions about floating point */
00118 /*  arithmetic. It will work on machines with a guard digit in */
00119 /*  add/subtract, or on those binary machines without guard digits */
00120 /*  which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
00121 /*  It could conceivably fail on hexadecimal or decimal machines */
00122 /*  without guard digits, but we know of none. */
00123 
00124 /*  Arguments */
00125 /*  ========= */
00126 
00127 /*  UPLO   (input) CHARACTER*1 */
00128 /*         = 'U': D and E define an upper bidiagonal matrix. */
00129 /*         = 'L': D and E define a  lower bidiagonal matrix. */
00130 
00131 /*  SMLSIZ (input) INTEGER */
00132 /*         The maximum size of the subproblems at the bottom of the */
00133 /*         computation tree. */
00134 
00135 /*  N      (input) INTEGER */
00136 /*         The dimension of the  bidiagonal matrix.  N >= 0. */
00137 
00138 /*  NRHS   (input) INTEGER */
00139 /*         The number of columns of B. NRHS must be at least 1. */
00140 
00141 /*  D      (input/output) DOUBLE PRECISION array, dimension (N) */
00142 /*         On entry D contains the main diagonal of the bidiagonal */
00143 /*         matrix. On exit, if INFO = 0, D contains its singular values. */
00144 
00145 /*  E      (input/output) DOUBLE PRECISION array, dimension (N-1) */
00146 /*         Contains the super-diagonal entries of the bidiagonal matrix. */
00147 /*         On exit, E has been destroyed. */
00148 
00149 /*  B      (input/output) COMPLEX*16 array, dimension (LDB,NRHS) */
00150 /*         On input, B contains the right hand sides of the least */
00151 /*         squares problem. On output, B contains the solution X. */
00152 
00153 /*  LDB    (input) INTEGER */
00154 /*         The leading dimension of B in the calling subprogram. */
00155 /*         LDB must be at least max(1,N). */
00156 
00157 /*  RCOND  (input) DOUBLE PRECISION */
00158 /*         The singular values of A less than or equal to RCOND times */
00159 /*         the largest singular value are treated as zero in solving */
00160 /*         the least squares problem. If RCOND is negative, */
00161 /*         machine precision is used instead. */
00162 /*         For example, if diag(S)*X=B were the least squares problem, */
00163 /*         where diag(S) is a diagonal matrix of singular values, the */
00164 /*         solution would be X(i) = B(i) / S(i) if S(i) is greater than */
00165 /*         RCOND*max(S), and X(i) = 0 if S(i) is less than or equal to */
00166 /*         RCOND*max(S). */
00167 
00168 /*  RANK   (output) INTEGER */
00169 /*         The number of singular values of A greater than RCOND times */
00170 /*         the largest singular value. */
00171 
00172 /*  WORK   (workspace) COMPLEX*16 array, dimension at least */
00173 /*         (N * NRHS). */
00174 
00175 /*  RWORK  (workspace) DOUBLE PRECISION array, dimension at least */
00176 /*         (9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + (SMLSIZ+1)**2), */
00177 /*         where */
00178 /*         NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
00179 
00180 /*  IWORK  (workspace) INTEGER array, dimension at least */
00181 /*         (3*N*NLVL + 11*N). */
00182 
00183 /*  INFO   (output) INTEGER */
00184 /*         = 0:  successful exit. */
00185 /*         < 0:  if INFO = -i, the i-th argument had an illegal value. */
00186 /*         > 0:  The algorithm failed to compute an singular value while */
00187 /*               working on the submatrix lying in rows and columns */
00188 /*               INFO/(N+1) through MOD(INFO,N+1). */
00189 
00190 /*  Further Details */
00191 /*  =============== */
00192 
00193 /*  Based on contributions by */
00194 /*     Ming Gu and Ren-Cang Li, Computer Science Division, University of */
00195 /*       California at Berkeley, USA */
00196 /*     Osni Marques, LBNL/NERSC, USA */
00197 
00198 /*  ===================================================================== */
00199 
00200 /*     .. Parameters .. */
00201 /*     .. */
00202 /*     .. Local Scalars .. */
00203 /*     .. */
00204 /*     .. External Functions .. */
00205 /*     .. */
00206 /*     .. External Subroutines .. */
00207 /*     .. */
00208 /*     .. Intrinsic Functions .. */
00209 /*     .. */
00210 /*     .. Executable Statements .. */
00211 
00212 /*     Test the input parameters. */
00213 
00214     /* Parameter adjustments */
00215     --d__;
00216     --e;
00217     b_dim1 = *ldb;
00218     b_offset = 1 + b_dim1;
00219     b -= b_offset;
00220     --work;
00221     --rwork;
00222     --iwork;
00223 
00224     /* Function Body */
00225     *info = 0;
00226 
00227     if (*n < 0) {
00228         *info = -3;
00229     } else if (*nrhs < 1) {
00230         *info = -4;
00231     } else if (*ldb < 1 || *ldb < *n) {
00232         *info = -8;
00233     }
00234     if (*info != 0) {
00235         i__1 = -(*info);
00236         xerbla_("ZLALSD", &i__1);
00237         return 0;
00238     }
00239 
00240     eps = dlamch_("Epsilon");
00241 
00242 /*     Set up the tolerance. */
00243 
00244     if (*rcond <= 0. || *rcond >= 1.) {
00245         rcnd = eps;
00246     } else {
00247         rcnd = *rcond;
00248     }
00249 
00250     *rank = 0;
00251 
00252 /*     Quick return if possible. */
00253 
00254     if (*n == 0) {
00255         return 0;
00256     } else if (*n == 1) {
00257         if (d__[1] == 0.) {
00258             zlaset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00259         } else {
00260             *rank = 1;
00261             zlascl_("G", &c__0, &c__0, &d__[1], &c_b10, &c__1, nrhs, &b[
00262                     b_offset], ldb, info);
00263             d__[1] = abs(d__[1]);
00264         }
00265         return 0;
00266     }
00267 
00268 /*     Rotate the matrix if it is lower bidiagonal. */
00269 
00270     if (*(unsigned char *)uplo == 'L') {
00271         i__1 = *n - 1;
00272         for (i__ = 1; i__ <= i__1; ++i__) {
00273             dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
00274             d__[i__] = r__;
00275             e[i__] = sn * d__[i__ + 1];
00276             d__[i__ + 1] = cs * d__[i__ + 1];
00277             if (*nrhs == 1) {
00278                 zdrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
00279                         c__1, &cs, &sn);
00280             } else {
00281                 rwork[(i__ << 1) - 1] = cs;
00282                 rwork[i__ * 2] = sn;
00283             }
00284 /* L10: */
00285         }
00286         if (*nrhs > 1) {
00287             i__1 = *nrhs;
00288             for (i__ = 1; i__ <= i__1; ++i__) {
00289                 i__2 = *n - 1;
00290                 for (j = 1; j <= i__2; ++j) {
00291                     cs = rwork[(j << 1) - 1];
00292                     sn = rwork[j * 2];
00293                     zdrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__ 
00294                             * b_dim1], &c__1, &cs, &sn);
00295 /* L20: */
00296                 }
00297 /* L30: */
00298             }
00299         }
00300     }
00301 
00302 /*     Scale. */
00303 
00304     nm1 = *n - 1;
00305     orgnrm = dlanst_("M", n, &d__[1], &e[1]);
00306     if (orgnrm == 0.) {
00307         zlaset_("A", n, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00308         return 0;
00309     }
00310 
00311     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, &c__1, &d__[1], n, info);
00312     dlascl_("G", &c__0, &c__0, &orgnrm, &c_b10, &nm1, &c__1, &e[1], &nm1, 
00313             info);
00314 
00315 /*     If N is smaller than the minimum divide size SMLSIZ, then solve */
00316 /*     the problem with another solver. */
00317 
00318     if (*n <= *smlsiz) {
00319         irwu = 1;
00320         irwvt = irwu + *n * *n;
00321         irwwrk = irwvt + *n * *n;
00322         irwrb = irwwrk;
00323         irwib = irwrb + *n * *nrhs;
00324         irwb = irwib + *n * *nrhs;
00325         dlaset_("A", n, n, &c_b35, &c_b10, &rwork[irwu], n);
00326         dlaset_("A", n, n, &c_b35, &c_b10, &rwork[irwvt], n);
00327         dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n, 
00328                 &rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info);
00329         if (*info != 0) {
00330             return 0;
00331         }
00332 
00333 /*        In the real version, B is passed to DLASDQ and multiplied */
00334 /*        internally by Q'. Here B is complex and that product is */
00335 /*        computed below in two steps (real and imaginary parts). */
00336 
00337         j = irwb - 1;
00338         i__1 = *nrhs;
00339         for (jcol = 1; jcol <= i__1; ++jcol) {
00340             i__2 = *n;
00341             for (jrow = 1; jrow <= i__2; ++jrow) {
00342                 ++j;
00343                 i__3 = jrow + jcol * b_dim1;
00344                 rwork[j] = b[i__3].r;
00345 /* L40: */
00346             }
00347 /* L50: */
00348         }
00349         dgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, 
00350                  &c_b35, &rwork[irwrb], n);
00351         j = irwb - 1;
00352         i__1 = *nrhs;
00353         for (jcol = 1; jcol <= i__1; ++jcol) {
00354             i__2 = *n;
00355             for (jrow = 1; jrow <= i__2; ++jrow) {
00356                 ++j;
00357                 rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
00358 /* L60: */
00359             }
00360 /* L70: */
00361         }
00362         dgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, 
00363                  &c_b35, &rwork[irwib], n);
00364         jreal = irwrb - 1;
00365         jimag = irwib - 1;
00366         i__1 = *nrhs;
00367         for (jcol = 1; jcol <= i__1; ++jcol) {
00368             i__2 = *n;
00369             for (jrow = 1; jrow <= i__2; ++jrow) {
00370                 ++jreal;
00371                 ++jimag;
00372                 i__3 = jrow + jcol * b_dim1;
00373                 i__4 = jreal;
00374                 i__5 = jimag;
00375                 z__1.r = rwork[i__4], z__1.i = rwork[i__5];
00376                 b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00377 /* L80: */
00378             }
00379 /* L90: */
00380         }
00381 
00382         tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
00383         i__1 = *n;
00384         for (i__ = 1; i__ <= i__1; ++i__) {
00385             if (d__[i__] <= tol) {
00386                 zlaset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb);
00387             } else {
00388                 zlascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &b[
00389                         i__ + b_dim1], ldb, info);
00390                 ++(*rank);
00391             }
00392 /* L100: */
00393         }
00394 
00395 /*        Since B is complex, the following call to DGEMM is performed */
00396 /*        in two steps (real and imaginary parts). That is for V * B */
00397 /*        (in the real version of the code V' is stored in WORK). */
00398 
00399 /*        CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, */
00400 /*    $               WORK( NWORK ), N ) */
00401 
00402         j = irwb - 1;
00403         i__1 = *nrhs;
00404         for (jcol = 1; jcol <= i__1; ++jcol) {
00405             i__2 = *n;
00406             for (jrow = 1; jrow <= i__2; ++jrow) {
00407                 ++j;
00408                 i__3 = jrow + jcol * b_dim1;
00409                 rwork[j] = b[i__3].r;
00410 /* L110: */
00411             }
00412 /* L120: */
00413         }
00414         dgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], 
00415                 n, &c_b35, &rwork[irwrb], n);
00416         j = irwb - 1;
00417         i__1 = *nrhs;
00418         for (jcol = 1; jcol <= i__1; ++jcol) {
00419             i__2 = *n;
00420             for (jrow = 1; jrow <= i__2; ++jrow) {
00421                 ++j;
00422                 rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
00423 /* L130: */
00424             }
00425 /* L140: */
00426         }
00427         dgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], 
00428                 n, &c_b35, &rwork[irwib], n);
00429         jreal = irwrb - 1;
00430         jimag = irwib - 1;
00431         i__1 = *nrhs;
00432         for (jcol = 1; jcol <= i__1; ++jcol) {
00433             i__2 = *n;
00434             for (jrow = 1; jrow <= i__2; ++jrow) {
00435                 ++jreal;
00436                 ++jimag;
00437                 i__3 = jrow + jcol * b_dim1;
00438                 i__4 = jreal;
00439                 i__5 = jimag;
00440                 z__1.r = rwork[i__4], z__1.i = rwork[i__5];
00441                 b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00442 /* L150: */
00443             }
00444 /* L160: */
00445         }
00446 
00447 /*        Unscale. */
00448 
00449         dlascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, 
00450                 info);
00451         dlasrt_("D", n, &d__[1], info);
00452         zlascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], 
00453                 ldb, info);
00454 
00455         return 0;
00456     }
00457 
00458 /*     Book-keeping and setting up some constants. */
00459 
00460     nlvl = (integer) (log((doublereal) (*n) / (doublereal) (*smlsiz + 1)) / 
00461             log(2.)) + 1;
00462 
00463     smlszp = *smlsiz + 1;
00464 
00465     u = 1;
00466     vt = *smlsiz * *n + 1;
00467     difl = vt + smlszp * *n;
00468     difr = difl + nlvl * *n;
00469     z__ = difr + (nlvl * *n << 1);
00470     c__ = z__ + nlvl * *n;
00471     s = c__ + *n;
00472     poles = s + *n;
00473     givnum = poles + (nlvl << 1) * *n;
00474     nrwork = givnum + (nlvl << 1) * *n;
00475     bx = 1;
00476 
00477     irwrb = nrwork;
00478     irwib = irwrb + *smlsiz * *nrhs;
00479     irwb = irwib + *smlsiz * *nrhs;
00480 
00481     sizei = *n + 1;
00482     k = sizei + *n;
00483     givptr = k + *n;
00484     perm = givptr + *n;
00485     givcol = perm + nlvl * *n;
00486     iwk = givcol + (nlvl * *n << 1);
00487 
00488     st = 1;
00489     sqre = 0;
00490     icmpq1 = 1;
00491     icmpq2 = 0;
00492     nsub = 0;
00493 
00494     i__1 = *n;
00495     for (i__ = 1; i__ <= i__1; ++i__) {
00496         if ((d__1 = d__[i__], abs(d__1)) < eps) {
00497             d__[i__] = d_sign(&eps, &d__[i__]);
00498         }
00499 /* L170: */
00500     }
00501 
00502     i__1 = nm1;
00503     for (i__ = 1; i__ <= i__1; ++i__) {
00504         if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
00505             ++nsub;
00506             iwork[nsub] = st;
00507 
00508 /*           Subproblem found. First determine its size and then */
00509 /*           apply divide and conquer on it. */
00510 
00511             if (i__ < nm1) {
00512 
00513 /*              A subproblem with E(I) small for I < NM1. */
00514 
00515                 nsize = i__ - st + 1;
00516                 iwork[sizei + nsub - 1] = nsize;
00517             } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
00518 
00519 /*              A subproblem with E(NM1) not too small but I = NM1. */
00520 
00521                 nsize = *n - st + 1;
00522                 iwork[sizei + nsub - 1] = nsize;
00523             } else {
00524 
00525 /*              A subproblem with E(NM1) small. This implies an */
00526 /*              1-by-1 subproblem at D(N), which is not solved */
00527 /*              explicitly. */
00528 
00529                 nsize = i__ - st + 1;
00530                 iwork[sizei + nsub - 1] = nsize;
00531                 ++nsub;
00532                 iwork[nsub] = *n;
00533                 iwork[sizei + nsub - 1] = 1;
00534                 zcopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
00535             }
00536             st1 = st - 1;
00537             if (nsize == 1) {
00538 
00539 /*              This is a 1-by-1 subproblem and is not solved */
00540 /*              explicitly. */
00541 
00542                 zcopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
00543             } else if (nsize <= *smlsiz) {
00544 
00545 /*              This is a small subproblem and is solved by DLASDQ. */
00546 
00547                 dlaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[vt + st1], 
00548                          n);
00549                 dlaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[u + st1], 
00550                         n);
00551                 dlasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], &
00552                         e[st], &rwork[vt + st1], n, &rwork[u + st1], n, &
00553                         rwork[nrwork], &c__1, &rwork[nrwork], info)
00554                         ;
00555                 if (*info != 0) {
00556                     return 0;
00557                 }
00558 
00559 /*              In the real version, B is passed to DLASDQ and multiplied */
00560 /*              internally by Q'. Here B is complex and that product is */
00561 /*              computed below in two steps (real and imaginary parts). */
00562 
00563                 j = irwb - 1;
00564                 i__2 = *nrhs;
00565                 for (jcol = 1; jcol <= i__2; ++jcol) {
00566                     i__3 = st + nsize - 1;
00567                     for (jrow = st; jrow <= i__3; ++jrow) {
00568                         ++j;
00569                         i__4 = jrow + jcol * b_dim1;
00570                         rwork[j] = b[i__4].r;
00571 /* L180: */
00572                     }
00573 /* L190: */
00574                 }
00575                 dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
00576 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &
00577                         nsize);
00578                 j = irwb - 1;
00579                 i__2 = *nrhs;
00580                 for (jcol = 1; jcol <= i__2; ++jcol) {
00581                     i__3 = st + nsize - 1;
00582                     for (jrow = st; jrow <= i__3; ++jrow) {
00583                         ++j;
00584                         rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
00585 /* L200: */
00586                     }
00587 /* L210: */
00588                 }
00589                 dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
00590 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &
00591                         nsize);
00592                 jreal = irwrb - 1;
00593                 jimag = irwib - 1;
00594                 i__2 = *nrhs;
00595                 for (jcol = 1; jcol <= i__2; ++jcol) {
00596                     i__3 = st + nsize - 1;
00597                     for (jrow = st; jrow <= i__3; ++jrow) {
00598                         ++jreal;
00599                         ++jimag;
00600                         i__4 = jrow + jcol * b_dim1;
00601                         i__5 = jreal;
00602                         i__6 = jimag;
00603                         z__1.r = rwork[i__5], z__1.i = rwork[i__6];
00604                         b[i__4].r = z__1.r, b[i__4].i = z__1.i;
00605 /* L220: */
00606                     }
00607 /* L230: */
00608                 }
00609 
00610                 zlacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx + 
00611                         st1], n);
00612             } else {
00613 
00614 /*              A large problem. Solve it using divide and conquer. */
00615 
00616                 dlasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
00617                         rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1], 
00618                         &rwork[difl + st1], &rwork[difr + st1], &rwork[z__ + 
00619                         st1], &rwork[poles + st1], &iwork[givptr + st1], &
00620                         iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
00621                         givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &
00622                         rwork[nrwork], &iwork[iwk], info);
00623                 if (*info != 0) {
00624                     return 0;
00625                 }
00626                 bxst = bx + st1;
00627                 zlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
00628                         work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], &
00629                         iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1]
00630 , &rwork[z__ + st1], &rwork[poles + st1], &iwork[
00631                         givptr + st1], &iwork[givcol + st1], n, &iwork[perm + 
00632                         st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[
00633                         s + st1], &rwork[nrwork], &iwork[iwk], info);
00634                 if (*info != 0) {
00635                     return 0;
00636                 }
00637             }
00638             st = i__ + 1;
00639         }
00640 /* L240: */
00641     }
00642 
00643 /*     Apply the singular values and treat the tiny ones as zero. */
00644 
00645     tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
00646 
00647     i__1 = *n;
00648     for (i__ = 1; i__ <= i__1; ++i__) {
00649 
00650 /*        Some of the elements in D can be negative because 1-by-1 */
00651 /*        subproblems were not solved explicitly. */
00652 
00653         if ((d__1 = d__[i__], abs(d__1)) <= tol) {
00654             zlaset_("A", &c__1, nrhs, &c_b1, &c_b1, &work[bx + i__ - 1], n);
00655         } else {
00656             ++(*rank);
00657             zlascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &work[
00658                     bx + i__ - 1], n, info);
00659         }
00660         d__[i__] = (d__1 = d__[i__], abs(d__1));
00661 /* L250: */
00662     }
00663 
00664 /*     Now apply back the right singular vectors. */
00665 
00666     icmpq2 = 1;
00667     i__1 = nsub;
00668     for (i__ = 1; i__ <= i__1; ++i__) {
00669         st = iwork[i__];
00670         st1 = st - 1;
00671         nsize = iwork[sizei + i__ - 1];
00672         bxst = bx + st1;
00673         if (nsize == 1) {
00674             zcopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
00675         } else if (nsize <= *smlsiz) {
00676 
00677 /*           Since B and BX are complex, the following call to DGEMM */
00678 /*           is performed in two steps (real and imaginary parts). */
00679 
00680 /*           CALL DGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, */
00681 /*    $                  RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO, */
00682 /*    $                  B( ST, 1 ), LDB ) */
00683 
00684             j = bxst - *n - 1;
00685             jreal = irwb - 1;
00686             i__2 = *nrhs;
00687             for (jcol = 1; jcol <= i__2; ++jcol) {
00688                 j += *n;
00689                 i__3 = nsize;
00690                 for (jrow = 1; jrow <= i__3; ++jrow) {
00691                     ++jreal;
00692                     i__4 = j + jrow;
00693                     rwork[jreal] = work[i__4].r;
00694 /* L260: */
00695                 }
00696 /* L270: */
00697             }
00698             dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], 
00699                     n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &nsize);
00700             j = bxst - *n - 1;
00701             jimag = irwb - 1;
00702             i__2 = *nrhs;
00703             for (jcol = 1; jcol <= i__2; ++jcol) {
00704                 j += *n;
00705                 i__3 = nsize;
00706                 for (jrow = 1; jrow <= i__3; ++jrow) {
00707                     ++jimag;
00708                     rwork[jimag] = d_imag(&work[j + jrow]);
00709 /* L280: */
00710                 }
00711 /* L290: */
00712             }
00713             dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], 
00714                     n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &nsize);
00715             jreal = irwrb - 1;
00716             jimag = irwib - 1;
00717             i__2 = *nrhs;
00718             for (jcol = 1; jcol <= i__2; ++jcol) {
00719                 i__3 = st + nsize - 1;
00720                 for (jrow = st; jrow <= i__3; ++jrow) {
00721                     ++jreal;
00722                     ++jimag;
00723                     i__4 = jrow + jcol * b_dim1;
00724                     i__5 = jreal;
00725                     i__6 = jimag;
00726                     z__1.r = rwork[i__5], z__1.i = rwork[i__6];
00727                     b[i__4].r = z__1.r, b[i__4].i = z__1.i;
00728 /* L300: */
00729                 }
00730 /* L310: */
00731             }
00732         } else {
00733             zlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st + 
00734                     b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], &
00735                     iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &
00736                     rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr + 
00737                     st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
00738                     givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[
00739                     nrwork], &iwork[iwk], info);
00740             if (*info != 0) {
00741                 return 0;
00742             }
00743         }
00744 /* L320: */
00745     }
00746 
00747 /*     Unscale and sort the singular values. */
00748 
00749     dlascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info);
00750     dlasrt_("D", n, &d__[1], info);
00751     zlascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb, 
00752             info);
00753 
00754     return 0;
00755 
00756 /*     End of ZLALSD */
00757 
00758 } /* zlalsd_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:41