dlasda.c
Go to the documentation of this file.
00001 /* dlasda.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__0 = 0;
00019 static doublereal c_b11 = 0.;
00020 static doublereal c_b12 = 1.;
00021 static integer c__1 = 1;
00022 static integer c__2 = 2;
00023 
00024 /* Subroutine */ int dlasda_(integer *icompq, integer *smlsiz, integer *n, 
00025         integer *sqre, doublereal *d__, doublereal *e, doublereal *u, integer 
00026         *ldu, doublereal *vt, integer *k, doublereal *difl, doublereal *difr, 
00027         doublereal *z__, doublereal *poles, integer *givptr, integer *givcol, 
00028         integer *ldgcol, integer *perm, doublereal *givnum, doublereal *c__, 
00029         doublereal *s, doublereal *work, integer *iwork, integer *info)
00030 {
00031     /* System generated locals */
00032     integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1, 
00033             difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset, 
00034             poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset, 
00035             z_dim1, z_offset, i__1, i__2;
00036 
00037     /* Builtin functions */
00038     integer pow_ii(integer *, integer *);
00039 
00040     /* Local variables */
00041     integer i__, j, m, i1, ic, lf, nd, ll, nl, vf, nr, vl, im1, ncc, nlf, nrf,
00042              vfi, iwk, vli, lvl, nru, ndb1, nlp1, lvl2, nrp1;
00043     doublereal beta;
00044     integer idxq, nlvl;
00045     doublereal alpha;
00046     integer inode, ndiml, ndimr, idxqi, itemp;
00047     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00048             doublereal *, integer *);
00049     integer sqrei;
00050     extern /* Subroutine */ int dlasd6_(integer *, integer *, integer *, 
00051             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00052              doublereal *, integer *, integer *, integer *, integer *, 
00053             integer *, doublereal *, integer *, doublereal *, doublereal *, 
00054             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
00055              doublereal *, integer *, integer *);
00056     integer nwork1, nwork2;
00057     extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer 
00058             *, integer *, integer *, doublereal *, doublereal *, doublereal *, 
00059              integer *, doublereal *, integer *, doublereal *, integer *, 
00060             doublereal *, integer *), dlasdt_(integer *, integer *, 
00061             integer *, integer *, integer *, integer *, integer *), dlaset_(
00062             char *, integer *, integer *, doublereal *, doublereal *, 
00063             doublereal *, integer *), xerbla_(char *, integer *);
00064     integer smlszp;
00065 
00066 
00067 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00068 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00069 /*     November 2006 */
00070 
00071 /*     .. Scalar Arguments .. */
00072 /*     .. */
00073 /*     .. Array Arguments .. */
00074 /*     .. */
00075 
00076 /*  Purpose */
00077 /*  ======= */
00078 
00079 /*  Using a divide and conquer approach, DLASDA computes the singular */
00080 /*  value decomposition (SVD) of a real upper bidiagonal N-by-M matrix */
00081 /*  B with diagonal D and offdiagonal E, where M = N + SQRE. The */
00082 /*  algorithm computes the singular values in the SVD B = U * S * VT. */
00083 /*  The orthogonal matrices U and VT are optionally computed in */
00084 /*  compact form. */
00085 
00086 /*  A related subroutine, DLASD0, computes the singular values and */
00087 /*  the singular vectors in explicit form. */
00088 
00089 /*  Arguments */
00090 /*  ========= */
00091 
00092 /*  ICOMPQ (input) INTEGER */
00093 /*         Specifies whether singular vectors are to be computed */
00094 /*         in compact form, as follows */
00095 /*         = 0: Compute singular values only. */
00096 /*         = 1: Compute singular vectors of upper bidiagonal */
00097 /*              matrix in compact form. */
00098 
00099 /*  SMLSIZ (input) INTEGER */
00100 /*         The maximum size of the subproblems at the bottom of the */
00101 /*         computation tree. */
00102 
00103 /*  N      (input) INTEGER */
00104 /*         The row dimension of the upper bidiagonal matrix. This is */
00105 /*         also the dimension of the main diagonal array D. */
00106 
00107 /*  SQRE   (input) INTEGER */
00108 /*         Specifies the column dimension of the bidiagonal matrix. */
00109 /*         = 0: The bidiagonal matrix has column dimension M = N; */
00110 /*         = 1: The bidiagonal matrix has column dimension M = N + 1. */
00111 
00112 /*  D      (input/output) DOUBLE PRECISION array, dimension ( N ) */
00113 /*         On entry D contains the main diagonal of the bidiagonal */
00114 /*         matrix. On exit D, if INFO = 0, contains its singular values. */
00115 
00116 /*  E      (input) DOUBLE PRECISION array, dimension ( M-1 ) */
00117 /*         Contains the subdiagonal entries of the bidiagonal matrix. */
00118 /*         On exit, E has been destroyed. */
00119 
00120 /*  U      (output) DOUBLE PRECISION array, */
00121 /*         dimension ( LDU, SMLSIZ ) if ICOMPQ = 1, and not referenced */
00122 /*         if ICOMPQ = 0. If ICOMPQ = 1, on exit, U contains the left */
00123 /*         singular vector matrices of all subproblems at the bottom */
00124 /*         level. */
00125 
00126 /*  LDU    (input) INTEGER, LDU = > N. */
00127 /*         The leading dimension of arrays U, VT, DIFL, DIFR, POLES, */
00128 /*         GIVNUM, and Z. */
00129 
00130 /*  VT     (output) DOUBLE PRECISION array, */
00131 /*         dimension ( LDU, SMLSIZ+1 ) if ICOMPQ = 1, and not referenced */
00132 /*         if ICOMPQ = 0. If ICOMPQ = 1, on exit, VT' contains the right */
00133 /*         singular vector matrices of all subproblems at the bottom */
00134 /*         level. */
00135 
00136 /*  K      (output) INTEGER array, */
00137 /*         dimension ( N ) if ICOMPQ = 1 and dimension 1 if ICOMPQ = 0. */
00138 /*         If ICOMPQ = 1, on exit, K(I) is the dimension of the I-th */
00139 /*         secular equation on the computation tree. */
00140 
00141 /*  DIFL   (output) DOUBLE PRECISION array, dimension ( LDU, NLVL ), */
00142 /*         where NLVL = floor(log_2 (N/SMLSIZ))). */
00143 
00144 /*  DIFR   (output) DOUBLE PRECISION array, */
00145 /*                  dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1 and */
00146 /*                  dimension ( N ) if ICOMPQ = 0. */
00147 /*         If ICOMPQ = 1, on exit, DIFL(1:N, I) and DIFR(1:N, 2 * I - 1) */
00148 /*         record distances between singular values on the I-th */
00149 /*         level and singular values on the (I -1)-th level, and */
00150 /*         DIFR(1:N, 2 * I ) contains the normalizing factors for */
00151 /*         the right singular vector matrix. See DLASD8 for details. */
00152 
00153 /*  Z      (output) DOUBLE PRECISION array, */
00154 /*                  dimension ( LDU, NLVL ) if ICOMPQ = 1 and */
00155 /*                  dimension ( N ) if ICOMPQ = 0. */
00156 /*         The first K elements of Z(1, I) contain the components of */
00157 /*         the deflation-adjusted updating row vector for subproblems */
00158 /*         on the I-th level. */
00159 
00160 /*  POLES  (output) DOUBLE PRECISION array, */
00161 /*         dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not referenced */
00162 /*         if ICOMPQ = 0. If ICOMPQ = 1, on exit, POLES(1, 2*I - 1) and */
00163 /*         POLES(1, 2*I) contain  the new and old singular values */
00164 /*         involved in the secular equations on the I-th level. */
00165 
00166 /*  GIVPTR (output) INTEGER array, */
00167 /*         dimension ( N ) if ICOMPQ = 1, and not referenced if */
00168 /*         ICOMPQ = 0. If ICOMPQ = 1, on exit, GIVPTR( I ) records */
00169 /*         the number of Givens rotations performed on the I-th */
00170 /*         problem on the computation tree. */
00171 
00172 /*  GIVCOL (output) INTEGER array, */
00173 /*         dimension ( LDGCOL, 2 * NLVL ) if ICOMPQ = 1, and not */
00174 /*         referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
00175 /*         GIVCOL(1, 2 *I - 1) and GIVCOL(1, 2 *I) record the locations */
00176 /*         of Givens rotations performed on the I-th level on the */
00177 /*         computation tree. */
00178 
00179 /*  LDGCOL (input) INTEGER, LDGCOL = > N. */
00180 /*         The leading dimension of arrays GIVCOL and PERM. */
00181 
00182 /*  PERM   (output) INTEGER array, */
00183 /*         dimension ( LDGCOL, NLVL ) if ICOMPQ = 1, and not referenced */
00184 /*         if ICOMPQ = 0. If ICOMPQ = 1, on exit, PERM(1, I) records */
00185 /*         permutations done on the I-th level of the computation tree. */
00186 
00187 /*  GIVNUM (output) DOUBLE PRECISION array, */
00188 /*         dimension ( LDU,  2 * NLVL ) if ICOMPQ = 1, and not */
00189 /*         referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
00190 /*         GIVNUM(1, 2 *I - 1) and GIVNUM(1, 2 *I) record the C- and S- */
00191 /*         values of Givens rotations performed on the I-th level on */
00192 /*         the computation tree. */
00193 
00194 /*  C      (output) DOUBLE PRECISION array, */
00195 /*         dimension ( N ) if ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. */
00196 /*         If ICOMPQ = 1 and the I-th subproblem is not square, on exit, */
00197 /*         C( I ) contains the C-value of a Givens rotation related to */
00198 /*         the right null space of the I-th subproblem. */
00199 
00200 /*  S      (output) DOUBLE PRECISION array, dimension ( N ) if */
00201 /*         ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. If ICOMPQ = 1 */
00202 /*         and the I-th subproblem is not square, on exit, S( I ) */
00203 /*         contains the S-value of a Givens rotation related to */
00204 /*         the right null space of the I-th subproblem. */
00205 
00206 /*  WORK   (workspace) DOUBLE PRECISION array, dimension */
00207 /*         (6 * N + (SMLSIZ + 1)*(SMLSIZ + 1)). */
00208 
00209 /*  IWORK  (workspace) INTEGER array. */
00210 /*         Dimension must be at least (7 * N). */
00211 
00212 /*  INFO   (output) INTEGER */
00213 /*          = 0:  successful exit. */
00214 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00215 /*          > 0:  if INFO = 1, an singular value did not converge */
00216 
00217 /*  Further Details */
00218 /*  =============== */
00219 
00220 /*  Based on contributions by */
00221 /*     Ming Gu and Huan Ren, Computer Science Division, University of */
00222 /*     California at Berkeley, USA */
00223 
00224 /*  ===================================================================== */
00225 
00226 /*     .. Parameters .. */
00227 /*     .. */
00228 /*     .. Local Scalars .. */
00229 /*     .. */
00230 /*     .. External Subroutines .. */
00231 /*     .. */
00232 /*     .. Executable Statements .. */
00233 
00234 /*     Test the input parameters. */
00235 
00236     /* Parameter adjustments */
00237     --d__;
00238     --e;
00239     givnum_dim1 = *ldu;
00240     givnum_offset = 1 + givnum_dim1;
00241     givnum -= givnum_offset;
00242     poles_dim1 = *ldu;
00243     poles_offset = 1 + poles_dim1;
00244     poles -= poles_offset;
00245     z_dim1 = *ldu;
00246     z_offset = 1 + z_dim1;
00247     z__ -= z_offset;
00248     difr_dim1 = *ldu;
00249     difr_offset = 1 + difr_dim1;
00250     difr -= difr_offset;
00251     difl_dim1 = *ldu;
00252     difl_offset = 1 + difl_dim1;
00253     difl -= difl_offset;
00254     vt_dim1 = *ldu;
00255     vt_offset = 1 + vt_dim1;
00256     vt -= vt_offset;
00257     u_dim1 = *ldu;
00258     u_offset = 1 + u_dim1;
00259     u -= u_offset;
00260     --k;
00261     --givptr;
00262     perm_dim1 = *ldgcol;
00263     perm_offset = 1 + perm_dim1;
00264     perm -= perm_offset;
00265     givcol_dim1 = *ldgcol;
00266     givcol_offset = 1 + givcol_dim1;
00267     givcol -= givcol_offset;
00268     --c__;
00269     --s;
00270     --work;
00271     --iwork;
00272 
00273     /* Function Body */
00274     *info = 0;
00275 
00276     if (*icompq < 0 || *icompq > 1) {
00277         *info = -1;
00278     } else if (*smlsiz < 3) {
00279         *info = -2;
00280     } else if (*n < 0) {
00281         *info = -3;
00282     } else if (*sqre < 0 || *sqre > 1) {
00283         *info = -4;
00284     } else if (*ldu < *n + *sqre) {
00285         *info = -8;
00286     } else if (*ldgcol < *n) {
00287         *info = -17;
00288     }
00289     if (*info != 0) {
00290         i__1 = -(*info);
00291         xerbla_("DLASDA", &i__1);
00292         return 0;
00293     }
00294 
00295     m = *n + *sqre;
00296 
00297 /*     If the input matrix is too small, call DLASDQ to find the SVD. */
00298 
00299     if (*n <= *smlsiz) {
00300         if (*icompq == 0) {
00301             dlasdq_("U", sqre, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
00302                     vt_offset], ldu, &u[u_offset], ldu, &u[u_offset], ldu, &
00303                     work[1], info);
00304         } else {
00305             dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
00306 , ldu, &u[u_offset], ldu, &u[u_offset], ldu, &work[1], 
00307                     info);
00308         }
00309         return 0;
00310     }
00311 
00312 /*     Book-keeping and  set up the computation tree. */
00313 
00314     inode = 1;
00315     ndiml = inode + *n;
00316     ndimr = ndiml + *n;
00317     idxq = ndimr + *n;
00318     iwk = idxq + *n;
00319 
00320     ncc = 0;
00321     nru = 0;
00322 
00323     smlszp = *smlsiz + 1;
00324     vf = 1;
00325     vl = vf + m;
00326     nwork1 = vl + m;
00327     nwork2 = nwork1 + smlszp * smlszp;
00328 
00329     dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr], 
00330             smlsiz);
00331 
00332 /*     for the nodes on bottom level of the tree, solve */
00333 /*     their subproblems by DLASDQ. */
00334 
00335     ndb1 = (nd + 1) / 2;
00336     i__1 = nd;
00337     for (i__ = ndb1; i__ <= i__1; ++i__) {
00338 
00339 /*        IC : center row of each node */
00340 /*        NL : number of rows of left  subproblem */
00341 /*        NR : number of rows of right subproblem */
00342 /*        NLF: starting row of the left   subproblem */
00343 /*        NRF: starting row of the right  subproblem */
00344 
00345         i1 = i__ - 1;
00346         ic = iwork[inode + i1];
00347         nl = iwork[ndiml + i1];
00348         nlp1 = nl + 1;
00349         nr = iwork[ndimr + i1];
00350         nlf = ic - nl;
00351         nrf = ic + 1;
00352         idxqi = idxq + nlf - 2;
00353         vfi = vf + nlf - 1;
00354         vli = vl + nlf - 1;
00355         sqrei = 1;
00356         if (*icompq == 0) {
00357             dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
00358             dlasdq_("U", &sqrei, &nl, &nlp1, &nru, &ncc, &d__[nlf], &e[nlf], &
00359                     work[nwork1], &smlszp, &work[nwork2], &nl, &work[nwork2], 
00360                     &nl, &work[nwork2], info);
00361             itemp = nwork1 + nl * smlszp;
00362             dcopy_(&nlp1, &work[nwork1], &c__1, &work[vfi], &c__1);
00363             dcopy_(&nlp1, &work[itemp], &c__1, &work[vli], &c__1);
00364         } else {
00365             dlaset_("A", &nl, &nl, &c_b11, &c_b12, &u[nlf + u_dim1], ldu);
00366             dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &vt[nlf + vt_dim1], 
00367                     ldu);
00368             dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &
00369                     vt[nlf + vt_dim1], ldu, &u[nlf + u_dim1], ldu, &u[nlf + 
00370                     u_dim1], ldu, &work[nwork1], info);
00371             dcopy_(&nlp1, &vt[nlf + vt_dim1], &c__1, &work[vfi], &c__1);
00372             dcopy_(&nlp1, &vt[nlf + nlp1 * vt_dim1], &c__1, &work[vli], &c__1)
00373                     ;
00374         }
00375         if (*info != 0) {
00376             return 0;
00377         }
00378         i__2 = nl;
00379         for (j = 1; j <= i__2; ++j) {
00380             iwork[idxqi + j] = j;
00381 /* L10: */
00382         }
00383         if (i__ == nd && *sqre == 0) {
00384             sqrei = 0;
00385         } else {
00386             sqrei = 1;
00387         }
00388         idxqi += nlp1;
00389         vfi += nlp1;
00390         vli += nlp1;
00391         nrp1 = nr + sqrei;
00392         if (*icompq == 0) {
00393             dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
00394             dlasdq_("U", &sqrei, &nr, &nrp1, &nru, &ncc, &d__[nrf], &e[nrf], &
00395                     work[nwork1], &smlszp, &work[nwork2], &nr, &work[nwork2], 
00396                     &nr, &work[nwork2], info);
00397             itemp = nwork1 + (nrp1 - 1) * smlszp;
00398             dcopy_(&nrp1, &work[nwork1], &c__1, &work[vfi], &c__1);
00399             dcopy_(&nrp1, &work[itemp], &c__1, &work[vli], &c__1);
00400         } else {
00401             dlaset_("A", &nr, &nr, &c_b11, &c_b12, &u[nrf + u_dim1], ldu);
00402             dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &vt[nrf + vt_dim1], 
00403                     ldu);
00404             dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &
00405                     vt[nrf + vt_dim1], ldu, &u[nrf + u_dim1], ldu, &u[nrf + 
00406                     u_dim1], ldu, &work[nwork1], info);
00407             dcopy_(&nrp1, &vt[nrf + vt_dim1], &c__1, &work[vfi], &c__1);
00408             dcopy_(&nrp1, &vt[nrf + nrp1 * vt_dim1], &c__1, &work[vli], &c__1)
00409                     ;
00410         }
00411         if (*info != 0) {
00412             return 0;
00413         }
00414         i__2 = nr;
00415         for (j = 1; j <= i__2; ++j) {
00416             iwork[idxqi + j] = j;
00417 /* L20: */
00418         }
00419 /* L30: */
00420     }
00421 
00422 /*     Now conquer each subproblem bottom-up. */
00423 
00424     j = pow_ii(&c__2, &nlvl);
00425     for (lvl = nlvl; lvl >= 1; --lvl) {
00426         lvl2 = (lvl << 1) - 1;
00427 
00428 /*        Find the first node LF and last node LL on */
00429 /*        the current level LVL. */
00430 
00431         if (lvl == 1) {
00432             lf = 1;
00433             ll = 1;
00434         } else {
00435             i__1 = lvl - 1;
00436             lf = pow_ii(&c__2, &i__1);
00437             ll = (lf << 1) - 1;
00438         }
00439         i__1 = ll;
00440         for (i__ = lf; i__ <= i__1; ++i__) {
00441             im1 = i__ - 1;
00442             ic = iwork[inode + im1];
00443             nl = iwork[ndiml + im1];
00444             nr = iwork[ndimr + im1];
00445             nlf = ic - nl;
00446             nrf = ic + 1;
00447             if (i__ == ll) {
00448                 sqrei = *sqre;
00449             } else {
00450                 sqrei = 1;
00451             }
00452             vfi = vf + nlf - 1;
00453             vli = vl + nlf - 1;
00454             idxqi = idxq + nlf - 1;
00455             alpha = d__[ic];
00456             beta = e[ic];
00457             if (*icompq == 0) {
00458                 dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
00459                         work[vli], &alpha, &beta, &iwork[idxqi], &perm[
00460                         perm_offset], &givptr[1], &givcol[givcol_offset], 
00461                         ldgcol, &givnum[givnum_offset], ldu, &poles[
00462                         poles_offset], &difl[difl_offset], &difr[difr_offset], 
00463                          &z__[z_offset], &k[1], &c__[1], &s[1], &work[nwork1], 
00464                          &iwork[iwk], info);
00465             } else {
00466                 --j;
00467                 dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
00468                         work[vli], &alpha, &beta, &iwork[idxqi], &perm[nlf + 
00469                         lvl * perm_dim1], &givptr[j], &givcol[nlf + lvl2 * 
00470                         givcol_dim1], ldgcol, &givnum[nlf + lvl2 * 
00471                         givnum_dim1], ldu, &poles[nlf + lvl2 * poles_dim1], &
00472                         difl[nlf + lvl * difl_dim1], &difr[nlf + lvl2 * 
00473                         difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[j], 
00474                         &s[j], &work[nwork1], &iwork[iwk], info);
00475             }
00476             if (*info != 0) {
00477                 return 0;
00478             }
00479 /* L40: */
00480         }
00481 /* L50: */
00482     }
00483 
00484     return 0;
00485 
00486 /*     End of DLASDA */
00487 
00488 } /* dlasda_ */


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