slasd0.c
Go to the documentation of this file.
00001 /* slasd0.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 integer c__2 = 2;
00020 
00021 /* Subroutine */ int slasd0_(integer *n, integer *sqre, real *d__, real *e, 
00022         real *u, integer *ldu, real *vt, integer *ldvt, integer *smlsiz, 
00023         integer *iwork, real *work, integer *info)
00024 {
00025     /* System generated locals */
00026     integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
00027 
00028     /* Builtin functions */
00029     integer pow_ii(integer *, integer *);
00030 
00031     /* Local variables */
00032     integer i__, j, m, i1, ic, lf, nd, ll, nl, nr, im1, ncc, nlf, nrf, iwk, 
00033             lvl, ndb1, nlp1, nrp1;
00034     real beta;
00035     integer idxq, nlvl;
00036     real alpha;
00037     integer inode, ndiml, idxqc, ndimr, itemp, sqrei;
00038     extern /* Subroutine */ int slasd1_(integer *, integer *, integer *, real 
00039             *, real *, real *, real *, integer *, real *, integer *, integer *
00040 , integer *, real *, integer *), xerbla_(char *, integer *), slasdq_(char *, integer *, integer *, integer *, integer 
00041             *, integer *, real *, real *, real *, integer *, real *, integer *
00042 , real *, integer *, real *, integer *), slasdt_(integer *
00043 , integer *, integer *, integer *, integer *, integer *, integer *
00044 );
00045 
00046 
00047 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00048 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00049 /*     November 2006 */
00050 
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*     .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*  Using a divide and conquer approach, SLASD0 computes the singular */
00060 /*  value decomposition (SVD) of a real upper bidiagonal N-by-M */
00061 /*  matrix B with diagonal D and offdiagonal E, where M = N + SQRE. */
00062 /*  The algorithm computes orthogonal matrices U and VT such that */
00063 /*  B = U * S * VT. The singular values S are overwritten on D. */
00064 
00065 /*  A related subroutine, SLASDA, computes only the singular values, */
00066 /*  and optionally, the singular vectors in compact form. */
00067 
00068 /*  Arguments */
00069 /*  ========= */
00070 
00071 /*  N      (input) INTEGER */
00072 /*         On entry, the row dimension of the upper bidiagonal matrix. */
00073 /*         This is also the dimension of the main diagonal array D. */
00074 
00075 /*  SQRE   (input) INTEGER */
00076 /*         Specifies the column dimension of the bidiagonal matrix. */
00077 /*         = 0: The bidiagonal matrix has column dimension M = N; */
00078 /*         = 1: The bidiagonal matrix has column dimension M = N+1; */
00079 
00080 /*  D      (input/output) REAL array, dimension (N) */
00081 /*         On entry D contains the main diagonal of the bidiagonal */
00082 /*         matrix. */
00083 /*         On exit D, if INFO = 0, contains its singular values. */
00084 
00085 /*  E      (input) REAL array, dimension (M-1) */
00086 /*         Contains the subdiagonal entries of the bidiagonal matrix. */
00087 /*         On exit, E has been destroyed. */
00088 
00089 /*  U      (output) REAL array, dimension at least (LDQ, N) */
00090 /*         On exit, U contains the left singular vectors. */
00091 
00092 /*  LDU    (input) INTEGER */
00093 /*         On entry, leading dimension of U. */
00094 
00095 /*  VT     (output) REAL array, dimension at least (LDVT, M) */
00096 /*         On exit, VT' contains the right singular vectors. */
00097 
00098 /*  LDVT   (input) INTEGER */
00099 /*         On entry, leading dimension of VT. */
00100 
00101 /*  SMLSIZ (input) INTEGER */
00102 /*         On entry, maximum size of the subproblems at the */
00103 /*         bottom of the computation tree. */
00104 
00105 /*  IWORK  (workspace) INTEGER array, dimension (8*N) */
00106 
00107 /*  WORK   (workspace) REAL array, dimension (3*M**2+2*M) */
00108 
00109 /*  INFO   (output) INTEGER */
00110 /*          = 0:  successful exit. */
00111 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00112 /*          > 0:  if INFO = 1, an singular value did not converge */
00113 
00114 /*  Further Details */
00115 /*  =============== */
00116 
00117 /*  Based on contributions by */
00118 /*     Ming Gu and Huan Ren, Computer Science Division, University of */
00119 /*     California at Berkeley, USA */
00120 
00121 /*  ===================================================================== */
00122 
00123 /*     .. Local Scalars .. */
00124 /*     .. */
00125 /*     .. External Subroutines .. */
00126 /*     .. */
00127 /*     .. Executable Statements .. */
00128 
00129 /*     Test the input parameters. */
00130 
00131     /* Parameter adjustments */
00132     --d__;
00133     --e;
00134     u_dim1 = *ldu;
00135     u_offset = 1 + u_dim1;
00136     u -= u_offset;
00137     vt_dim1 = *ldvt;
00138     vt_offset = 1 + vt_dim1;
00139     vt -= vt_offset;
00140     --iwork;
00141     --work;
00142 
00143     /* Function Body */
00144     *info = 0;
00145 
00146     if (*n < 0) {
00147         *info = -1;
00148     } else if (*sqre < 0 || *sqre > 1) {
00149         *info = -2;
00150     }
00151 
00152     m = *n + *sqre;
00153 
00154     if (*ldu < *n) {
00155         *info = -6;
00156     } else if (*ldvt < m) {
00157         *info = -8;
00158     } else if (*smlsiz < 3) {
00159         *info = -9;
00160     }
00161     if (*info != 0) {
00162         i__1 = -(*info);
00163         xerbla_("SLASD0", &i__1);
00164         return 0;
00165     }
00166 
00167 /*     If the input matrix is too small, call SLASDQ to find the SVD. */
00168 
00169     if (*n <= *smlsiz) {
00170         slasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset], 
00171                 ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[1], info);
00172         return 0;
00173     }
00174 
00175 /*     Set up the computation tree. */
00176 
00177     inode = 1;
00178     ndiml = inode + *n;
00179     ndimr = ndiml + *n;
00180     idxq = ndimr + *n;
00181     iwk = idxq + *n;
00182     slasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr], 
00183             smlsiz);
00184 
00185 /*     For the nodes on bottom level of the tree, solve */
00186 /*     their subproblems by SLASDQ. */
00187 
00188     ndb1 = (nd + 1) / 2;
00189     ncc = 0;
00190     i__1 = nd;
00191     for (i__ = ndb1; i__ <= i__1; ++i__) {
00192 
00193 /*     IC : center row of each node */
00194 /*     NL : number of rows of left  subproblem */
00195 /*     NR : number of rows of right subproblem */
00196 /*     NLF: starting row of the left   subproblem */
00197 /*     NRF: starting row of the right  subproblem */
00198 
00199         i1 = i__ - 1;
00200         ic = iwork[inode + i1];
00201         nl = iwork[ndiml + i1];
00202         nlp1 = nl + 1;
00203         nr = iwork[ndimr + i1];
00204         nrp1 = nr + 1;
00205         nlf = ic - nl;
00206         nrf = ic + 1;
00207         sqrei = 1;
00208         slasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &vt[
00209                 nlf + nlf * vt_dim1], ldvt, &u[nlf + nlf * u_dim1], ldu, &u[
00210                 nlf + nlf * u_dim1], ldu, &work[1], info);
00211         if (*info != 0) {
00212             return 0;
00213         }
00214         itemp = idxq + nlf - 2;
00215         i__2 = nl;
00216         for (j = 1; j <= i__2; ++j) {
00217             iwork[itemp + j] = j;
00218 /* L10: */
00219         }
00220         if (i__ == nd) {
00221             sqrei = *sqre;
00222         } else {
00223             sqrei = 1;
00224         }
00225         nrp1 = nr + sqrei;
00226         slasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &vt[
00227                 nrf + nrf * vt_dim1], ldvt, &u[nrf + nrf * u_dim1], ldu, &u[
00228                 nrf + nrf * u_dim1], ldu, &work[1], info);
00229         if (*info != 0) {
00230             return 0;
00231         }
00232         itemp = idxq + ic;
00233         i__2 = nr;
00234         for (j = 1; j <= i__2; ++j) {
00235             iwork[itemp + j - 1] = j;
00236 /* L20: */
00237         }
00238 /* L30: */
00239     }
00240 
00241 /*     Now conquer each subproblem bottom-up. */
00242 
00243     for (lvl = nlvl; lvl >= 1; --lvl) {
00244 
00245 /*        Find the first node LF and last node LL on the */
00246 /*        current level LVL. */
00247 
00248         if (lvl == 1) {
00249             lf = 1;
00250             ll = 1;
00251         } else {
00252             i__1 = lvl - 1;
00253             lf = pow_ii(&c__2, &i__1);
00254             ll = (lf << 1) - 1;
00255         }
00256         i__1 = ll;
00257         for (i__ = lf; i__ <= i__1; ++i__) {
00258             im1 = i__ - 1;
00259             ic = iwork[inode + im1];
00260             nl = iwork[ndiml + im1];
00261             nr = iwork[ndimr + im1];
00262             nlf = ic - nl;
00263             if (*sqre == 0 && i__ == ll) {
00264                 sqrei = *sqre;
00265             } else {
00266                 sqrei = 1;
00267             }
00268             idxqc = idxq + nlf - 1;
00269             alpha = d__[ic];
00270             beta = e[ic];
00271             slasd1_(&nl, &nr, &sqrei, &d__[nlf], &alpha, &beta, &u[nlf + nlf *
00272                      u_dim1], ldu, &vt[nlf + nlf * vt_dim1], ldvt, &iwork[
00273                     idxqc], &iwork[iwk], &work[1], info);
00274             if (*info != 0) {
00275                 return 0;
00276             }
00277 /* L40: */
00278         }
00279 /* L50: */
00280     }
00281 
00282     return 0;
00283 
00284 /*     End of SLASD0 */
00285 
00286 } /* slasd0_ */


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