slasd3.c
Go to the documentation of this file.
00001 /* slasd3.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__1 = 1;
00019 static integer c__0 = 0;
00020 static real c_b13 = 1.f;
00021 static real c_b26 = 0.f;
00022 
00023 /* Subroutine */ int slasd3_(integer *nl, integer *nr, integer *sqre, integer 
00024         *k, real *d__, real *q, integer *ldq, real *dsigma, real *u, integer *
00025         ldu, real *u2, integer *ldu2, real *vt, integer *ldvt, real *vt2, 
00026         integer *ldvt2, integer *idxc, integer *ctot, real *z__, integer *
00027         info)
00028 {
00029     /* System generated locals */
00030     integer q_dim1, q_offset, u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1, 
00031             vt_offset, vt2_dim1, vt2_offset, i__1, i__2;
00032     real r__1, r__2;
00033 
00034     /* Builtin functions */
00035     double sqrt(doublereal), r_sign(real *, real *);
00036 
00037     /* Local variables */
00038     integer i__, j, m, n, jc;
00039     real rho;
00040     integer nlp1, nlp2, nrp1;
00041     real temp;
00042     extern doublereal snrm2_(integer *, real *, integer *);
00043     integer ctemp;
00044     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00045             integer *, real *, real *, integer *, real *, integer *, real *, 
00046             real *, integer *);
00047     integer ktemp;
00048     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00049             integer *);
00050     extern doublereal slamc3_(real *, real *);
00051     extern /* Subroutine */ int slasd4_(integer *, integer *, real *, real *, 
00052             real *, real *, real *, real *, integer *), xerbla_(char *, 
00053             integer *), slascl_(char *, integer *, integer *, real *, 
00054             real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *, 
00055             real *, integer *);
00056 
00057 
00058 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00059 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00060 /*     November 2006 */
00061 
00062 /*     .. Scalar Arguments .. */
00063 /*     .. */
00064 /*     .. Array Arguments .. */
00065 /*     .. */
00066 
00067 /*  Purpose */
00068 /*  ======= */
00069 
00070 /*  SLASD3 finds all the square roots of the roots of the secular */
00071 /*  equation, as defined by the values in D and Z.  It makes the */
00072 /*  appropriate calls to SLASD4 and then updates the singular */
00073 /*  vectors by matrix multiplication. */
00074 
00075 /*  This code makes very mild assumptions about floating point */
00076 /*  arithmetic. It will work on machines with a guard digit in */
00077 /*  add/subtract, or on those binary machines without guard digits */
00078 /*  which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
00079 /*  It could conceivably fail on hexadecimal or decimal machines */
00080 /*  without guard digits, but we know of none. */
00081 
00082 /*  SLASD3 is called from SLASD1. */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  NL     (input) INTEGER */
00088 /*         The row dimension of the upper block.  NL >= 1. */
00089 
00090 /*  NR     (input) INTEGER */
00091 /*         The row dimension of the lower block.  NR >= 1. */
00092 
00093 /*  SQRE   (input) INTEGER */
00094 /*         = 0: the lower block is an NR-by-NR square matrix. */
00095 /*         = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
00096 
00097 /*         The bidiagonal matrix has N = NL + NR + 1 rows and */
00098 /*         M = N + SQRE >= N columns. */
00099 
00100 /*  K      (input) INTEGER */
00101 /*         The size of the secular equation, 1 =< K = < N. */
00102 
00103 /*  D      (output) REAL array, dimension(K) */
00104 /*         On exit the square roots of the roots of the secular equation, */
00105 /*         in ascending order. */
00106 
00107 /*  Q      (workspace) REAL array, */
00108 /*                     dimension at least (LDQ,K). */
00109 
00110 /*  LDQ    (input) INTEGER */
00111 /*         The leading dimension of the array Q.  LDQ >= K. */
00112 
00113 /*  DSIGMA (input/output) REAL array, dimension(K) */
00114 /*         The first K elements of this array contain the old roots */
00115 /*         of the deflated updating problem.  These are the poles */
00116 /*         of the secular equation. */
00117 
00118 /*  U      (output) REAL array, dimension (LDU, N) */
00119 /*         The last N - K columns of this matrix contain the deflated */
00120 /*         left singular vectors. */
00121 
00122 /*  LDU    (input) INTEGER */
00123 /*         The leading dimension of the array U.  LDU >= N. */
00124 
00125 /*  U2     (input) REAL array, dimension (LDU2, N) */
00126 /*         The first K columns of this matrix contain the non-deflated */
00127 /*         left singular vectors for the split problem. */
00128 
00129 /*  LDU2   (input) INTEGER */
00130 /*         The leading dimension of the array U2.  LDU2 >= N. */
00131 
00132 /*  VT     (output) REAL array, dimension (LDVT, M) */
00133 /*         The last M - K columns of VT' contain the deflated */
00134 /*         right singular vectors. */
00135 
00136 /*  LDVT   (input) INTEGER */
00137 /*         The leading dimension of the array VT.  LDVT >= N. */
00138 
00139 /*  VT2    (input/output) REAL array, dimension (LDVT2, N) */
00140 /*         The first K columns of VT2' contain the non-deflated */
00141 /*         right singular vectors for the split problem. */
00142 
00143 /*  LDVT2  (input) INTEGER */
00144 /*         The leading dimension of the array VT2.  LDVT2 >= N. */
00145 
00146 /*  IDXC   (input) INTEGER array, dimension (N) */
00147 /*         The permutation used to arrange the columns of U (and rows of */
00148 /*         VT) into three groups:  the first group contains non-zero */
00149 /*         entries only at and above (or before) NL +1; the second */
00150 /*         contains non-zero entries only at and below (or after) NL+2; */
00151 /*         and the third is dense. The first column of U and the row of */
00152 /*         VT are treated separately, however. */
00153 
00154 /*         The rows of the singular vectors found by SLASD4 */
00155 /*         must be likewise permuted before the matrix multiplies can */
00156 /*         take place. */
00157 
00158 /*  CTOT   (input) INTEGER array, dimension (4) */
00159 /*         A count of the total number of the various types of columns */
00160 /*         in U (or rows in VT), as described in IDXC. The fourth column */
00161 /*         type is any column which has been deflated. */
00162 
00163 /*  Z      (input/output) REAL array, dimension (K) */
00164 /*         The first K elements of this array contain the components */
00165 /*         of the deflation-adjusted updating row vector. */
00166 
00167 /*  INFO   (output) INTEGER */
00168 /*         = 0:  successful exit. */
00169 /*         < 0:  if INFO = -i, the i-th argument had an illegal value. */
00170 /*         > 0:  if INFO = 1, an singular value did not converge */
00171 
00172 /*  Further Details */
00173 /*  =============== */
00174 
00175 /*  Based on contributions by */
00176 /*     Ming Gu and Huan Ren, Computer Science Division, University of */
00177 /*     California at Berkeley, USA */
00178 
00179 /*  ===================================================================== */
00180 
00181 /*     .. Parameters .. */
00182 /*     .. */
00183 /*     .. Local Scalars .. */
00184 /*     .. */
00185 /*     .. External Functions .. */
00186 /*     .. */
00187 /*     .. External Subroutines .. */
00188 /*     .. */
00189 /*     .. Intrinsic Functions .. */
00190 /*     .. */
00191 /*     .. Executable Statements .. */
00192 
00193 /*     Test the input parameters. */
00194 
00195     /* Parameter adjustments */
00196     --d__;
00197     q_dim1 = *ldq;
00198     q_offset = 1 + q_dim1;
00199     q -= q_offset;
00200     --dsigma;
00201     u_dim1 = *ldu;
00202     u_offset = 1 + u_dim1;
00203     u -= u_offset;
00204     u2_dim1 = *ldu2;
00205     u2_offset = 1 + u2_dim1;
00206     u2 -= u2_offset;
00207     vt_dim1 = *ldvt;
00208     vt_offset = 1 + vt_dim1;
00209     vt -= vt_offset;
00210     vt2_dim1 = *ldvt2;
00211     vt2_offset = 1 + vt2_dim1;
00212     vt2 -= vt2_offset;
00213     --idxc;
00214     --ctot;
00215     --z__;
00216 
00217     /* Function Body */
00218     *info = 0;
00219 
00220     if (*nl < 1) {
00221         *info = -1;
00222     } else if (*nr < 1) {
00223         *info = -2;
00224     } else if (*sqre != 1 && *sqre != 0) {
00225         *info = -3;
00226     }
00227 
00228     n = *nl + *nr + 1;
00229     m = n + *sqre;
00230     nlp1 = *nl + 1;
00231     nlp2 = *nl + 2;
00232 
00233     if (*k < 1 || *k > n) {
00234         *info = -4;
00235     } else if (*ldq < *k) {
00236         *info = -7;
00237     } else if (*ldu < n) {
00238         *info = -10;
00239     } else if (*ldu2 < n) {
00240         *info = -12;
00241     } else if (*ldvt < m) {
00242         *info = -14;
00243     } else if (*ldvt2 < m) {
00244         *info = -16;
00245     }
00246     if (*info != 0) {
00247         i__1 = -(*info);
00248         xerbla_("SLASD3", &i__1);
00249         return 0;
00250     }
00251 
00252 /*     Quick return if possible */
00253 
00254     if (*k == 1) {
00255         d__[1] = dabs(z__[1]);
00256         scopy_(&m, &vt2[vt2_dim1 + 1], ldvt2, &vt[vt_dim1 + 1], ldvt);
00257         if (z__[1] > 0.f) {
00258             scopy_(&n, &u2[u2_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
00259         } else {
00260             i__1 = n;
00261             for (i__ = 1; i__ <= i__1; ++i__) {
00262                 u[i__ + u_dim1] = -u2[i__ + u2_dim1];
00263 /* L10: */
00264             }
00265         }
00266         return 0;
00267     }
00268 
00269 /*     Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can */
00270 /*     be computed with high relative accuracy (barring over/underflow). */
00271 /*     This is a problem on machines without a guard digit in */
00272 /*     add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
00273 /*     The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), */
00274 /*     which on any of these machines zeros out the bottommost */
00275 /*     bit of DSIGMA(I) if it is 1; this makes the subsequent */
00276 /*     subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation */
00277 /*     occurs. On binary machines with a guard digit (almost all */
00278 /*     machines) it does not change DSIGMA(I) at all. On hexadecimal */
00279 /*     and decimal machines with a guard digit, it slightly */
00280 /*     changes the bottommost bits of DSIGMA(I). It does not account */
00281 /*     for hexadecimal or decimal machines without guard digits */
00282 /*     (we know of none). We use a subroutine call to compute */
00283 /*     2*DSIGMA(I) to prevent optimizing compilers from eliminating */
00284 /*     this code. */
00285 
00286     i__1 = *k;
00287     for (i__ = 1; i__ <= i__1; ++i__) {
00288         dsigma[i__] = slamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
00289 /* L20: */
00290     }
00291 
00292 /*     Keep a copy of Z. */
00293 
00294     scopy_(k, &z__[1], &c__1, &q[q_offset], &c__1);
00295 
00296 /*     Normalize Z. */
00297 
00298     rho = snrm2_(k, &z__[1], &c__1);
00299     slascl_("G", &c__0, &c__0, &rho, &c_b13, k, &c__1, &z__[1], k, info);
00300     rho *= rho;
00301 
00302 /*     Find the new singular values. */
00303 
00304     i__1 = *k;
00305     for (j = 1; j <= i__1; ++j) {
00306         slasd4_(k, &j, &dsigma[1], &z__[1], &u[j * u_dim1 + 1], &rho, &d__[j], 
00307                  &vt[j * vt_dim1 + 1], info);
00308 
00309 /*        If the zero finder fails, the computation is terminated. */
00310 
00311         if (*info != 0) {
00312             return 0;
00313         }
00314 /* L30: */
00315     }
00316 
00317 /*     Compute updated Z. */
00318 
00319     i__1 = *k;
00320     for (i__ = 1; i__ <= i__1; ++i__) {
00321         z__[i__] = u[i__ + *k * u_dim1] * vt[i__ + *k * vt_dim1];
00322         i__2 = i__ - 1;
00323         for (j = 1; j <= i__2; ++j) {
00324             z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
00325                     i__] - dsigma[j]) / (dsigma[i__] + dsigma[j]);
00326 /* L40: */
00327         }
00328         i__2 = *k - 1;
00329         for (j = i__; j <= i__2; ++j) {
00330             z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
00331                     i__] - dsigma[j + 1]) / (dsigma[i__] + dsigma[j + 1]);
00332 /* L50: */
00333         }
00334         r__2 = sqrt((r__1 = z__[i__], dabs(r__1)));
00335         z__[i__] = r_sign(&r__2, &q[i__ + q_dim1]);
00336 /* L60: */
00337     }
00338 
00339 /*     Compute left singular vectors of the modified diagonal matrix, */
00340 /*     and store related information for the right singular vectors. */
00341 
00342     i__1 = *k;
00343     for (i__ = 1; i__ <= i__1; ++i__) {
00344         vt[i__ * vt_dim1 + 1] = z__[1] / u[i__ * u_dim1 + 1] / vt[i__ * 
00345                 vt_dim1 + 1];
00346         u[i__ * u_dim1 + 1] = -1.f;
00347         i__2 = *k;
00348         for (j = 2; j <= i__2; ++j) {
00349             vt[j + i__ * vt_dim1] = z__[j] / u[j + i__ * u_dim1] / vt[j + i__ 
00350                     * vt_dim1];
00351             u[j + i__ * u_dim1] = dsigma[j] * vt[j + i__ * vt_dim1];
00352 /* L70: */
00353         }
00354         temp = snrm2_(k, &u[i__ * u_dim1 + 1], &c__1);
00355         q[i__ * q_dim1 + 1] = u[i__ * u_dim1 + 1] / temp;
00356         i__2 = *k;
00357         for (j = 2; j <= i__2; ++j) {
00358             jc = idxc[j];
00359             q[j + i__ * q_dim1] = u[jc + i__ * u_dim1] / temp;
00360 /* L80: */
00361         }
00362 /* L90: */
00363     }
00364 
00365 /*     Update the left singular vector matrix. */
00366 
00367     if (*k == 2) {
00368         sgemm_("N", "N", &n, k, k, &c_b13, &u2[u2_offset], ldu2, &q[q_offset], 
00369                  ldq, &c_b26, &u[u_offset], ldu);
00370         goto L100;
00371     }
00372     if (ctot[1] > 0) {
00373         sgemm_("N", "N", nl, k, &ctot[1], &c_b13, &u2[(u2_dim1 << 1) + 1], 
00374                 ldu2, &q[q_dim1 + 2], ldq, &c_b26, &u[u_dim1 + 1], ldu);
00375         if (ctot[3] > 0) {
00376             ktemp = ctot[1] + 2 + ctot[2];
00377             sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1]
00378 , ldu2, &q[ktemp + q_dim1], ldq, &c_b13, &u[u_dim1 + 1], 
00379                     ldu);
00380         }
00381     } else if (ctot[3] > 0) {
00382         ktemp = ctot[1] + 2 + ctot[2];
00383         sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1], 
00384                 ldu2, &q[ktemp + q_dim1], ldq, &c_b26, &u[u_dim1 + 1], ldu);
00385     } else {
00386         slacpy_("F", nl, k, &u2[u2_offset], ldu2, &u[u_offset], ldu);
00387     }
00388     scopy_(k, &q[q_dim1 + 1], ldq, &u[nlp1 + u_dim1], ldu);
00389     ktemp = ctot[1] + 2;
00390     ctemp = ctot[2] + ctot[3];
00391     sgemm_("N", "N", nr, k, &ctemp, &c_b13, &u2[nlp2 + ktemp * u2_dim1], ldu2, 
00392              &q[ktemp + q_dim1], ldq, &c_b26, &u[nlp2 + u_dim1], ldu);
00393 
00394 /*     Generate the right singular vectors. */
00395 
00396 L100:
00397     i__1 = *k;
00398     for (i__ = 1; i__ <= i__1; ++i__) {
00399         temp = snrm2_(k, &vt[i__ * vt_dim1 + 1], &c__1);
00400         q[i__ + q_dim1] = vt[i__ * vt_dim1 + 1] / temp;
00401         i__2 = *k;
00402         for (j = 2; j <= i__2; ++j) {
00403             jc = idxc[j];
00404             q[i__ + j * q_dim1] = vt[jc + i__ * vt_dim1] / temp;
00405 /* L110: */
00406         }
00407 /* L120: */
00408     }
00409 
00410 /*     Update the right singular vector matrix. */
00411 
00412     if (*k == 2) {
00413         sgemm_("N", "N", k, &m, k, &c_b13, &q[q_offset], ldq, &vt2[vt2_offset]
00414 , ldvt2, &c_b26, &vt[vt_offset], ldvt);
00415         return 0;
00416     }
00417     ktemp = ctot[1] + 1;
00418     sgemm_("N", "N", k, &nlp1, &ktemp, &c_b13, &q[q_dim1 + 1], ldq, &vt2[
00419             vt2_dim1 + 1], ldvt2, &c_b26, &vt[vt_dim1 + 1], ldvt);
00420     ktemp = ctot[1] + 2 + ctot[2];
00421     if (ktemp <= *ldvt2) {
00422         sgemm_("N", "N", k, &nlp1, &ctot[3], &c_b13, &q[ktemp * q_dim1 + 1], 
00423                 ldq, &vt2[ktemp + vt2_dim1], ldvt2, &c_b13, &vt[vt_dim1 + 1], 
00424                 ldvt);
00425     }
00426 
00427     ktemp = ctot[1] + 1;
00428     nrp1 = *nr + *sqre;
00429     if (ktemp > 1) {
00430         i__1 = *k;
00431         for (i__ = 1; i__ <= i__1; ++i__) {
00432             q[i__ + ktemp * q_dim1] = q[i__ + q_dim1];
00433 /* L130: */
00434         }
00435         i__1 = m;
00436         for (i__ = nlp2; i__ <= i__1; ++i__) {
00437             vt2[ktemp + i__ * vt2_dim1] = vt2[i__ * vt2_dim1 + 1];
00438 /* L140: */
00439         }
00440     }
00441     ctemp = ctot[2] + 1 + ctot[3];
00442     sgemm_("N", "N", k, &nrp1, &ctemp, &c_b13, &q[ktemp * q_dim1 + 1], ldq, &
00443             vt2[ktemp + nlp2 * vt2_dim1], ldvt2, &c_b26, &vt[nlp2 * vt_dim1 + 
00444             1], ldvt);
00445 
00446     return 0;
00447 
00448 /*     End of SLASD3 */
00449 
00450 } /* slasd3_ */


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