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


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