clalsd.c
Go to the documentation of this file.
00001 /* clalsd.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 complex c_b1 = {0.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c__0 = 0;
00021 static real c_b10 = 1.f;
00022 static real c_b35 = 0.f;
00023 
00024 /* Subroutine */ int clalsd_(char *uplo, integer *smlsiz, integer *n, integer 
00025         *nrhs, real *d__, real *e, complex *b, integer *ldb, real *rcond, 
00026         integer *rank, complex *work, real *rwork, integer *iwork, integer *
00027         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     real r__1;
00032     complex q__1;
00033 
00034     /* Builtin functions */
00035     double r_imag(complex *), log(doublereal), r_sign(real *, real *);
00036 
00037     /* Local variables */
00038     integer c__, i__, j, k;
00039     real r__;
00040     integer s, u, z__;
00041     real cs;
00042     integer bx;
00043     real sn;
00044     integer st, vt, nm1, st1;
00045     real eps;
00046     integer iwk;
00047     real tol;
00048     integer difl, difr;
00049     real rcnd;
00050     integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu, jimag, 
00051             jreal;
00052     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00053             integer *, real *, real *, integer *, real *, integer *, real *, 
00054             real *, integer *);
00055     integer irwib;
00056     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00057             complex *, integer *);
00058     integer poles, sizei, irwrb, nsize;
00059     extern /* Subroutine */ int csrot_(integer *, complex *, integer *, 
00060             complex *, integer *, real *, real *);
00061     integer irwvt, icmpq1, icmpq2;
00062     extern /* Subroutine */ int clalsa_(integer *, integer *, integer *, 
00063             integer *, complex *, integer *, complex *, integer *, real *, 
00064             integer *, real *, integer *, real *, real *, real *, real *, 
00065             integer *, integer *, integer *, integer *, real *, real *, real *
00066 , real *, integer *, integer *), clascl_(char *, integer *, 
00067             integer *, real *, real *, integer *, integer *, complex *, 
00068             integer *, integer *);
00069     extern doublereal slamch_(char *);
00070     extern /* Subroutine */ int slasda_(integer *, integer *, integer *, 
00071             integer *, real *, real *, real *, integer *, real *, integer *, 
00072             real *, real *, real *, real *, integer *, integer *, integer *, 
00073             integer *, real *, real *, real *, real *, integer *, integer *), 
00074             clacpy_(char *, integer *, integer *, complex *, integer *, 
00075             complex *, integer *), claset_(char *, integer *, integer 
00076             *, complex *, complex *, complex *, integer *), xerbla_(
00077             char *, integer *), slascl_(char *, integer *, integer *, 
00078             real *, real *, integer *, integer *, real *, integer *, integer *
00079 );
00080     extern integer isamax_(integer *, real *, integer *);
00081     integer givcol;
00082     extern /* Subroutine */ int slasdq_(char *, integer *, integer *, integer 
00083             *, integer *, integer *, real *, real *, real *, integer *, real *
00084 , integer *, real *, integer *, real *, integer *), 
00085             slaset_(char *, integer *, integer *, real *, real *, real *, 
00086             integer *), slartg_(real *, real *, real *, real *, real *
00087 );
00088     real orgnrm;
00089     integer givnum;
00090     extern doublereal slanst_(char *, integer *, real *, real *);
00091     extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *);
00092     integer 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 /*  CLALSD 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) REAL 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) REAL 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 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) REAL */
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 array, dimension (N * NRHS). */
00173 
00174 /*  RWORK  (workspace) REAL array, dimension at least */
00175 /*         (9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + (SMLSIZ+1)**2), */
00176 /*         where */
00177 /*         NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
00178 
00179 /*  IWORK  (workspace) INTEGER array, dimension (3*N*NLVL + 11*N). */
00180 
00181 /*  INFO   (output) INTEGER */
00182 /*         = 0:  successful exit. */
00183 /*         < 0:  if INFO = -i, the i-th argument had an illegal value. */
00184 /*         > 0:  The algorithm failed to compute an singular value while */
00185 /*               working on the submatrix lying in rows and columns */
00186 /*               INFO/(N+1) through MOD(INFO,N+1). */
00187 
00188 /*  Further Details */
00189 /*  =============== */
00190 
00191 /*  Based on contributions by */
00192 /*     Ming Gu and Ren-Cang Li, Computer Science Division, University of */
00193 /*       California at Berkeley, USA */
00194 /*     Osni Marques, LBNL/NERSC, USA */
00195 
00196 /*  ===================================================================== */
00197 
00198 /*     .. Parameters .. */
00199 /*     .. */
00200 /*     .. Local Scalars .. */
00201 /*     .. */
00202 /*     .. External Functions .. */
00203 /*     .. */
00204 /*     .. External Subroutines .. */
00205 /*     .. */
00206 /*     .. Intrinsic Functions .. */
00207 /*     .. */
00208 /*     .. Executable Statements .. */
00209 
00210 /*     Test the input parameters. */
00211 
00212     /* Parameter adjustments */
00213     --d__;
00214     --e;
00215     b_dim1 = *ldb;
00216     b_offset = 1 + b_dim1;
00217     b -= b_offset;
00218     --work;
00219     --rwork;
00220     --iwork;
00221 
00222     /* Function Body */
00223     *info = 0;
00224 
00225     if (*n < 0) {
00226         *info = -3;
00227     } else if (*nrhs < 1) {
00228         *info = -4;
00229     } else if (*ldb < 1 || *ldb < *n) {
00230         *info = -8;
00231     }
00232     if (*info != 0) {
00233         i__1 = -(*info);
00234         xerbla_("CLALSD", &i__1);
00235         return 0;
00236     }
00237 
00238     eps = slamch_("Epsilon");
00239 
00240 /*     Set up the tolerance. */
00241 
00242     if (*rcond <= 0.f || *rcond >= 1.f) {
00243         rcnd = eps;
00244     } else {
00245         rcnd = *rcond;
00246     }
00247 
00248     *rank = 0;
00249 
00250 /*     Quick return if possible. */
00251 
00252     if (*n == 0) {
00253         return 0;
00254     } else if (*n == 1) {
00255         if (d__[1] == 0.f) {
00256             claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00257         } else {
00258             *rank = 1;
00259             clascl_("G", &c__0, &c__0, &d__[1], &c_b10, &c__1, nrhs, &b[
00260                     b_offset], ldb, info);
00261             d__[1] = dabs(d__[1]);
00262         }
00263         return 0;
00264     }
00265 
00266 /*     Rotate the matrix if it is lower bidiagonal. */
00267 
00268     if (*(unsigned char *)uplo == 'L') {
00269         i__1 = *n - 1;
00270         for (i__ = 1; i__ <= i__1; ++i__) {
00271             slartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
00272             d__[i__] = r__;
00273             e[i__] = sn * d__[i__ + 1];
00274             d__[i__ + 1] = cs * d__[i__ + 1];
00275             if (*nrhs == 1) {
00276                 csrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
00277                         c__1, &cs, &sn);
00278             } else {
00279                 rwork[(i__ << 1) - 1] = cs;
00280                 rwork[i__ * 2] = sn;
00281             }
00282 /* L10: */
00283         }
00284         if (*nrhs > 1) {
00285             i__1 = *nrhs;
00286             for (i__ = 1; i__ <= i__1; ++i__) {
00287                 i__2 = *n - 1;
00288                 for (j = 1; j <= i__2; ++j) {
00289                     cs = rwork[(j << 1) - 1];
00290                     sn = rwork[j * 2];
00291                     csrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__ 
00292                             * b_dim1], &c__1, &cs, &sn);
00293 /* L20: */
00294                 }
00295 /* L30: */
00296             }
00297         }
00298     }
00299 
00300 /*     Scale. */
00301 
00302     nm1 = *n - 1;
00303     orgnrm = slanst_("M", n, &d__[1], &e[1]);
00304     if (orgnrm == 0.f) {
00305         claset_("A", n, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00306         return 0;
00307     }
00308 
00309     slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, &c__1, &d__[1], n, info);
00310     slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, &nm1, &c__1, &e[1], &nm1, 
00311             info);
00312 
00313 /*     If N is smaller than the minimum divide size SMLSIZ, then solve */
00314 /*     the problem with another solver. */
00315 
00316     if (*n <= *smlsiz) {
00317         irwu = 1;
00318         irwvt = irwu + *n * *n;
00319         irwwrk = irwvt + *n * *n;
00320         irwrb = irwwrk;
00321         irwib = irwrb + *n * *nrhs;
00322         irwb = irwib + *n * *nrhs;
00323         slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwu], n);
00324         slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwvt], n);
00325         slasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n, 
00326                 &rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info);
00327         if (*info != 0) {
00328             return 0;
00329         }
00330 
00331 /*        In the real version, B is passed to SLASDQ and multiplied */
00332 /*        internally by Q'. Here B is complex and that product is */
00333 /*        computed below in two steps (real and imaginary parts). */
00334 
00335         j = irwb - 1;
00336         i__1 = *nrhs;
00337         for (jcol = 1; jcol <= i__1; ++jcol) {
00338             i__2 = *n;
00339             for (jrow = 1; jrow <= i__2; ++jrow) {
00340                 ++j;
00341                 i__3 = jrow + jcol * b_dim1;
00342                 rwork[j] = b[i__3].r;
00343 /* L40: */
00344             }
00345 /* L50: */
00346         }
00347         sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, 
00348                  &c_b35, &rwork[irwrb], n);
00349         j = irwb - 1;
00350         i__1 = *nrhs;
00351         for (jcol = 1; jcol <= i__1; ++jcol) {
00352             i__2 = *n;
00353             for (jrow = 1; jrow <= i__2; ++jrow) {
00354                 ++j;
00355                 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
00356 /* L60: */
00357             }
00358 /* L70: */
00359         }
00360         sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, 
00361                  &c_b35, &rwork[irwib], n);
00362         jreal = irwrb - 1;
00363         jimag = irwib - 1;
00364         i__1 = *nrhs;
00365         for (jcol = 1; jcol <= i__1; ++jcol) {
00366             i__2 = *n;
00367             for (jrow = 1; jrow <= i__2; ++jrow) {
00368                 ++jreal;
00369                 ++jimag;
00370                 i__3 = jrow + jcol * b_dim1;
00371                 i__4 = jreal;
00372                 i__5 = jimag;
00373                 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
00374                 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00375 /* L80: */
00376             }
00377 /* L90: */
00378         }
00379 
00380         tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], dabs(r__1));
00381         i__1 = *n;
00382         for (i__ = 1; i__ <= i__1; ++i__) {
00383             if (d__[i__] <= tol) {
00384                 claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb);
00385             } else {
00386                 clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &b[
00387                         i__ + b_dim1], ldb, info);
00388                 ++(*rank);
00389             }
00390 /* L100: */
00391         }
00392 
00393 /*        Since B is complex, the following call to SGEMM is performed */
00394 /*        in two steps (real and imaginary parts). That is for V * B */
00395 /*        (in the real version of the code V' is stored in WORK). */
00396 
00397 /*        CALL SGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, */
00398 /*    $               WORK( NWORK ), N ) */
00399 
00400         j = irwb - 1;
00401         i__1 = *nrhs;
00402         for (jcol = 1; jcol <= i__1; ++jcol) {
00403             i__2 = *n;
00404             for (jrow = 1; jrow <= i__2; ++jrow) {
00405                 ++j;
00406                 i__3 = jrow + jcol * b_dim1;
00407                 rwork[j] = b[i__3].r;
00408 /* L110: */
00409             }
00410 /* L120: */
00411         }
00412         sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], 
00413                 n, &c_b35, &rwork[irwrb], n);
00414         j = irwb - 1;
00415         i__1 = *nrhs;
00416         for (jcol = 1; jcol <= i__1; ++jcol) {
00417             i__2 = *n;
00418             for (jrow = 1; jrow <= i__2; ++jrow) {
00419                 ++j;
00420                 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
00421 /* L130: */
00422             }
00423 /* L140: */
00424         }
00425         sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], 
00426                 n, &c_b35, &rwork[irwib], n);
00427         jreal = irwrb - 1;
00428         jimag = irwib - 1;
00429         i__1 = *nrhs;
00430         for (jcol = 1; jcol <= i__1; ++jcol) {
00431             i__2 = *n;
00432             for (jrow = 1; jrow <= i__2; ++jrow) {
00433                 ++jreal;
00434                 ++jimag;
00435                 i__3 = jrow + jcol * b_dim1;
00436                 i__4 = jreal;
00437                 i__5 = jimag;
00438                 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
00439                 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00440 /* L150: */
00441             }
00442 /* L160: */
00443         }
00444 
00445 /*        Unscale. */
00446 
00447         slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, 
00448                 info);
00449         slasrt_("D", n, &d__[1], info);
00450         clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], 
00451                 ldb, info);
00452 
00453         return 0;
00454     }
00455 
00456 /*     Book-keeping and setting up some constants. */
00457 
00458     nlvl = (integer) (log((real) (*n) / (real) (*smlsiz + 1)) / log(2.f)) + 1;
00459 
00460     smlszp = *smlsiz + 1;
00461 
00462     u = 1;
00463     vt = *smlsiz * *n + 1;
00464     difl = vt + smlszp * *n;
00465     difr = difl + nlvl * *n;
00466     z__ = difr + (nlvl * *n << 1);
00467     c__ = z__ + nlvl * *n;
00468     s = c__ + *n;
00469     poles = s + *n;
00470     givnum = poles + (nlvl << 1) * *n;
00471     nrwork = givnum + (nlvl << 1) * *n;
00472     bx = 1;
00473 
00474     irwrb = nrwork;
00475     irwib = irwrb + *smlsiz * *nrhs;
00476     irwb = irwib + *smlsiz * *nrhs;
00477 
00478     sizei = *n + 1;
00479     k = sizei + *n;
00480     givptr = k + *n;
00481     perm = givptr + *n;
00482     givcol = perm + nlvl * *n;
00483     iwk = givcol + (nlvl * *n << 1);
00484 
00485     st = 1;
00486     sqre = 0;
00487     icmpq1 = 1;
00488     icmpq2 = 0;
00489     nsub = 0;
00490 
00491     i__1 = *n;
00492     for (i__ = 1; i__ <= i__1; ++i__) {
00493         if ((r__1 = d__[i__], dabs(r__1)) < eps) {
00494             d__[i__] = r_sign(&eps, &d__[i__]);
00495         }
00496 /* L170: */
00497     }
00498 
00499     i__1 = nm1;
00500     for (i__ = 1; i__ <= i__1; ++i__) {
00501         if ((r__1 = e[i__], dabs(r__1)) < eps || i__ == nm1) {
00502             ++nsub;
00503             iwork[nsub] = st;
00504 
00505 /*           Subproblem found. First determine its size and then */
00506 /*           apply divide and conquer on it. */
00507 
00508             if (i__ < nm1) {
00509 
00510 /*              A subproblem with E(I) small for I < NM1. */
00511 
00512                 nsize = i__ - st + 1;
00513                 iwork[sizei + nsub - 1] = nsize;
00514             } else if ((r__1 = e[i__], dabs(r__1)) >= eps) {
00515 
00516 /*              A subproblem with E(NM1) not too small but I = NM1. */
00517 
00518                 nsize = *n - st + 1;
00519                 iwork[sizei + nsub - 1] = nsize;
00520             } else {
00521 
00522 /*              A subproblem with E(NM1) small. This implies an */
00523 /*              1-by-1 subproblem at D(N), which is not solved */
00524 /*              explicitly. */
00525 
00526                 nsize = i__ - st + 1;
00527                 iwork[sizei + nsub - 1] = nsize;
00528                 ++nsub;
00529                 iwork[nsub] = *n;
00530                 iwork[sizei + nsub - 1] = 1;
00531                 ccopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
00532             }
00533             st1 = st - 1;
00534             if (nsize == 1) {
00535 
00536 /*              This is a 1-by-1 subproblem and is not solved */
00537 /*              explicitly. */
00538 
00539                 ccopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
00540             } else if (nsize <= *smlsiz) {
00541 
00542 /*              This is a small subproblem and is solved by SLASDQ. */
00543 
00544                 slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[vt + st1], 
00545                          n);
00546                 slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[u + st1], 
00547                         n);
00548                 slasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], &
00549                         e[st], &rwork[vt + st1], n, &rwork[u + st1], n, &
00550                         rwork[nrwork], &c__1, &rwork[nrwork], info)
00551                         ;
00552                 if (*info != 0) {
00553                     return 0;
00554                 }
00555 
00556 /*              In the real version, B is passed to SLASDQ and multiplied */
00557 /*              internally by Q'. Here B is complex and that product is */
00558 /*              computed below in two steps (real and imaginary parts). */
00559 
00560                 j = irwb - 1;
00561                 i__2 = *nrhs;
00562                 for (jcol = 1; jcol <= i__2; ++jcol) {
00563                     i__3 = st + nsize - 1;
00564                     for (jrow = st; jrow <= i__3; ++jrow) {
00565                         ++j;
00566                         i__4 = jrow + jcol * b_dim1;
00567                         rwork[j] = b[i__4].r;
00568 /* L180: */
00569                     }
00570 /* L190: */
00571                 }
00572                 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
00573 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &
00574                         nsize);
00575                 j = irwb - 1;
00576                 i__2 = *nrhs;
00577                 for (jcol = 1; jcol <= i__2; ++jcol) {
00578                     i__3 = st + nsize - 1;
00579                     for (jrow = st; jrow <= i__3; ++jrow) {
00580                         ++j;
00581                         rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
00582 /* L200: */
00583                     }
00584 /* L210: */
00585                 }
00586                 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
00587 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &
00588                         nsize);
00589                 jreal = irwrb - 1;
00590                 jimag = irwib - 1;
00591                 i__2 = *nrhs;
00592                 for (jcol = 1; jcol <= i__2; ++jcol) {
00593                     i__3 = st + nsize - 1;
00594                     for (jrow = st; jrow <= i__3; ++jrow) {
00595                         ++jreal;
00596                         ++jimag;
00597                         i__4 = jrow + jcol * b_dim1;
00598                         i__5 = jreal;
00599                         i__6 = jimag;
00600                         q__1.r = rwork[i__5], q__1.i = rwork[i__6];
00601                         b[i__4].r = q__1.r, b[i__4].i = q__1.i;
00602 /* L220: */
00603                     }
00604 /* L230: */
00605                 }
00606 
00607                 clacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx + 
00608                         st1], n);
00609             } else {
00610 
00611 /*              A large problem. Solve it using divide and conquer. */
00612 
00613                 slasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
00614                         rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1], 
00615                         &rwork[difl + st1], &rwork[difr + st1], &rwork[z__ + 
00616                         st1], &rwork[poles + st1], &iwork[givptr + st1], &
00617                         iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
00618                         givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &
00619                         rwork[nrwork], &iwork[iwk], info);
00620                 if (*info != 0) {
00621                     return 0;
00622                 }
00623                 bxst = bx + st1;
00624                 clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
00625                         work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], &
00626                         iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1]
00627 , &rwork[z__ + st1], &rwork[poles + st1], &iwork[
00628                         givptr + st1], &iwork[givcol + st1], n, &iwork[perm + 
00629                         st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[
00630                         s + st1], &rwork[nrwork], &iwork[iwk], info);
00631                 if (*info != 0) {
00632                     return 0;
00633                 }
00634             }
00635             st = i__ + 1;
00636         }
00637 /* L240: */
00638     }
00639 
00640 /*     Apply the singular values and treat the tiny ones as zero. */
00641 
00642     tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], dabs(r__1));
00643 
00644     i__1 = *n;
00645     for (i__ = 1; i__ <= i__1; ++i__) {
00646 
00647 /*        Some of the elements in D can be negative because 1-by-1 */
00648 /*        subproblems were not solved explicitly. */
00649 
00650         if ((r__1 = d__[i__], dabs(r__1)) <= tol) {
00651             claset_("A", &c__1, nrhs, &c_b1, &c_b1, &work[bx + i__ - 1], n);
00652         } else {
00653             ++(*rank);
00654             clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &work[
00655                     bx + i__ - 1], n, info);
00656         }
00657         d__[i__] = (r__1 = d__[i__], dabs(r__1));
00658 /* L250: */
00659     }
00660 
00661 /*     Now apply back the right singular vectors. */
00662 
00663     icmpq2 = 1;
00664     i__1 = nsub;
00665     for (i__ = 1; i__ <= i__1; ++i__) {
00666         st = iwork[i__];
00667         st1 = st - 1;
00668         nsize = iwork[sizei + i__ - 1];
00669         bxst = bx + st1;
00670         if (nsize == 1) {
00671             ccopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
00672         } else if (nsize <= *smlsiz) {
00673 
00674 /*           Since B and BX are complex, the following call to SGEMM */
00675 /*           is performed in two steps (real and imaginary parts). */
00676 
00677 /*           CALL SGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, */
00678 /*    $                  RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO, */
00679 /*    $                  B( ST, 1 ), LDB ) */
00680 
00681             j = bxst - *n - 1;
00682             jreal = irwb - 1;
00683             i__2 = *nrhs;
00684             for (jcol = 1; jcol <= i__2; ++jcol) {
00685                 j += *n;
00686                 i__3 = nsize;
00687                 for (jrow = 1; jrow <= i__3; ++jrow) {
00688                     ++jreal;
00689                     i__4 = j + jrow;
00690                     rwork[jreal] = work[i__4].r;
00691 /* L260: */
00692                 }
00693 /* L270: */
00694             }
00695             sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], 
00696                     n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &nsize);
00697             j = bxst - *n - 1;
00698             jimag = irwb - 1;
00699             i__2 = *nrhs;
00700             for (jcol = 1; jcol <= i__2; ++jcol) {
00701                 j += *n;
00702                 i__3 = nsize;
00703                 for (jrow = 1; jrow <= i__3; ++jrow) {
00704                     ++jimag;
00705                     rwork[jimag] = r_imag(&work[j + jrow]);
00706 /* L280: */
00707                 }
00708 /* L290: */
00709             }
00710             sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], 
00711                     n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &nsize);
00712             jreal = irwrb - 1;
00713             jimag = irwib - 1;
00714             i__2 = *nrhs;
00715             for (jcol = 1; jcol <= i__2; ++jcol) {
00716                 i__3 = st + nsize - 1;
00717                 for (jrow = st; jrow <= i__3; ++jrow) {
00718                     ++jreal;
00719                     ++jimag;
00720                     i__4 = jrow + jcol * b_dim1;
00721                     i__5 = jreal;
00722                     i__6 = jimag;
00723                     q__1.r = rwork[i__5], q__1.i = rwork[i__6];
00724                     b[i__4].r = q__1.r, b[i__4].i = q__1.i;
00725 /* L300: */
00726                 }
00727 /* L310: */
00728             }
00729         } else {
00730             clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st + 
00731                     b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], &
00732                     iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &
00733                     rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr + 
00734                     st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
00735                     givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[
00736                     nrwork], &iwork[iwk], info);
00737             if (*info != 0) {
00738                 return 0;
00739             }
00740         }
00741 /* L320: */
00742     }
00743 
00744 /*     Unscale and sort the singular values. */
00745 
00746     slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info);
00747     slasrt_("D", n, &d__[1], info);
00748     clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb, 
00749             info);
00750 
00751     return 0;
00752 
00753 /*     End of CLALSD */
00754 
00755 } /* clalsd_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:30