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


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