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


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