sort01.c
Go to the documentation of this file.
00001 /* sort01.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_b7 = 0.f;
00019 static real c_b8 = 1.f;
00020 static real c_b10 = -1.f;
00021 static integer c__1 = 1;
00022 
00023 /* Subroutine */ int sort01_(char *rowcol, integer *m, integer *n, real *u, 
00024         integer *ldu, real *work, integer *lwork, real *resid)
00025 {
00026     /* System generated locals */
00027     integer u_dim1, u_offset, i__1, i__2;
00028     real r__1, r__2;
00029 
00030     /* Local variables */
00031     integer i__, j, k;
00032     real eps, tmp;
00033     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00034     extern logical lsame_(char *, char *);
00035     integer mnmin;
00036     extern /* Subroutine */ int ssyrk_(char *, char *, integer *, integer *, 
00037             real *, real *, integer *, real *, real *, integer *);
00038     extern doublereal slamch_(char *);
00039     extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, 
00040             real *, real *, integer *);
00041     integer ldwork;
00042     extern doublereal slansy_(char *, char *, integer *, real *, integer *, 
00043             real *);
00044     char transu[1];
00045 
00046 
00047 /*  -- LAPACK test routine (version 3.1) -- */
00048 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00049 /*     November 2006 */
00050 
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*     .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*  SORT01 checks that the matrix U is orthogonal by computing the ratio */
00060 
00061 /*     RESID = norm( I - U*U' ) / ( n * EPS ), if ROWCOL = 'R', */
00062 /*  or */
00063 /*     RESID = norm( I - U'*U ) / ( m * EPS ), if ROWCOL = 'C'. */
00064 
00065 /*  Alternatively, if there isn't sufficient workspace to form */
00066 /*  I - U*U' or I - U'*U, the ratio is computed as */
00067 
00068 /*     RESID = abs( I - U*U' ) / ( n * EPS ), if ROWCOL = 'R', */
00069 /*  or */
00070 /*     RESID = abs( I - U'*U ) / ( m * EPS ), if ROWCOL = 'C'. */
00071 
00072 /*  where EPS is the machine precision.  ROWCOL is used only if m = n; */
00073 /*  if m > n, ROWCOL is assumed to be 'C', and if m < n, ROWCOL is */
00074 /*  assumed to be 'R'. */
00075 
00076 /*  Arguments */
00077 /*  ========= */
00078 
00079 /*  ROWCOL  (input) CHARACTER */
00080 /*          Specifies whether the rows or columns of U should be checked */
00081 /*          for orthogonality.  Used only if M = N. */
00082 /*          = 'R':  Check for orthogonal rows of U */
00083 /*          = 'C':  Check for orthogonal columns of U */
00084 
00085 /*  M       (input) INTEGER */
00086 /*          The number of rows of the matrix U. */
00087 
00088 /*  N       (input) INTEGER */
00089 /*          The number of columns of the matrix U. */
00090 
00091 /*  U       (input) REAL array, dimension (LDU,N) */
00092 /*          The orthogonal matrix U.  U is checked for orthogonal columns */
00093 /*          if m > n or if m = n and ROWCOL = 'C'.  U is checked for */
00094 /*          orthogonal rows if m < n or if m = n and ROWCOL = 'R'. */
00095 
00096 /*  LDU     (input) INTEGER */
00097 /*          The leading dimension of the array U.  LDU >= max(1,M). */
00098 
00099 /*  WORK    (workspace) REAL array, dimension (LWORK) */
00100 
00101 /*  LWORK   (input) INTEGER */
00102 /*          The length of the array WORK.  For best performance, LWORK */
00103 /*          should be at least N*(N+1) if ROWCOL = 'C' or M*(M+1) if */
00104 /*          ROWCOL = 'R', but the test will be done even if LWORK is 0. */
00105 
00106 /*  RESID   (output) REAL */
00107 /*          RESID = norm( I - U * U' ) / ( n * EPS ), if ROWCOL = 'R', or */
00108 /*          RESID = norm( I - U' * U ) / ( m * EPS ), if ROWCOL = 'C'. */
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     /* Parameter adjustments */
00125     u_dim1 = *ldu;
00126     u_offset = 1 + u_dim1;
00127     u -= u_offset;
00128     --work;
00129 
00130     /* Function Body */
00131     *resid = 0.f;
00132 
00133 /*     Quick return if possible */
00134 
00135     if (*m <= 0 || *n <= 0) {
00136         return 0;
00137     }
00138 
00139     eps = slamch_("Precision");
00140     if (*m < *n || *m == *n && lsame_(rowcol, "R")) {
00141         *(unsigned char *)transu = 'N';
00142         k = *n;
00143     } else {
00144         *(unsigned char *)transu = 'T';
00145         k = *m;
00146     }
00147     mnmin = min(*m,*n);
00148 
00149     if ((mnmin + 1) * mnmin <= *lwork) {
00150         ldwork = mnmin;
00151     } else {
00152         ldwork = 0;
00153     }
00154     if (ldwork > 0) {
00155 
00156 /*        Compute I - U*U' or I - U'*U. */
00157 
00158         slaset_("Upper", &mnmin, &mnmin, &c_b7, &c_b8, &work[1], &ldwork);
00159         ssyrk_("Upper", transu, &mnmin, &k, &c_b10, &u[u_offset], ldu, &c_b8, 
00160                 &work[1], &ldwork);
00161 
00162 /*        Compute norm( I - U*U' ) / ( K * EPS ) . */
00163 
00164         *resid = slansy_("1", "Upper", &mnmin, &work[1], &ldwork, &work[
00165                 ldwork * mnmin + 1]);
00166         *resid = *resid / (real) k / eps;
00167     } else if (*(unsigned char *)transu == 'T') {
00168 
00169 /*        Find the maximum element in abs( I - U'*U ) / ( m * EPS ) */
00170 
00171         i__1 = *n;
00172         for (j = 1; j <= i__1; ++j) {
00173             i__2 = j;
00174             for (i__ = 1; i__ <= i__2; ++i__) {
00175                 if (i__ != j) {
00176                     tmp = 0.f;
00177                 } else {
00178                     tmp = 1.f;
00179                 }
00180                 tmp -= sdot_(m, &u[i__ * u_dim1 + 1], &c__1, &u[j * u_dim1 + 
00181                         1], &c__1);
00182 /* Computing MAX */
00183                 r__1 = *resid, r__2 = dabs(tmp);
00184                 *resid = dmax(r__1,r__2);
00185 /* L10: */
00186             }
00187 /* L20: */
00188         }
00189         *resid = *resid / (real) (*m) / eps;
00190     } else {
00191 
00192 /*        Find the maximum element in abs( I - U*U' ) / ( n * EPS ) */
00193 
00194         i__1 = *m;
00195         for (j = 1; j <= i__1; ++j) {
00196             i__2 = j;
00197             for (i__ = 1; i__ <= i__2; ++i__) {
00198                 if (i__ != j) {
00199                     tmp = 0.f;
00200                 } else {
00201                     tmp = 1.f;
00202                 }
00203                 tmp -= sdot_(n, &u[j + u_dim1], ldu, &u[i__ + u_dim1], ldu);
00204 /* Computing MAX */
00205                 r__1 = *resid, r__2 = dabs(tmp);
00206                 *resid = dmax(r__1,r__2);
00207 /* L30: */
00208             }
00209 /* L40: */
00210         }
00211         *resid = *resid / (real) (*n) / eps;
00212     }
00213     return 0;
00214 
00215 /*     End of SORT01 */
00216 
00217 } /* sort01_ */


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