sgebd2.c
Go to the documentation of this file.
00001 /* sgebd2.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 
00020 /* Subroutine */ int sgebd2_(integer *m, integer *n, real *a, integer *lda, 
00021         real *d__, real *e, real *tauq, real *taup, real *work, integer *info)
00022 {
00023     /* System generated locals */
00024     integer a_dim1, a_offset, i__1, i__2, i__3;
00025 
00026     /* Local variables */
00027     integer i__;
00028     extern /* Subroutine */ int slarf_(char *, integer *, integer *, real *, 
00029             integer *, real *, real *, integer *, real *), xerbla_(
00030             char *, integer *), slarfg_(integer *, real *, real *, 
00031             integer *, real *);
00032 
00033 
00034 /*  -- LAPACK routine (version 3.2) -- */
00035 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00036 /*     November 2006 */
00037 
00038 /*     .. Scalar Arguments .. */
00039 /*     .. */
00040 /*     .. Array Arguments .. */
00041 /*     .. */
00042 
00043 /*  Purpose */
00044 /*  ======= */
00045 
00046 /*  SGEBD2 reduces a real general m by n matrix A to upper or lower */
00047 /*  bidiagonal form B by an orthogonal transformation: Q' * A * P = B. */
00048 
00049 /*  If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
00050 
00051 /*  Arguments */
00052 /*  ========= */
00053 
00054 /*  M       (input) INTEGER */
00055 /*          The number of rows in the matrix A.  M >= 0. */
00056 
00057 /*  N       (input) INTEGER */
00058 /*          The number of columns in the matrix A.  N >= 0. */
00059 
00060 /*  A       (input/output) REAL array, dimension (LDA,N) */
00061 /*          On entry, the m by n general matrix to be reduced. */
00062 /*          On exit, */
00063 /*          if m >= n, the diagonal and the first superdiagonal are */
00064 /*            overwritten with the upper bidiagonal matrix B; the */
00065 /*            elements below the diagonal, with the array TAUQ, represent */
00066 /*            the orthogonal matrix Q as a product of elementary */
00067 /*            reflectors, and the elements above the first superdiagonal, */
00068 /*            with the array TAUP, represent the orthogonal matrix P as */
00069 /*            a product of elementary reflectors; */
00070 /*          if m < n, the diagonal and the first subdiagonal are */
00071 /*            overwritten with the lower bidiagonal matrix B; the */
00072 /*            elements below the first subdiagonal, with the array TAUQ, */
00073 /*            represent the orthogonal matrix Q as a product of */
00074 /*            elementary reflectors, and the elements above the diagonal, */
00075 /*            with the array TAUP, represent the orthogonal matrix P as */
00076 /*            a product of elementary reflectors. */
00077 /*          See Further Details. */
00078 
00079 /*  LDA     (input) INTEGER */
00080 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00081 
00082 /*  D       (output) REAL array, dimension (min(M,N)) */
00083 /*          The diagonal elements of the bidiagonal matrix B: */
00084 /*          D(i) = A(i,i). */
00085 
00086 /*  E       (output) REAL array, dimension (min(M,N)-1) */
00087 /*          The off-diagonal elements of the bidiagonal matrix B: */
00088 /*          if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1; */
00089 /*          if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1. */
00090 
00091 /*  TAUQ    (output) REAL array dimension (min(M,N)) */
00092 /*          The scalar factors of the elementary reflectors which */
00093 /*          represent the orthogonal matrix Q. See Further Details. */
00094 
00095 /*  TAUP    (output) REAL array, dimension (min(M,N)) */
00096 /*          The scalar factors of the elementary reflectors which */
00097 /*          represent the orthogonal matrix P. See Further Details. */
00098 
00099 /*  WORK    (workspace) REAL array, dimension (max(M,N)) */
00100 
00101 /*  INFO    (output) INTEGER */
00102 /*          = 0: successful exit. */
00103 /*          < 0: if INFO = -i, the i-th argument had an illegal value. */
00104 
00105 /*  Further Details */
00106 /*  =============== */
00107 
00108 /*  The matrices Q and P are represented as products of elementary */
00109 /*  reflectors: */
00110 
00111 /*  If m >= n, */
00112 
00113 /*     Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1) */
00114 
00115 /*  Each H(i) and G(i) has the form: */
00116 
00117 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
00118 
00119 /*  where tauq and taup are real scalars, and v and u are real vectors; */
00120 /*  v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i); */
00121 /*  u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n); */
00122 /*  tauq is stored in TAUQ(i) and taup in TAUP(i). */
00123 
00124 /*  If m < n, */
00125 
00126 /*     Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m) */
00127 
00128 /*  Each H(i) and G(i) has the form: */
00129 
00130 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
00131 
00132 /*  where tauq and taup are real scalars, and v and u are real vectors; */
00133 /*  v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i); */
00134 /*  u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); */
00135 /*  tauq is stored in TAUQ(i) and taup in TAUP(i). */
00136 
00137 /*  The contents of A on exit are illustrated by the following examples: */
00138 
00139 /*  m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n): */
00140 
00141 /*    (  d   e   u1  u1  u1 )           (  d   u1  u1  u1  u1  u1 ) */
00142 /*    (  v1  d   e   u2  u2 )           (  e   d   u2  u2  u2  u2 ) */
00143 /*    (  v1  v2  d   e   u3 )           (  v1  e   d   u3  u3  u3 ) */
00144 /*    (  v1  v2  v3  d   e  )           (  v1  v2  e   d   u4  u4 ) */
00145 /*    (  v1  v2  v3  v4  d  )           (  v1  v2  v3  e   d   u5 ) */
00146 /*    (  v1  v2  v3  v4  v5 ) */
00147 
00148 /*  where d and e denote diagonal and off-diagonal elements of B, vi */
00149 /*  denotes an element of the vector defining H(i), and ui an element of */
00150 /*  the vector defining G(i). */
00151 
00152 /*  ===================================================================== */
00153 
00154 /*     .. Parameters .. */
00155 /*     .. */
00156 /*     .. Local Scalars .. */
00157 /*     .. */
00158 /*     .. External Subroutines .. */
00159 /*     .. */
00160 /*     .. Intrinsic Functions .. */
00161 /*     .. */
00162 /*     .. Executable Statements .. */
00163 
00164 /*     Test the input parameters */
00165 
00166     /* Parameter adjustments */
00167     a_dim1 = *lda;
00168     a_offset = 1 + a_dim1;
00169     a -= a_offset;
00170     --d__;
00171     --e;
00172     --tauq;
00173     --taup;
00174     --work;
00175 
00176     /* Function Body */
00177     *info = 0;
00178     if (*m < 0) {
00179         *info = -1;
00180     } else if (*n < 0) {
00181         *info = -2;
00182     } else if (*lda < max(1,*m)) {
00183         *info = -4;
00184     }
00185     if (*info < 0) {
00186         i__1 = -(*info);
00187         xerbla_("SGEBD2", &i__1);
00188         return 0;
00189     }
00190 
00191     if (*m >= *n) {
00192 
00193 /*        Reduce to upper bidiagonal form */
00194 
00195         i__1 = *n;
00196         for (i__ = 1; i__ <= i__1; ++i__) {
00197 
00198 /*           Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
00199 
00200             i__2 = *m - i__ + 1;
00201 /* Computing MIN */
00202             i__3 = i__ + 1;
00203             slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3, *m)+ i__ * 
00204                     a_dim1], &c__1, &tauq[i__]);
00205             d__[i__] = a[i__ + i__ * a_dim1];
00206             a[i__ + i__ * a_dim1] = 1.f;
00207 
00208 /*           Apply H(i) to A(i:m,i+1:n) from the left */
00209 
00210             if (i__ < *n) {
00211                 i__2 = *m - i__ + 1;
00212                 i__3 = *n - i__;
00213                 slarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
00214                         tauq[i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]
00215 );
00216             }
00217             a[i__ + i__ * a_dim1] = d__[i__];
00218 
00219             if (i__ < *n) {
00220 
00221 /*              Generate elementary reflector G(i) to annihilate */
00222 /*              A(i,i+2:n) */
00223 
00224                 i__2 = *n - i__;
00225 /* Computing MIN */
00226                 i__3 = i__ + 2;
00227                 slarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
00228                         i__3, *n)* a_dim1], lda, &taup[i__]);
00229                 e[i__] = a[i__ + (i__ + 1) * a_dim1];
00230                 a[i__ + (i__ + 1) * a_dim1] = 1.f;
00231 
00232 /*              Apply G(i) to A(i+1:m,i+1:n) from the right */
00233 
00234                 i__2 = *m - i__;
00235                 i__3 = *n - i__;
00236                 slarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1], 
00237                         lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1], 
00238                         lda, &work[1]);
00239                 a[i__ + (i__ + 1) * a_dim1] = e[i__];
00240             } else {
00241                 taup[i__] = 0.f;
00242             }
00243 /* L10: */
00244         }
00245     } else {
00246 
00247 /*        Reduce to lower bidiagonal form */
00248 
00249         i__1 = *m;
00250         for (i__ = 1; i__ <= i__1; ++i__) {
00251 
00252 /*           Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
00253 
00254             i__2 = *n - i__ + 1;
00255 /* Computing MIN */
00256             i__3 = i__ + 1;
00257             slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3, *n)* 
00258                     a_dim1], lda, &taup[i__]);
00259             d__[i__] = a[i__ + i__ * a_dim1];
00260             a[i__ + i__ * a_dim1] = 1.f;
00261 
00262 /*           Apply G(i) to A(i+1:m,i:n) from the right */
00263 
00264             if (i__ < *m) {
00265                 i__2 = *m - i__;
00266                 i__3 = *n - i__ + 1;
00267                 slarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &
00268                         taup[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
00269             }
00270             a[i__ + i__ * a_dim1] = d__[i__];
00271 
00272             if (i__ < *m) {
00273 
00274 /*              Generate elementary reflector H(i) to annihilate */
00275 /*              A(i+2:m,i) */
00276 
00277                 i__2 = *m - i__;
00278 /* Computing MIN */
00279                 i__3 = i__ + 2;
00280                 slarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *m)+ 
00281                         i__ * a_dim1], &c__1, &tauq[i__]);
00282                 e[i__] = a[i__ + 1 + i__ * a_dim1];
00283                 a[i__ + 1 + i__ * a_dim1] = 1.f;
00284 
00285 /*              Apply H(i) to A(i+1:m,i+1:n) from the left */
00286 
00287                 i__2 = *m - i__;
00288                 i__3 = *n - i__;
00289                 slarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &
00290                         c__1, &tauq[i__], &a[i__ + 1 + (i__ + 1) * a_dim1], 
00291                         lda, &work[1]);
00292                 a[i__ + 1 + i__ * a_dim1] = e[i__];
00293             } else {
00294                 tauq[i__] = 0.f;
00295             }
00296 /* L20: */
00297         }
00298     }
00299     return 0;
00300 
00301 /*     End of SGEBD2 */
00302 
00303 } /* sgebd2_ */


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