zgelsd.c
Go to the documentation of this file.
00001 /* zgelsd.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__9 = 9;
00020 static integer c__0 = 0;
00021 static integer c__6 = 6;
00022 static integer c_n1 = -1;
00023 static integer c__1 = 1;
00024 static doublereal c_b80 = 0.;
00025 
00026 /* Subroutine */ int zgelsd_(integer *m, integer *n, integer *nrhs, 
00027         doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, 
00028         doublereal *s, doublereal *rcond, integer *rank, doublecomplex *work, 
00029         integer *lwork, doublereal *rwork, integer *iwork, integer *info)
00030 {
00031     /* System generated locals */
00032     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
00033 
00034     /* Builtin functions */
00035     double log(doublereal);
00036 
00037     /* Local variables */
00038     integer ie, il, mm;
00039     doublereal eps, anrm, bnrm;
00040     integer itau, nlvl, iascl, ibscl;
00041     doublereal sfmin;
00042     integer minmn, maxmn, itaup, itauq, mnthr, nwork;
00043     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
00044     extern doublereal dlamch_(char *);
00045     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
00046             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00047             integer *, integer *), dlaset_(char *, integer *, integer 
00048             *, doublereal *, doublereal *, doublereal *, integer *), 
00049             xerbla_(char *, integer *), zgebrd_(integer *, integer *, 
00050             doublecomplex *, integer *, doublereal *, doublereal *, 
00051             doublecomplex *, doublecomplex *, doublecomplex *, integer *, 
00052             integer *);
00053     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00054             integer *, integer *);
00055     extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, 
00056             integer *, doublereal *);
00057     doublereal bignum;
00058     extern /* Subroutine */ int zgelqf_(integer *, integer *, doublecomplex *, 
00059              integer *, doublecomplex *, doublecomplex *, integer *, integer *
00060 ), zlalsd_(char *, integer *, integer *, integer *, doublereal *, 
00061             doublereal *, doublecomplex *, integer *, doublereal *, integer *, 
00062              doublecomplex *, doublereal *, integer *, integer *), 
00063             zlascl_(char *, integer *, integer *, doublereal *, doublereal *, 
00064             integer *, integer *, doublecomplex *, integer *, integer *), zgeqrf_(integer *, integer *, doublecomplex *, integer *, 
00065              doublecomplex *, doublecomplex *, integer *, integer *);
00066     integer ldwork;
00067     extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, 
00068             doublecomplex *, integer *, doublecomplex *, integer *), 
00069             zlaset_(char *, integer *, integer *, doublecomplex *, 
00070             doublecomplex *, doublecomplex *, integer *);
00071     integer liwork, minwrk, maxwrk;
00072     doublereal smlnum;
00073     extern /* Subroutine */ int zunmbr_(char *, char *, char *, integer *, 
00074             integer *, integer *, doublecomplex *, integer *, doublecomplex *, 
00075              doublecomplex *, integer *, doublecomplex *, integer *, integer *
00076 );
00077     integer lrwork;
00078     logical lquery;
00079     integer nrwork, smlsiz;
00080     extern /* Subroutine */ int zunmlq_(char *, char *, integer *, integer *, 
00081             integer *, doublecomplex *, integer *, doublecomplex *, 
00082             doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, 
00083             integer *, doublecomplex *, integer *, doublecomplex *, 
00084             doublecomplex *, integer *, doublecomplex *, integer *, integer *);
00085 
00086 
00087 /*  -- LAPACK driver routine (version 3.2) -- */
00088 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00089 /*     November 2006 */
00090 
00091 /*     .. Scalar Arguments .. */
00092 /*     .. */
00093 /*     .. Array Arguments .. */
00094 /*     .. */
00095 
00096 /*  Purpose */
00097 /*  ======= */
00098 
00099 /*  ZGELSD computes the minimum-norm solution to a real linear least */
00100 /*  squares problem: */
00101 /*      minimize 2-norm(| b - A*x |) */
00102 /*  using the singular value decomposition (SVD) of A. A is an M-by-N */
00103 /*  matrix which may be rank-deficient. */
00104 
00105 /*  Several right hand side vectors b and solution vectors x can be */
00106 /*  handled in a single call; they are stored as the columns of the */
00107 /*  M-by-NRHS right hand side matrix B and the N-by-NRHS solution */
00108 /*  matrix X. */
00109 
00110 /*  The problem is solved in three steps: */
00111 /*  (1) Reduce the coefficient matrix A to bidiagonal form with */
00112 /*      Householder tranformations, reducing the original problem */
00113 /*      into a "bidiagonal least squares problem" (BLS) */
00114 /*  (2) Solve the BLS using a divide and conquer approach. */
00115 /*  (3) Apply back all the Householder tranformations to solve */
00116 /*      the original least squares problem. */
00117 
00118 /*  The effective rank of A is determined by treating as zero those */
00119 /*  singular values which are less than RCOND times the largest singular */
00120 /*  value. */
00121 
00122 /*  The divide and conquer algorithm makes very mild assumptions about */
00123 /*  floating point arithmetic. It will work on machines with a guard */
00124 /*  digit in add/subtract, or on those binary machines without guard */
00125 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00126 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00127 /*  without guard digits, but we know of none. */
00128 
00129 /*  Arguments */
00130 /*  ========= */
00131 
00132 /*  M       (input) INTEGER */
00133 /*          The number of rows of the matrix A. M >= 0. */
00134 
00135 /*  N       (input) INTEGER */
00136 /*          The number of columns of the matrix A. N >= 0. */
00137 
00138 /*  NRHS    (input) INTEGER */
00139 /*          The number of right hand sides, i.e., the number of columns */
00140 /*          of the matrices B and X. NRHS >= 0. */
00141 
00142 /*  A       (input) COMPLEX*16 array, dimension (LDA,N) */
00143 /*          On entry, the M-by-N matrix A. */
00144 /*          On exit, A has been destroyed. */
00145 
00146 /*  LDA     (input) INTEGER */
00147 /*          The leading dimension of the array A. LDA >= max(1,M). */
00148 
00149 /*  B       (input/output) COMPLEX*16 array, dimension (LDB,NRHS) */
00150 /*          On entry, the M-by-NRHS right hand side matrix B. */
00151 /*          On exit, B is overwritten by the N-by-NRHS solution matrix X. */
00152 /*          If m >= n and RANK = n, the residual sum-of-squares for */
00153 /*          the solution in the i-th column is given by the sum of */
00154 /*          squares of the modulus of elements n+1:m in that column. */
00155 
00156 /*  LDB     (input) INTEGER */
00157 /*          The leading dimension of the array B.  LDB >= max(1,M,N). */
00158 
00159 /*  S       (output) DOUBLE PRECISION array, dimension (min(M,N)) */
00160 /*          The singular values of A in decreasing order. */
00161 /*          The condition number of A in the 2-norm = S(1)/S(min(m,n)). */
00162 
00163 /*  RCOND   (input) DOUBLE PRECISION */
00164 /*          RCOND is used to determine the effective rank of A. */
00165 /*          Singular values S(i) <= RCOND*S(1) are treated as zero. */
00166 /*          If RCOND < 0, machine precision is used instead. */
00167 
00168 /*  RANK    (output) INTEGER */
00169 /*          The effective rank of A, i.e., the number of singular values */
00170 /*          which are greater than RCOND*S(1). */
00171 
00172 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00173 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00174 
00175 /*  LWORK   (input) INTEGER */
00176 /*          The dimension of the array WORK. LWORK must be at least 1. */
00177 /*          The exact minimum amount of workspace needed depends on M, */
00178 /*          N and NRHS. As long as LWORK is at least */
00179 /*              2*N + N*NRHS */
00180 /*          if M is greater than or equal to N or */
00181 /*              2*M + M*NRHS */
00182 /*          if M is less than N, the code will execute correctly. */
00183 /*          For good performance, LWORK should generally be larger. */
00184 
00185 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00186 /*          only calculates the optimal size of the array WORK and the */
00187 /*          minimum sizes of the arrays RWORK and IWORK, and returns */
00188 /*          these values as the first entries of the WORK, RWORK and */
00189 /*          IWORK arrays, and no error message related to LWORK is issued */
00190 /*          by XERBLA. */
00191 
00192 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
00193 /*          LRWORK >= */
00194 /*              10*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + */
00195 /*             (SMLSIZ+1)**2 */
00196 /*          if M is greater than or equal to N or */
00197 /*             10*M + 2*M*SMLSIZ + 8*M*NLVL + 3*SMLSIZ*NRHS + */
00198 /*             (SMLSIZ+1)**2 */
00199 /*          if M is less than N, the code will execute correctly. */
00200 /*          SMLSIZ is returned by ILAENV and is equal to the maximum */
00201 /*          size of the subproblems at the bottom of the computation */
00202 /*          tree (usually about 25), and */
00203 /*             NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
00204 /*          On exit, if INFO = 0, RWORK(1) returns the minimum LRWORK. */
00205 
00206 /*  IWORK   (workspace) INTEGER array, dimension (MAX(1,LIWORK)) */
00207 /*          LIWORK >= max(1, 3*MINMN*NLVL + 11*MINMN), */
00208 /*          where MINMN = MIN( M,N ). */
00209 /*          On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
00210 
00211 /*  INFO    (output) INTEGER */
00212 /*          = 0: successful exit */
00213 /*          < 0: if INFO = -i, the i-th argument had an illegal value. */
00214 /*          > 0:  the algorithm for computing the SVD failed to converge; */
00215 /*                if INFO = i, i off-diagonal elements of an intermediate */
00216 /*                bidiagonal form did not converge to zero. */
00217 
00218 /*  Further Details */
00219 /*  =============== */
00220 
00221 /*  Based on contributions by */
00222 /*     Ming Gu and Ren-Cang Li, Computer Science Division, University of */
00223 /*       California at Berkeley, USA */
00224 /*     Osni Marques, LBNL/NERSC, USA */
00225 
00226 /*  ===================================================================== */
00227 
00228 /*     .. Parameters .. */
00229 /*     .. */
00230 /*     .. Local Scalars .. */
00231 /*     .. */
00232 /*     .. External Subroutines .. */
00233 /*     .. */
00234 /*     .. External Functions .. */
00235 /*     .. */
00236 /*     .. Intrinsic Functions .. */
00237 /*     .. */
00238 /*     .. Executable Statements .. */
00239 
00240 /*     Test the input arguments. */
00241 
00242     /* Parameter adjustments */
00243     a_dim1 = *lda;
00244     a_offset = 1 + a_dim1;
00245     a -= a_offset;
00246     b_dim1 = *ldb;
00247     b_offset = 1 + b_dim1;
00248     b -= b_offset;
00249     --s;
00250     --work;
00251     --rwork;
00252     --iwork;
00253 
00254     /* Function Body */
00255     *info = 0;
00256     minmn = min(*m,*n);
00257     maxmn = max(*m,*n);
00258     lquery = *lwork == -1;
00259     if (*m < 0) {
00260         *info = -1;
00261     } else if (*n < 0) {
00262         *info = -2;
00263     } else if (*nrhs < 0) {
00264         *info = -3;
00265     } else if (*lda < max(1,*m)) {
00266         *info = -5;
00267     } else if (*ldb < max(1,maxmn)) {
00268         *info = -7;
00269     }
00270 
00271 /*     Compute workspace. */
00272 /*     (Note: Comments in the code beginning "Workspace:" describe the */
00273 /*     minimal amount of workspace needed at that point in the code, */
00274 /*     as well as the preferred amount for good performance. */
00275 /*     NB refers to the optimal block size for the immediately */
00276 /*     following subroutine, as returned by ILAENV.) */
00277 
00278     if (*info == 0) {
00279         minwrk = 1;
00280         maxwrk = 1;
00281         liwork = 1;
00282         lrwork = 1;
00283         if (minmn > 0) {
00284             smlsiz = ilaenv_(&c__9, "ZGELSD", " ", &c__0, &c__0, &c__0, &c__0);
00285             mnthr = ilaenv_(&c__6, "ZGELSD", " ", m, n, nrhs, &c_n1);
00286 /* Computing MAX */
00287             i__1 = (integer) (log((doublereal) minmn / (doublereal) (smlsiz + 
00288                     1)) / log(2.)) + 1;
00289             nlvl = max(i__1,0);
00290             liwork = minmn * 3 * nlvl + minmn * 11;
00291             mm = *m;
00292             if (*m >= *n && *m >= mnthr) {
00293 
00294 /*              Path 1a - overdetermined, with many more rows than */
00295 /*                        columns. */
00296 
00297                 mm = *n;
00298 /* Computing MAX */
00299                 i__1 = maxwrk, i__2 = *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n, 
00300                          &c_n1, &c_n1);
00301                 maxwrk = max(i__1,i__2);
00302 /* Computing MAX */
00303                 i__1 = maxwrk, i__2 = *nrhs * ilaenv_(&c__1, "ZUNMQR", "LC", 
00304                         m, nrhs, n, &c_n1);
00305                 maxwrk = max(i__1,i__2);
00306             }
00307             if (*m >= *n) {
00308 
00309 /*              Path 1 - overdetermined or exactly determined. */
00310 
00311 /* Computing 2nd power */
00312                 i__1 = smlsiz + 1;
00313                 lrwork = *n * 10 + (*n << 1) * smlsiz + (*n << 3) * nlvl + 
00314                         smlsiz * 3 * *nrhs + i__1 * i__1;
00315 /* Computing MAX */
00316                 i__1 = maxwrk, i__2 = (*n << 1) + (mm + *n) * ilaenv_(&c__1, 
00317                         "ZGEBRD", " ", &mm, n, &c_n1, &c_n1);
00318                 maxwrk = max(i__1,i__2);
00319 /* Computing MAX */
00320                 i__1 = maxwrk, i__2 = (*n << 1) + *nrhs * ilaenv_(&c__1, 
00321                         "ZUNMBR", "QLC", &mm, nrhs, n, &c_n1);
00322                 maxwrk = max(i__1,i__2);
00323 /* Computing MAX */
00324                 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1, 
00325                         "ZUNMBR", "PLN", n, nrhs, n, &c_n1);
00326                 maxwrk = max(i__1,i__2);
00327 /* Computing MAX */
00328                 i__1 = maxwrk, i__2 = (*n << 1) + *n * *nrhs;
00329                 maxwrk = max(i__1,i__2);
00330 /* Computing MAX */
00331                 i__1 = (*n << 1) + mm, i__2 = (*n << 1) + *n * *nrhs;
00332                 minwrk = max(i__1,i__2);
00333             }
00334             if (*n > *m) {
00335 /* Computing 2nd power */
00336                 i__1 = smlsiz + 1;
00337                 lrwork = *m * 10 + (*m << 1) * smlsiz + (*m << 3) * nlvl + 
00338                         smlsiz * 3 * *nrhs + i__1 * i__1;
00339                 if (*n >= mnthr) {
00340 
00341 /*                 Path 2a - underdetermined, with many more columns */
00342 /*                           than rows. */
00343 
00344                     maxwrk = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
00345                             c_n1, &c_n1);
00346 /* Computing MAX */
00347                     i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m << 1) * 
00348                             ilaenv_(&c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1);
00349                     maxwrk = max(i__1,i__2);
00350 /* Computing MAX */
00351                     i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *nrhs * 
00352                             ilaenv_(&c__1, "ZUNMBR", "QLC", m, nrhs, m, &c_n1);
00353                     maxwrk = max(i__1,i__2);
00354 /* Computing MAX */
00355                     i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m - 1) * 
00356                             ilaenv_(&c__1, "ZUNMLQ", "LC", n, nrhs, m, &c_n1);
00357                     maxwrk = max(i__1,i__2);
00358                     if (*nrhs > 1) {
00359 /* Computing MAX */
00360                         i__1 = maxwrk, i__2 = *m * *m + *m + *m * *nrhs;
00361                         maxwrk = max(i__1,i__2);
00362                     } else {
00363 /* Computing MAX */
00364                         i__1 = maxwrk, i__2 = *m * *m + (*m << 1);
00365                         maxwrk = max(i__1,i__2);
00366                     }
00367 /* Computing MAX */
00368                     i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *m * *nrhs;
00369                     maxwrk = max(i__1,i__2);
00370 /*     XXX: Ensure the Path 2a case below is triggered.  The workspace */
00371 /*     calculation should use queries for all routines eventually. */
00372 /* Computing MAX */
00373 /* Computing MAX */
00374                     i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), 
00375                             i__3 = max(i__3,*nrhs), i__4 = *n - *m * 3;
00376                     i__1 = maxwrk, i__2 = (*m << 2) + *m * *m + max(i__3,i__4)
00377                             ;
00378                     maxwrk = max(i__1,i__2);
00379                 } else {
00380 
00381 /*                 Path 2 - underdetermined. */
00382 
00383                     maxwrk = (*m << 1) + (*n + *m) * ilaenv_(&c__1, "ZGEBRD", 
00384                             " ", m, n, &c_n1, &c_n1);
00385 /* Computing MAX */
00386                     i__1 = maxwrk, i__2 = (*m << 1) + *nrhs * ilaenv_(&c__1, 
00387                             "ZUNMBR", "QLC", m, nrhs, m, &c_n1);
00388                     maxwrk = max(i__1,i__2);
00389 /* Computing MAX */
00390                     i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1, 
00391                             "ZUNMBR", "PLN", n, nrhs, m, &c_n1);
00392                     maxwrk = max(i__1,i__2);
00393 /* Computing MAX */
00394                     i__1 = maxwrk, i__2 = (*m << 1) + *m * *nrhs;
00395                     maxwrk = max(i__1,i__2);
00396                 }
00397 /* Computing MAX */
00398                 i__1 = (*m << 1) + *n, i__2 = (*m << 1) + *m * *nrhs;
00399                 minwrk = max(i__1,i__2);
00400             }
00401         }
00402         minwrk = min(minwrk,maxwrk);
00403         work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00404         iwork[1] = liwork;
00405         rwork[1] = (doublereal) lrwork;
00406 
00407         if (*lwork < minwrk && ! lquery) {
00408             *info = -12;
00409         }
00410     }
00411 
00412     if (*info != 0) {
00413         i__1 = -(*info);
00414         xerbla_("ZGELSD", &i__1);
00415         return 0;
00416     } else if (lquery) {
00417         return 0;
00418     }
00419 
00420 /*     Quick return if possible. */
00421 
00422     if (*m == 0 || *n == 0) {
00423         *rank = 0;
00424         return 0;
00425     }
00426 
00427 /*     Get machine parameters. */
00428 
00429     eps = dlamch_("P");
00430     sfmin = dlamch_("S");
00431     smlnum = sfmin / eps;
00432     bignum = 1. / smlnum;
00433     dlabad_(&smlnum, &bignum);
00434 
00435 /*     Scale A if max entry outside range [SMLNUM,BIGNUM]. */
00436 
00437     anrm = zlange_("M", m, n, &a[a_offset], lda, &rwork[1]);
00438     iascl = 0;
00439     if (anrm > 0. && anrm < smlnum) {
00440 
00441 /*        Scale matrix norm up to SMLNUM */
00442 
00443         zlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, 
00444                 info);
00445         iascl = 1;
00446     } else if (anrm > bignum) {
00447 
00448 /*        Scale matrix norm down to BIGNUM. */
00449 
00450         zlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, 
00451                 info);
00452         iascl = 2;
00453     } else if (anrm == 0.) {
00454 
00455 /*        Matrix all zero. Return zero solution. */
00456 
00457         i__1 = max(*m,*n);
00458         zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00459         dlaset_("F", &minmn, &c__1, &c_b80, &c_b80, &s[1], &c__1);
00460         *rank = 0;
00461         goto L10;
00462     }
00463 
00464 /*     Scale B if max entry outside range [SMLNUM,BIGNUM]. */
00465 
00466     bnrm = zlange_("M", m, nrhs, &b[b_offset], ldb, &rwork[1]);
00467     ibscl = 0;
00468     if (bnrm > 0. && bnrm < smlnum) {
00469 
00470 /*        Scale matrix norm up to SMLNUM. */
00471 
00472         zlascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb, 
00473                  info);
00474         ibscl = 1;
00475     } else if (bnrm > bignum) {
00476 
00477 /*        Scale matrix norm down to BIGNUM. */
00478 
00479         zlascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb, 
00480                  info);
00481         ibscl = 2;
00482     }
00483 
00484 /*     If M < N make sure B(M+1:N,:) = 0 */
00485 
00486     if (*m < *n) {
00487         i__1 = *n - *m;
00488         zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[*m + 1 + b_dim1], ldb);
00489     }
00490 
00491 /*     Overdetermined case. */
00492 
00493     if (*m >= *n) {
00494 
00495 /*        Path 1 - overdetermined or exactly determined. */
00496 
00497         mm = *m;
00498         if (*m >= mnthr) {
00499 
00500 /*           Path 1a - overdetermined, with many more rows than columns */
00501 
00502             mm = *n;
00503             itau = 1;
00504             nwork = itau + *n;
00505 
00506 /*           Compute A=Q*R. */
00507 /*           (RWorkspace: need N) */
00508 /*           (CWorkspace: need N, prefer N*NB) */
00509 
00510             i__1 = *lwork - nwork + 1;
00511             zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1, 
00512                      info);
00513 
00514 /*           Multiply B by transpose(Q). */
00515 /*           (RWorkspace: need N) */
00516 /*           (CWorkspace: need NRHS, prefer NRHS*NB) */
00517 
00518             i__1 = *lwork - nwork + 1;
00519             zunmqr_("L", "C", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[
00520                     b_offset], ldb, &work[nwork], &i__1, info);
00521 
00522 /*           Zero out below R. */
00523 
00524             if (*n > 1) {
00525                 i__1 = *n - 1;
00526                 i__2 = *n - 1;
00527                 zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
00528             }
00529         }
00530 
00531         itauq = 1;
00532         itaup = itauq + *n;
00533         nwork = itaup + *n;
00534         ie = 1;
00535         nrwork = ie + *n;
00536 
00537 /*        Bidiagonalize R in A. */
00538 /*        (RWorkspace: need N) */
00539 /*        (CWorkspace: need 2*N+MM, prefer 2*N+(MM+N)*NB) */
00540 
00541         i__1 = *lwork - nwork + 1;
00542         zgebrd_(&mm, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], &
00543                 work[itaup], &work[nwork], &i__1, info);
00544 
00545 /*        Multiply B by transpose of left bidiagonalizing vectors of R. */
00546 /*        (CWorkspace: need 2*N+NRHS, prefer 2*N+NRHS*NB) */
00547 
00548         i__1 = *lwork - nwork + 1;
00549         zunmbr_("Q", "L", "C", &mm, nrhs, n, &a[a_offset], lda, &work[itauq], 
00550                 &b[b_offset], ldb, &work[nwork], &i__1, info);
00551 
00552 /*        Solve the bidiagonal least squares problem. */
00553 
00554         zlalsd_("U", &smlsiz, n, nrhs, &s[1], &rwork[ie], &b[b_offset], ldb, 
00555                 rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1], info);
00556         if (*info != 0) {
00557             goto L10;
00558         }
00559 
00560 /*        Multiply B by right bidiagonalizing vectors of R. */
00561 
00562         i__1 = *lwork - nwork + 1;
00563         zunmbr_("P", "L", "N", n, nrhs, n, &a[a_offset], lda, &work[itaup], &
00564                 b[b_offset], ldb, &work[nwork], &i__1, info);
00565 
00566     } else /* if(complicated condition) */ {
00567 /* Computing MAX */
00568         i__1 = *m, i__2 = (*m << 1) - 4, i__1 = max(i__1,i__2), i__1 = max(
00569                 i__1,*nrhs), i__2 = *n - *m * 3;
00570         if (*n >= mnthr && *lwork >= (*m << 2) + *m * *m + max(i__1,i__2)) {
00571 
00572 /*        Path 2a - underdetermined, with many more columns than rows */
00573 /*        and sufficient workspace for an efficient algorithm. */
00574 
00575             ldwork = *m;
00576 /* Computing MAX */
00577 /* Computing MAX */
00578             i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), i__3 = 
00579                     max(i__3,*nrhs), i__4 = *n - *m * 3;
00580             i__1 = (*m << 2) + *m * *lda + max(i__3,i__4), i__2 = *m * *lda + 
00581                     *m + *m * *nrhs;
00582             if (*lwork >= max(i__1,i__2)) {
00583                 ldwork = *lda;
00584             }
00585             itau = 1;
00586             nwork = *m + 1;
00587 
00588 /*        Compute A=L*Q. */
00589 /*        (CWorkspace: need 2*M, prefer M+M*NB) */
00590 
00591             i__1 = *lwork - nwork + 1;
00592             zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1, 
00593                      info);
00594             il = nwork;
00595 
00596 /*        Copy L to WORK(IL), zeroing out above its diagonal. */
00597 
00598             zlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork);
00599             i__1 = *m - 1;
00600             i__2 = *m - 1;
00601             zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &work[il + ldwork], &
00602                     ldwork);
00603             itauq = il + ldwork * *m;
00604             itaup = itauq + *m;
00605             nwork = itaup + *m;
00606             ie = 1;
00607             nrwork = ie + *m;
00608 
00609 /*        Bidiagonalize L in WORK(IL). */
00610 /*        (RWorkspace: need M) */
00611 /*        (CWorkspace: need M*M+4*M, prefer M*M+4*M+2*M*NB) */
00612 
00613             i__1 = *lwork - nwork + 1;
00614             zgebrd_(m, m, &work[il], &ldwork, &s[1], &rwork[ie], &work[itauq], 
00615                      &work[itaup], &work[nwork], &i__1, info);
00616 
00617 /*        Multiply B by transpose of left bidiagonalizing vectors of L. */
00618 /*        (CWorkspace: need M*M+4*M+NRHS, prefer M*M+4*M+NRHS*NB) */
00619 
00620             i__1 = *lwork - nwork + 1;
00621             zunmbr_("Q", "L", "C", m, nrhs, m, &work[il], &ldwork, &work[
00622                     itauq], &b[b_offset], ldb, &work[nwork], &i__1, info);
00623 
00624 /*        Solve the bidiagonal least squares problem. */
00625 
00626             zlalsd_("U", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset], 
00627                     ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1], 
00628                      info);
00629             if (*info != 0) {
00630                 goto L10;
00631             }
00632 
00633 /*        Multiply B by right bidiagonalizing vectors of L. */
00634 
00635             i__1 = *lwork - nwork + 1;
00636             zunmbr_("P", "L", "N", m, nrhs, m, &work[il], &ldwork, &work[
00637                     itaup], &b[b_offset], ldb, &work[nwork], &i__1, info);
00638 
00639 /*        Zero out below first M rows of B. */
00640 
00641             i__1 = *n - *m;
00642             zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[*m + 1 + b_dim1], ldb);
00643             nwork = itau + *m;
00644 
00645 /*        Multiply transpose(Q) by B. */
00646 /*        (CWorkspace: need NRHS, prefer NRHS*NB) */
00647 
00648             i__1 = *lwork - nwork + 1;
00649             zunmlq_("L", "C", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[
00650                     b_offset], ldb, &work[nwork], &i__1, info);
00651 
00652         } else {
00653 
00654 /*        Path 2 - remaining underdetermined cases. */
00655 
00656             itauq = 1;
00657             itaup = itauq + *m;
00658             nwork = itaup + *m;
00659             ie = 1;
00660             nrwork = ie + *m;
00661 
00662 /*        Bidiagonalize A. */
00663 /*        (RWorkspace: need M) */
00664 /*        (CWorkspace: need 2*M+N, prefer 2*M+(M+N)*NB) */
00665 
00666             i__1 = *lwork - nwork + 1;
00667             zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], 
00668                     &work[itaup], &work[nwork], &i__1, info);
00669 
00670 /*        Multiply B by transpose of left bidiagonalizing vectors. */
00671 /*        (CWorkspace: need 2*M+NRHS, prefer 2*M+NRHS*NB) */
00672 
00673             i__1 = *lwork - nwork + 1;
00674             zunmbr_("Q", "L", "C", m, nrhs, n, &a[a_offset], lda, &work[itauq]
00675 , &b[b_offset], ldb, &work[nwork], &i__1, info);
00676 
00677 /*        Solve the bidiagonal least squares problem. */
00678 
00679             zlalsd_("L", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset], 
00680                     ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1], 
00681                      info);
00682             if (*info != 0) {
00683                 goto L10;
00684             }
00685 
00686 /*        Multiply B by right bidiagonalizing vectors of A. */
00687 
00688             i__1 = *lwork - nwork + 1;
00689             zunmbr_("P", "L", "N", n, nrhs, m, &a[a_offset], lda, &work[itaup]
00690 , &b[b_offset], ldb, &work[nwork], &i__1, info);
00691 
00692         }
00693     }
00694 
00695 /*     Undo scaling. */
00696 
00697     if (iascl == 1) {
00698         zlascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb, 
00699                  info);
00700         dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
00701                 minmn, info);
00702     } else if (iascl == 2) {
00703         zlascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb, 
00704                  info);
00705         dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
00706                 minmn, info);
00707     }
00708     if (ibscl == 1) {
00709         zlascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb, 
00710                  info);
00711     } else if (ibscl == 2) {
00712         zlascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb, 
00713                  info);
00714     }
00715 
00716 L10:
00717     work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00718     iwork[1] = liwork;
00719     rwork[1] = (doublereal) lrwork;
00720     return 0;
00721 
00722 /*     End of ZGELSD */
00723 
00724 } /* zgelsd_ */


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