dbdt03.c
Go to the documentation of this file.
00001 /* dbdt03.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_b6 = -1.;
00019 static integer c__1 = 1;
00020 static doublereal c_b8 = 0.;
00021 
00022 /* Subroutine */ int dbdt03_(char *uplo, integer *n, integer *kd, doublereal *
00023         d__, doublereal *e, doublereal *u, integer *ldu, doublereal *s, 
00024         doublereal *vt, integer *ldvt, doublereal *work, doublereal *resid)
00025 {
00026     /* System generated locals */
00027     integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
00028     doublereal d__1, d__2, d__3, d__4;
00029 
00030     /* Local variables */
00031     integer i__, j;
00032     doublereal eps;
00033     extern logical lsame_(char *, char *);
00034     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
00035             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00036             doublereal *, doublereal *, integer *);
00037     extern doublereal dasum_(integer *, doublereal *, integer *);
00038     doublereal bnorm;
00039     extern doublereal dlamch_(char *);
00040     extern integer idamax_(integer *, doublereal *, integer *);
00041 
00042 
00043 /*  -- LAPACK test routine (version 3.1) -- */
00044 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00045 /*     November 2006 */
00046 
00047 /*     .. Scalar Arguments .. */
00048 /*     .. */
00049 /*     .. Array Arguments .. */
00050 /*     .. */
00051 
00052 /*  Purpose */
00053 /*  ======= */
00054 
00055 /*  DBDT03 reconstructs a bidiagonal matrix B from its SVD: */
00056 /*     S = U' * B * V */
00057 /*  where U and V are orthogonal matrices and S is diagonal. */
00058 
00059 /*  The test ratio to test the singular value decomposition is */
00060 /*     RESID = norm( B - U * S * VT ) / ( n * norm(B) * EPS ) */
00061 /*  where VT = V' and EPS is the machine precision. */
00062 
00063 /*  Arguments */
00064 /*  ========= */
00065 
00066 /*  UPLO    (input) CHARACTER*1 */
00067 /*          Specifies whether the matrix B is upper or lower bidiagonal. */
00068 /*          = 'U':  Upper bidiagonal */
00069 /*          = 'L':  Lower bidiagonal */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The order of the matrix B. */
00073 
00074 /*  KD      (input) INTEGER */
00075 /*          The bandwidth of the bidiagonal matrix B.  If KD = 1, the */
00076 /*          matrix B is bidiagonal, and if KD = 0, B is diagonal and E is */
00077 /*          not referenced.  If KD is greater than 1, it is assumed to be */
00078 /*          1, and if KD is less than 0, it is assumed to be 0. */
00079 
00080 /*  D       (input) DOUBLE PRECISION array, dimension (N) */
00081 /*          The n diagonal elements of the bidiagonal matrix B. */
00082 
00083 /*  E       (input) DOUBLE PRECISION array, dimension (N-1) */
00084 /*          The (n-1) superdiagonal elements of the bidiagonal matrix B */
00085 /*          if UPLO = 'U', or the (n-1) subdiagonal elements of B if */
00086 /*          UPLO = 'L'. */
00087 
00088 /*  U       (input) DOUBLE PRECISION array, dimension (LDU,N) */
00089 /*          The n by n orthogonal matrix U in the reduction B = U'*A*P. */
00090 
00091 /*  LDU     (input) INTEGER */
00092 /*          The leading dimension of the array U.  LDU >= max(1,N) */
00093 
00094 /*  S       (input) DOUBLE PRECISION array, dimension (N) */
00095 /*          The singular values from the SVD of B, sorted in decreasing */
00096 /*          order. */
00097 
00098 /*  VT      (input) DOUBLE PRECISION array, dimension (LDVT,N) */
00099 /*          The n by n orthogonal matrix V' in the reduction */
00100 /*          B = U * S * V'. */
00101 
00102 /*  LDVT    (input) INTEGER */
00103 /*          The leading dimension of the array VT. */
00104 
00105 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (2*N) */
00106 
00107 /*  RESID   (output) DOUBLE PRECISION */
00108 /*          The test ratio:  norm(B - U * S * V') / ( n * norm(A) * EPS ) */
00109 
00110 /* ====================================================================== */
00111 
00112 /*     .. Parameters .. */
00113 /*     .. */
00114 /*     .. Local Scalars .. */
00115 /*     .. */
00116 /*     .. External Functions .. */
00117 /*     .. */
00118 /*     .. External Subroutines .. */
00119 /*     .. */
00120 /*     .. Intrinsic Functions .. */
00121 /*     .. */
00122 /*     .. Executable Statements .. */
00123 
00124 /*     Quick return if possible */
00125 
00126     /* Parameter adjustments */
00127     --d__;
00128     --e;
00129     u_dim1 = *ldu;
00130     u_offset = 1 + u_dim1;
00131     u -= u_offset;
00132     --s;
00133     vt_dim1 = *ldvt;
00134     vt_offset = 1 + vt_dim1;
00135     vt -= vt_offset;
00136     --work;
00137 
00138     /* Function Body */
00139     *resid = 0.;
00140     if (*n <= 0) {
00141         return 0;
00142     }
00143 
00144 /*     Compute B - U * S * V' one column at a time. */
00145 
00146     bnorm = 0.;
00147     if (*kd >= 1) {
00148 
00149 /*        B is bidiagonal. */
00150 
00151         if (lsame_(uplo, "U")) {
00152 
00153 /*           B is upper bidiagonal. */
00154 
00155             i__1 = *n;
00156             for (j = 1; j <= i__1; ++j) {
00157                 i__2 = *n;
00158                 for (i__ = 1; i__ <= i__2; ++i__) {
00159                     work[*n + i__] = s[i__] * vt[i__ + j * vt_dim1];
00160 /* L10: */
00161                 }
00162                 dgemv_("No transpose", n, n, &c_b6, &u[u_offset], ldu, &work[*
00163                         n + 1], &c__1, &c_b8, &work[1], &c__1);
00164                 work[j] += d__[j];
00165                 if (j > 1) {
00166                     work[j - 1] += e[j - 1];
00167 /* Computing MAX */
00168                     d__3 = bnorm, d__4 = (d__1 = d__[j], abs(d__1)) + (d__2 = 
00169                             e[j - 1], abs(d__2));
00170                     bnorm = max(d__3,d__4);
00171                 } else {
00172 /* Computing MAX */
00173                     d__2 = bnorm, d__3 = (d__1 = d__[j], abs(d__1));
00174                     bnorm = max(d__2,d__3);
00175                 }
00176 /* Computing MAX */
00177                 d__1 = *resid, d__2 = dasum_(n, &work[1], &c__1);
00178                 *resid = max(d__1,d__2);
00179 /* L20: */
00180             }
00181         } else {
00182 
00183 /*           B is lower bidiagonal. */
00184 
00185             i__1 = *n;
00186             for (j = 1; j <= i__1; ++j) {
00187                 i__2 = *n;
00188                 for (i__ = 1; i__ <= i__2; ++i__) {
00189                     work[*n + i__] = s[i__] * vt[i__ + j * vt_dim1];
00190 /* L30: */
00191                 }
00192                 dgemv_("No transpose", n, n, &c_b6, &u[u_offset], ldu, &work[*
00193                         n + 1], &c__1, &c_b8, &work[1], &c__1);
00194                 work[j] += d__[j];
00195                 if (j < *n) {
00196                     work[j + 1] += e[j];
00197 /* Computing MAX */
00198                     d__3 = bnorm, d__4 = (d__1 = d__[j], abs(d__1)) + (d__2 = 
00199                             e[j], abs(d__2));
00200                     bnorm = max(d__3,d__4);
00201                 } else {
00202 /* Computing MAX */
00203                     d__2 = bnorm, d__3 = (d__1 = d__[j], abs(d__1));
00204                     bnorm = max(d__2,d__3);
00205                 }
00206 /* Computing MAX */
00207                 d__1 = *resid, d__2 = dasum_(n, &work[1], &c__1);
00208                 *resid = max(d__1,d__2);
00209 /* L40: */
00210             }
00211         }
00212     } else {
00213 
00214 /*        B is diagonal. */
00215 
00216         i__1 = *n;
00217         for (j = 1; j <= i__1; ++j) {
00218             i__2 = *n;
00219             for (i__ = 1; i__ <= i__2; ++i__) {
00220                 work[*n + i__] = s[i__] * vt[i__ + j * vt_dim1];
00221 /* L50: */
00222             }
00223             dgemv_("No transpose", n, n, &c_b6, &u[u_offset], ldu, &work[*n + 
00224                     1], &c__1, &c_b8, &work[1], &c__1);
00225             work[j] += d__[j];
00226 /* Computing MAX */
00227             d__1 = *resid, d__2 = dasum_(n, &work[1], &c__1);
00228             *resid = max(d__1,d__2);
00229 /* L60: */
00230         }
00231         j = idamax_(n, &d__[1], &c__1);
00232         bnorm = (d__1 = d__[j], abs(d__1));
00233     }
00234 
00235 /*     Compute norm(B - U * S * V') / ( n * norm(B) * EPS ) */
00236 
00237     eps = dlamch_("Precision");
00238 
00239     if (bnorm <= 0.) {
00240         if (*resid != 0.) {
00241             *resid = 1. / eps;
00242         }
00243     } else {
00244         if (bnorm >= *resid) {
00245             *resid = *resid / bnorm / ((doublereal) (*n) * eps);
00246         } else {
00247             if (bnorm < 1.) {
00248 /* Computing MIN */
00249                 d__1 = *resid, d__2 = (doublereal) (*n) * bnorm;
00250                 *resid = min(d__1,d__2) / bnorm / ((doublereal) (*n) * eps);
00251             } else {
00252 /* Computing MIN */
00253                 d__1 = *resid / bnorm, d__2 = (doublereal) (*n);
00254                 *resid = min(d__1,d__2) / ((doublereal) (*n) * eps);
00255             }
00256         }
00257     }
00258 
00259     return 0;
00260 
00261 /*     End of DBDT03 */
00262 
00263 } /* dbdt03_ */


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