cget01.c
Go to the documentation of this file.
00001 /* cget01.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_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int cget01_(integer *m, integer *n, complex *a, integer *lda, 
00023          complex *afac, integer *ldafac, integer *ipiv, real *rwork, real *
00024         resid)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, afac_dim1, afac_offset, i__1, i__2, i__3, i__4, 
00028             i__5;
00029     complex q__1, q__2;
00030 
00031     /* Local variables */
00032     integer i__, j, k;
00033     complex t;
00034     real eps;
00035     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00036             integer *), cgemv_(char *, integer *, integer *, complex *, 
00037             complex *, integer *, complex *, integer *, complex *, complex *, 
00038             integer *);
00039     real anorm;
00040     extern /* Complex */ VOID cdotu_(complex *, integer *, complex *, integer 
00041             *, complex *, integer *);
00042     extern /* Subroutine */ int ctrmv_(char *, char *, char *, integer *, 
00043             complex *, integer *, complex *, integer *);
00044     extern doublereal clange_(char *, integer *, integer *, complex *, 
00045             integer *, real *), slamch_(char *);
00046     extern /* Subroutine */ int claswp_(integer *, complex *, integer *, 
00047             integer *, integer *, integer *, integer *);
00048 
00049 
00050 /*  -- LAPACK test routine (version 3.1) -- */
00051 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00052 /*     November 2006 */
00053 
00054 /*     .. Scalar Arguments .. */
00055 /*     .. */
00056 /*     .. Array Arguments .. */
00057 /*     .. */
00058 
00059 /*  Purpose */
00060 /*  ======= */
00061 
00062 /*  CGET01 reconstructs a matrix A from its L*U factorization and */
00063 /*  computes the residual */
00064 /*     norm(L*U - A) / ( N * norm(A) * EPS ), */
00065 /*  where EPS is the machine epsilon. */
00066 
00067 /*  Arguments */
00068 /*  ========== */
00069 
00070 /*  M       (input) INTEGER */
00071 /*          The number of rows of the matrix A.  M >= 0. */
00072 
00073 /*  N       (input) INTEGER */
00074 /*          The number of columns of the matrix A.  N >= 0. */
00075 
00076 /*  A       (input) COMPLEX array, dimension (LDA,N) */
00077 /*          The original M x N matrix A. */
00078 
00079 /*  LDA     (input) INTEGER */
00080 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00081 
00082 /*  AFAC    (input/output) COMPLEX array, dimension (LDAFAC,N) */
00083 /*          The factored form of the matrix A.  AFAC contains the factors */
00084 /*          L and U from the L*U factorization as computed by CGETRF. */
00085 /*          Overwritten with the reconstructed matrix, and then with the */
00086 /*          difference L*U - A. */
00087 
00088 /*  LDAFAC  (input) INTEGER */
00089 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,M). */
00090 
00091 /*  IPIV    (input) INTEGER array, dimension (N) */
00092 /*          The pivot indices from CGETRF. */
00093 
00094 /*  RWORK   (workspace) REAL array, dimension (M) */
00095 
00096 /*  RESID   (output) REAL */
00097 /*          norm(L*U - A) / ( N * norm(A) * EPS ) */
00098 
00099 /*  ===================================================================== */
00100 
00101 /*     .. Parameters .. */
00102 /*     .. */
00103 /*     .. Local Scalars .. */
00104 /*     .. */
00105 /*     .. External Functions .. */
00106 /*     .. */
00107 /*     .. External Subroutines .. */
00108 /*     .. */
00109 /*     .. Intrinsic Functions .. */
00110 /*     .. */
00111 /*     .. Executable Statements .. */
00112 
00113 /*     Quick exit if M = 0 or N = 0. */
00114 
00115     /* Parameter adjustments */
00116     a_dim1 = *lda;
00117     a_offset = 1 + a_dim1;
00118     a -= a_offset;
00119     afac_dim1 = *ldafac;
00120     afac_offset = 1 + afac_dim1;
00121     afac -= afac_offset;
00122     --ipiv;
00123     --rwork;
00124 
00125     /* Function Body */
00126     if (*m <= 0 || *n <= 0) {
00127         *resid = 0.f;
00128         return 0;
00129     }
00130 
00131 /*     Determine EPS and the norm of A. */
00132 
00133     eps = slamch_("Epsilon");
00134     anorm = clange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00135 
00136 /*     Compute the product L*U and overwrite AFAC with the result. */
00137 /*     A column at a time of the product is obtained, starting with */
00138 /*     column N. */
00139 
00140     for (k = *n; k >= 1; --k) {
00141         if (k > *m) {
00142             ctrmv_("Lower", "No transpose", "Unit", m, &afac[afac_offset], 
00143                     ldafac, &afac[k * afac_dim1 + 1], &c__1);
00144         } else {
00145 
00146 /*           Compute elements (K+1:M,K) */
00147 
00148             i__1 = k + k * afac_dim1;
00149             t.r = afac[i__1].r, t.i = afac[i__1].i;
00150             if (k + 1 <= *m) {
00151                 i__1 = *m - k;
00152                 cscal_(&i__1, &t, &afac[k + 1 + k * afac_dim1], &c__1);
00153                 i__1 = *m - k;
00154                 i__2 = k - 1;
00155                 cgemv_("No transpose", &i__1, &i__2, &c_b1, &afac[k + 1 + 
00156                         afac_dim1], ldafac, &afac[k * afac_dim1 + 1], &c__1, &
00157                         c_b1, &afac[k + 1 + k * afac_dim1], &c__1)
00158                         ;
00159             }
00160 
00161 /*           Compute the (K,K) element */
00162 
00163             i__1 = k + k * afac_dim1;
00164             i__2 = k - 1;
00165             cdotu_(&q__2, &i__2, &afac[k + afac_dim1], ldafac, &afac[k * 
00166                     afac_dim1 + 1], &c__1);
00167             q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00168             afac[i__1].r = q__1.r, afac[i__1].i = q__1.i;
00169 
00170 /*           Compute elements (1:K-1,K) */
00171 
00172             i__1 = k - 1;
00173             ctrmv_("Lower", "No transpose", "Unit", &i__1, &afac[afac_offset], 
00174                      ldafac, &afac[k * afac_dim1 + 1], &c__1);
00175         }
00176 /* L10: */
00177     }
00178     i__1 = min(*m,*n);
00179     claswp_(n, &afac[afac_offset], ldafac, &c__1, &i__1, &ipiv[1], &c_n1);
00180 
00181 /*     Compute the difference  L*U - A  and store in AFAC. */
00182 
00183     i__1 = *n;
00184     for (j = 1; j <= i__1; ++j) {
00185         i__2 = *m;
00186         for (i__ = 1; i__ <= i__2; ++i__) {
00187             i__3 = i__ + j * afac_dim1;
00188             i__4 = i__ + j * afac_dim1;
00189             i__5 = i__ + j * a_dim1;
00190             q__1.r = afac[i__4].r - a[i__5].r, q__1.i = afac[i__4].i - a[i__5]
00191                     .i;
00192             afac[i__3].r = q__1.r, afac[i__3].i = q__1.i;
00193 /* L20: */
00194         }
00195 /* L30: */
00196     }
00197 
00198 /*     Compute norm( L*U - A ) / ( N * norm(A) * EPS ) */
00199 
00200     *resid = clange_("1", m, n, &afac[afac_offset], ldafac, &rwork[1]);
00201 
00202     if (anorm <= 0.f) {
00203         if (*resid != 0.f) {
00204             *resid = 1.f / eps;
00205         }
00206     } else {
00207         *resid = *resid / (real) (*n) / anorm / eps;
00208     }
00209 
00210     return 0;
00211 
00212 /*     End of CGET01 */
00213 
00214 } /* cget01_ */


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