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


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