dlals0.c
Go to the documentation of this file.
00001 /* dlals0.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 doublereal c_b5 = -1.;
00019 static integer c__1 = 1;
00020 static doublereal c_b11 = 1.;
00021 static doublereal c_b13 = 0.;
00022 static integer c__0 = 0;
00023 
00024 /* Subroutine */ int dlals0_(integer *icompq, integer *nl, integer *nr, 
00025         integer *sqre, integer *nrhs, doublereal *b, integer *ldb, doublereal 
00026         *bx, integer *ldbx, integer *perm, integer *givptr, integer *givcol, 
00027         integer *ldgcol, doublereal *givnum, integer *ldgnum, doublereal *
00028         poles, doublereal *difl, doublereal *difr, doublereal *z__, integer *
00029         k, doublereal *c__, doublereal *s, doublereal *work, integer *info)
00030 {
00031     /* System generated locals */
00032     integer givcol_dim1, givcol_offset, b_dim1, b_offset, bx_dim1, bx_offset, 
00033             difr_dim1, difr_offset, givnum_dim1, givnum_offset, poles_dim1, 
00034             poles_offset, i__1, i__2;
00035     doublereal d__1;
00036 
00037     /* Local variables */
00038     integer i__, j, m, n;
00039     doublereal dj;
00040     integer nlp1;
00041     doublereal temp;
00042     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *, 
00043             doublereal *, integer *, doublereal *, doublereal *);
00044     extern doublereal dnrm2_(integer *, doublereal *, integer *);
00045     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00046             integer *);
00047     doublereal diflj, difrj, dsigj;
00048     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
00049             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00050             doublereal *, doublereal *, integer *), dcopy_(integer *, 
00051             doublereal *, integer *, doublereal *, integer *);
00052     extern doublereal dlamc3_(doublereal *, doublereal *);
00053     extern /* Subroutine */ int 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     doublereal dsigjp;
00059 
00060 
00061 /*  -- LAPACK routine (version 3.2) -- */
00062 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00063 /*     November 2006 */
00064 
00065 /*     .. Scalar Arguments .. */
00066 /*     .. */
00067 /*     .. Array Arguments .. */
00068 /*     .. */
00069 
00070 /*  Purpose */
00071 /*  ======= */
00072 
00073 /*  DLALS0 applies back the multiplying factors of either the left or the */
00074 /*  right singular vector matrix of a diagonal matrix appended by a row */
00075 /*  to the right hand side matrix B in solving the least squares problem */
00076 /*  using the divide-and-conquer SVD approach. */
00077 
00078 /*  For the left singular vector matrix, three types of orthogonal */
00079 /*  matrices are involved: */
00080 
00081 /*  (1L) Givens rotations: the number of such rotations is GIVPTR; the */
00082 /*       pairs of columns/rows they were applied to are stored in GIVCOL; */
00083 /*       and the C- and S-values of these rotations are stored in GIVNUM. */
00084 
00085 /*  (2L) Permutation. The (NL+1)-st row of B is to be moved to the first */
00086 /*       row, and for J=2:N, PERM(J)-th row of B is to be moved to the */
00087 /*       J-th row. */
00088 
00089 /*  (3L) The left singular vector matrix of the remaining matrix. */
00090 
00091 /*  For the right singular vector matrix, four types of orthogonal */
00092 /*  matrices are involved: */
00093 
00094 /*  (1R) The right singular vector matrix of the remaining matrix. */
00095 
00096 /*  (2R) If SQRE = 1, one extra Givens rotation to generate the right */
00097 /*       null space. */
00098 
00099 /*  (3R) The inverse transformation of (2L). */
00100 
00101 /*  (4R) The inverse transformation of (1L). */
00102 
00103 /*  Arguments */
00104 /*  ========= */
00105 
00106 /*  ICOMPQ (input) INTEGER */
00107 /*         Specifies whether singular vectors are to be computed in */
00108 /*         factored form: */
00109 /*         = 0: Left singular vector matrix. */
00110 /*         = 1: Right singular vector matrix. */
00111 
00112 /*  NL     (input) INTEGER */
00113 /*         The row dimension of the upper block. NL >= 1. */
00114 
00115 /*  NR     (input) INTEGER */
00116 /*         The row dimension of the lower block. NR >= 1. */
00117 
00118 /*  SQRE   (input) INTEGER */
00119 /*         = 0: the lower block is an NR-by-NR square matrix. */
00120 /*         = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
00121 
00122 /*         The bidiagonal matrix has row dimension N = NL + NR + 1, */
00123 /*         and column dimension M = N + SQRE. */
00124 
00125 /*  NRHS   (input) INTEGER */
00126 /*         The number of columns of B and BX. NRHS must be at least 1. */
00127 
00128 /*  B      (input/output) DOUBLE PRECISION array, dimension ( LDB, NRHS ) */
00129 /*         On input, B contains the right hand sides of the least */
00130 /*         squares problem in rows 1 through M. On output, B contains */
00131 /*         the solution X in rows 1 through N. */
00132 
00133 /*  LDB    (input) INTEGER */
00134 /*         The leading dimension of B. LDB must be at least */
00135 /*         max(1,MAX( M, N ) ). */
00136 
00137 /*  BX     (workspace) DOUBLE PRECISION array, dimension ( LDBX, NRHS ) */
00138 
00139 /*  LDBX   (input) INTEGER */
00140 /*         The leading dimension of BX. */
00141 
00142 /*  PERM   (input) INTEGER array, dimension ( N ) */
00143 /*         The permutations (from deflation and sorting) applied */
00144 /*         to the two blocks. */
00145 
00146 /*  GIVPTR (input) INTEGER */
00147 /*         The number of Givens rotations which took place in this */
00148 /*         subproblem. */
00149 
00150 /*  GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 ) */
00151 /*         Each pair of numbers indicates a pair of rows/columns */
00152 /*         involved in a Givens rotation. */
00153 
00154 /*  LDGCOL (input) INTEGER */
00155 /*         The leading dimension of GIVCOL, must be at least N. */
00156 
00157 /*  GIVNUM (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
00158 /*         Each number indicates the C or S value used in the */
00159 /*         corresponding Givens rotation. */
00160 
00161 /*  LDGNUM (input) INTEGER */
00162 /*         The leading dimension of arrays DIFR, POLES and */
00163 /*         GIVNUM, must be at least K. */
00164 
00165 /*  POLES  (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
00166 /*         On entry, POLES(1:K, 1) contains the new singular */
00167 /*         values obtained from solving the secular equation, and */
00168 /*         POLES(1:K, 2) is an array containing the poles in the secular */
00169 /*         equation. */
00170 
00171 /*  DIFL   (input) DOUBLE PRECISION array, dimension ( K ). */
00172 /*         On entry, DIFL(I) is the distance between I-th updated */
00173 /*         (undeflated) singular value and the I-th (undeflated) old */
00174 /*         singular value. */
00175 
00176 /*  DIFR   (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ). */
00177 /*         On entry, DIFR(I, 1) contains the distances between I-th */
00178 /*         updated (undeflated) singular value and the I+1-th */
00179 /*         (undeflated) old singular value. And DIFR(I, 2) is the */
00180 /*         normalizing factor for the I-th right singular vector. */
00181 
00182 /*  Z      (input) DOUBLE PRECISION array, dimension ( K ) */
00183 /*         Contain the components of the deflation-adjusted updating row */
00184 /*         vector. */
00185 
00186 /*  K      (input) INTEGER */
00187 /*         Contains the dimension of the non-deflated matrix, */
00188 /*         This is the order of the related secular equation. 1 <= K <=N. */
00189 
00190 /*  C      (input) DOUBLE PRECISION */
00191 /*         C contains garbage if SQRE =0 and the C-value of a Givens */
00192 /*         rotation related to the right null space if SQRE = 1. */
00193 
00194 /*  S      (input) DOUBLE PRECISION */
00195 /*         S contains garbage if SQRE =0 and the S-value of a Givens */
00196 /*         rotation related to the right null space if SQRE = 1. */
00197 
00198 /*  WORK   (workspace) DOUBLE PRECISION array, dimension ( K ) */
00199 
00200 /*  INFO   (output) INTEGER */
00201 /*          = 0:  successful exit. */
00202 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00203 
00204 /*  Further Details */
00205 /*  =============== */
00206 
00207 /*  Based on contributions by */
00208 /*     Ming Gu and Ren-Cang Li, Computer Science Division, University of */
00209 /*       California at Berkeley, USA */
00210 /*     Osni Marques, LBNL/NERSC, USA */
00211 
00212 /*  ===================================================================== */
00213 
00214 /*     .. Parameters .. */
00215 /*     .. */
00216 /*     .. Local Scalars .. */
00217 /*     .. */
00218 /*     .. External Subroutines .. */
00219 /*     .. */
00220 /*     .. External Functions .. */
00221 /*     .. */
00222 /*     .. Intrinsic Functions .. */
00223 /*     .. */
00224 /*     .. Executable Statements .. */
00225 
00226 /*     Test the input parameters. */
00227 
00228     /* Parameter adjustments */
00229     b_dim1 = *ldb;
00230     b_offset = 1 + b_dim1;
00231     b -= b_offset;
00232     bx_dim1 = *ldbx;
00233     bx_offset = 1 + bx_dim1;
00234     bx -= bx_offset;
00235     --perm;
00236     givcol_dim1 = *ldgcol;
00237     givcol_offset = 1 + givcol_dim1;
00238     givcol -= givcol_offset;
00239     difr_dim1 = *ldgnum;
00240     difr_offset = 1 + difr_dim1;
00241     difr -= difr_offset;
00242     poles_dim1 = *ldgnum;
00243     poles_offset = 1 + poles_dim1;
00244     poles -= poles_offset;
00245     givnum_dim1 = *ldgnum;
00246     givnum_offset = 1 + givnum_dim1;
00247     givnum -= givnum_offset;
00248     --difl;
00249     --z__;
00250     --work;
00251 
00252     /* Function Body */
00253     *info = 0;
00254 
00255     if (*icompq < 0 || *icompq > 1) {
00256         *info = -1;
00257     } else if (*nl < 1) {
00258         *info = -2;
00259     } else if (*nr < 1) {
00260         *info = -3;
00261     } else if (*sqre < 0 || *sqre > 1) {
00262         *info = -4;
00263     }
00264 
00265     n = *nl + *nr + 1;
00266 
00267     if (*nrhs < 1) {
00268         *info = -5;
00269     } else if (*ldb < n) {
00270         *info = -7;
00271     } else if (*ldbx < n) {
00272         *info = -9;
00273     } else if (*givptr < 0) {
00274         *info = -11;
00275     } else if (*ldgcol < n) {
00276         *info = -13;
00277     } else if (*ldgnum < n) {
00278         *info = -15;
00279     } else if (*k < 1) {
00280         *info = -20;
00281     }
00282     if (*info != 0) {
00283         i__1 = -(*info);
00284         xerbla_("DLALS0", &i__1);
00285         return 0;
00286     }
00287 
00288     m = n + *sqre;
00289     nlp1 = *nl + 1;
00290 
00291     if (*icompq == 0) {
00292 
00293 /*        Apply back orthogonal transformations from the left. */
00294 
00295 /*        Step (1L): apply back the Givens rotations performed. */
00296 
00297         i__1 = *givptr;
00298         for (i__ = 1; i__ <= i__1; ++i__) {
00299             drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
00300                     b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ + 
00301                     (givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
00302 /* L10: */
00303         }
00304 
00305 /*        Step (2L): permute rows of B. */
00306 
00307         dcopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
00308         i__1 = n;
00309         for (i__ = 2; i__ <= i__1; ++i__) {
00310             dcopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1], 
00311                     ldbx);
00312 /* L20: */
00313         }
00314 
00315 /*        Step (3L): apply the inverse of the left singular vector */
00316 /*        matrix to BX. */
00317 
00318         if (*k == 1) {
00319             dcopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
00320             if (z__[1] < 0.) {
00321                 dscal_(nrhs, &c_b5, &b[b_offset], ldb);
00322             }
00323         } else {
00324             i__1 = *k;
00325             for (j = 1; j <= i__1; ++j) {
00326                 diflj = difl[j];
00327                 dj = poles[j + poles_dim1];
00328                 dsigj = -poles[j + (poles_dim1 << 1)];
00329                 if (j < *k) {
00330                     difrj = -difr[j + difr_dim1];
00331                     dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
00332                 }
00333                 if (z__[j] == 0. || poles[j + (poles_dim1 << 1)] == 0.) {
00334                     work[j] = 0.;
00335                 } else {
00336                     work[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj /
00337                              (poles[j + (poles_dim1 << 1)] + dj);
00338                 }
00339                 i__2 = j - 1;
00340                 for (i__ = 1; i__ <= i__2; ++i__) {
00341                     if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] == 
00342                             0.) {
00343                         work[i__] = 0.;
00344                     } else {
00345                         work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__] 
00346                                 / (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
00347                                 dsigj) - diflj) / (poles[i__ + (poles_dim1 << 
00348                                 1)] + dj);
00349                     }
00350 /* L30: */
00351                 }
00352                 i__2 = *k;
00353                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00354                     if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] == 
00355                             0.) {
00356                         work[i__] = 0.;
00357                     } else {
00358                         work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__] 
00359                                 / (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
00360                                 dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
00361                                  1)] + dj);
00362                     }
00363 /* L40: */
00364                 }
00365                 work[1] = -1.;
00366                 temp = dnrm2_(k, &work[1], &c__1);
00367                 dgemv_("T", k, nrhs, &c_b11, &bx[bx_offset], ldbx, &work[1], &
00368                         c__1, &c_b13, &b[j + b_dim1], ldb);
00369                 dlascl_("G", &c__0, &c__0, &temp, &c_b11, &c__1, nrhs, &b[j + 
00370                         b_dim1], ldb, info);
00371 /* L50: */
00372             }
00373         }
00374 
00375 /*        Move the deflated rows of BX to B also. */
00376 
00377         if (*k < max(m,n)) {
00378             i__1 = n - *k;
00379             dlacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1 
00380                     + b_dim1], ldb);
00381         }
00382     } else {
00383 
00384 /*        Apply back the right orthogonal transformations. */
00385 
00386 /*        Step (1R): apply back the new right singular vector matrix */
00387 /*        to B. */
00388 
00389         if (*k == 1) {
00390             dcopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
00391         } else {
00392             i__1 = *k;
00393             for (j = 1; j <= i__1; ++j) {
00394                 dsigj = poles[j + (poles_dim1 << 1)];
00395                 if (z__[j] == 0.) {
00396                     work[j] = 0.;
00397                 } else {
00398                     work[j] = -z__[j] / difl[j] / (dsigj + poles[j + 
00399                             poles_dim1]) / difr[j + (difr_dim1 << 1)];
00400                 }
00401                 i__2 = j - 1;
00402                 for (i__ = 1; i__ <= i__2; ++i__) {
00403                     if (z__[j] == 0.) {
00404                         work[i__] = 0.;
00405                     } else {
00406                         d__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
00407                         work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difr[
00408                                 i__ + difr_dim1]) / (dsigj + poles[i__ + 
00409                                 poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
00410                     }
00411 /* L60: */
00412                 }
00413                 i__2 = *k;
00414                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00415                     if (z__[j] == 0.) {
00416                         work[i__] = 0.;
00417                     } else {
00418                         d__1 = -poles[i__ + (poles_dim1 << 1)];
00419                         work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difl[
00420                                 i__]) / (dsigj + poles[i__ + poles_dim1]) / 
00421                                 difr[i__ + (difr_dim1 << 1)];
00422                     }
00423 /* L70: */
00424                 }
00425                 dgemv_("T", k, nrhs, &c_b11, &b[b_offset], ldb, &work[1], &
00426                         c__1, &c_b13, &bx[j + bx_dim1], ldbx);
00427 /* L80: */
00428             }
00429         }
00430 
00431 /*        Step (2R): if SQRE = 1, apply back the rotation that is */
00432 /*        related to the right null space of the subproblem. */
00433 
00434         if (*sqre == 1) {
00435             dcopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
00436             drot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__, 
00437                     s);
00438         }
00439         if (*k < max(m,n)) {
00440             i__1 = n - *k;
00441             dlacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 + 
00442                     bx_dim1], ldbx);
00443         }
00444 
00445 /*        Step (3R): permute rows of B. */
00446 
00447         dcopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
00448         if (*sqre == 1) {
00449             dcopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
00450         }
00451         i__1 = n;
00452         for (i__ = 2; i__ <= i__1; ++i__) {
00453             dcopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1], 
00454                     ldb);
00455 /* L90: */
00456         }
00457 
00458 /*        Step (4R): apply back the Givens rotations performed. */
00459 
00460         for (i__ = *givptr; i__ >= 1; --i__) {
00461             d__1 = -givnum[i__ + givnum_dim1];
00462             drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
00463                     b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ + 
00464                     (givnum_dim1 << 1)], &d__1);
00465 /* L100: */
00466         }
00467     }
00468 
00469     return 0;
00470 
00471 /*     End of DLALS0 */
00472 
00473 } /* dlals0_ */


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