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


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