sla_gercond.c
Go to the documentation of this file.
00001 /* sla_gercond.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 integer c__1 = 1;
00019 
00020 doublereal sla_gercond__(char *trans, integer *n, real *a, integer *lda, real 
00021         *af, integer *ldaf, integer *ipiv, integer *cmode, real *c__, integer 
00022         *info, real *work, integer *iwork, ftnlen trans_len)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, af_dim1, af_offset, i__1, i__2;
00026     real ret_val, r__1;
00027 
00028     /* Local variables */
00029     integer i__, j;
00030     real tmp;
00031     integer kase;
00032     extern logical lsame_(char *, char *);
00033     integer isave[3];
00034     extern /* Subroutine */ int slacn2_(integer *, real *, real *, integer *, 
00035             real *, integer *, integer *), xerbla_(char *, integer *);
00036     real ainvnm;
00037     extern /* Subroutine */ int sgetrs_(char *, integer *, integer *, real *, 
00038             integer *, integer *, real *, integer *, integer *);
00039     logical notrans;
00040 
00041 
00042 /*     -- LAPACK routine (version 3.2.1)                                 -- */
00043 /*     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
00044 /*     -- Jason Riedy of Univ. of California Berkeley.                 -- */
00045 /*     -- April 2009                                                   -- */
00046 
00047 /*     -- LAPACK is a software package provided by Univ. of Tennessee, -- */
00048 /*     -- Univ. of California Berkeley and NAG Ltd.                    -- */
00049 
00050 /*     .. */
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*    .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*     SLA_GERCOND estimates the Skeel condition number of op(A) * op2(C) */
00060 /*     where op2 is determined by CMODE as follows */
00061 /*     CMODE =  1    op2(C) = C */
00062 /*     CMODE =  0    op2(C) = I */
00063 /*     CMODE = -1    op2(C) = inv(C) */
00064 /*     The Skeel condition number cond(A) = norminf( |inv(A)||A| ) */
00065 /*     is computed by computing scaling factors R such that */
00066 /*     diag(R)*A*op2(C) is row equilibrated and computing the standard */
00067 /*     infinity-norm condition number. */
00068 
00069 /*  Arguments */
00070 /*  ========== */
00071 
00072 /*     TRANS   (input) CHARACTER*1 */
00073 /*     Specifies the form of the system of equations: */
00074 /*       = 'N':  A * X = B     (No transpose) */
00075 /*       = 'T':  A**T * X = B  (Transpose) */
00076 /*       = 'C':  A**H * X = B  (Conjugate Transpose = Transpose) */
00077 
00078 /*     N       (input) INTEGER */
00079 /*     The number of linear equations, i.e., the order of the */
00080 /*     matrix A.  N >= 0. */
00081 
00082 /*     A       (input) REAL array, dimension (LDA,N) */
00083 /*     On entry, the N-by-N matrix A. */
00084 
00085 /*     LDA     (input) INTEGER */
00086 /*     The leading dimension of the array A.  LDA >= max(1,N). */
00087 
00088 /*     AF      (input) REAL array, dimension (LDAF,N) */
00089 /*     The factors L and U from the factorization */
00090 /*     A = P*L*U as computed by SGETRF. */
00091 
00092 /*     LDAF    (input) INTEGER */
00093 /*     The leading dimension of the array AF.  LDAF >= max(1,N). */
00094 
00095 /*     IPIV    (input) INTEGER array, dimension (N) */
00096 /*     The pivot indices from the factorization A = P*L*U */
00097 /*     as computed by SGETRF; row i of the matrix was interchanged */
00098 /*     with row IPIV(i). */
00099 
00100 /*     CMODE   (input) INTEGER */
00101 /*     Determines op2(C) in the formula op(A) * op2(C) as follows: */
00102 /*     CMODE =  1    op2(C) = C */
00103 /*     CMODE =  0    op2(C) = I */
00104 /*     CMODE = -1    op2(C) = inv(C) */
00105 
00106 /*     C       (input) REAL array, dimension (N) */
00107 /*     The vector C in the formula op(A) * op2(C). */
00108 
00109 /*     INFO    (output) INTEGER */
00110 /*       = 0:  Successful exit. */
00111 /*     i > 0:  The ith argument is invalid. */
00112 
00113 /*     WORK    (input) REAL array, dimension (3*N). */
00114 /*     Workspace. */
00115 
00116 /*     IWORK   (input) INTEGER array, dimension (N). */
00117 /*     Workspace.2 */
00118 
00119 /*  ===================================================================== */
00120 
00121 /*     .. Local Scalars .. */
00122 /*     .. */
00123 /*     .. Local Arrays .. */
00124 /*     .. */
00125 /*     .. External Functions .. */
00126 /*     .. */
00127 /*     .. External Subroutines .. */
00128 /*     .. */
00129 /*     .. Intrinsic Functions .. */
00130 /*     .. */
00131 /*     .. Executable Statements .. */
00132 
00133     /* Parameter adjustments */
00134     a_dim1 = *lda;
00135     a_offset = 1 + a_dim1;
00136     a -= a_offset;
00137     af_dim1 = *ldaf;
00138     af_offset = 1 + af_dim1;
00139     af -= af_offset;
00140     --ipiv;
00141     --c__;
00142     --work;
00143     --iwork;
00144 
00145     /* Function Body */
00146     ret_val = 0.f;
00147 
00148     *info = 0;
00149     notrans = lsame_(trans, "N");
00150     if (! notrans && ! lsame_(trans, "T") && ! lsame_(
00151             trans, "C")) {
00152         *info = -1;
00153     } else if (*n < 0) {
00154         *info = -2;
00155     } else if (*lda < max(1,*n)) {
00156         *info = -4;
00157     } else if (*ldaf < max(1,*n)) {
00158         *info = -6;
00159     }
00160     if (*info != 0) {
00161         i__1 = -(*info);
00162         xerbla_("SLA_GERCOND", &i__1);
00163         return ret_val;
00164     }
00165     if (*n == 0) {
00166         ret_val = 1.f;
00167         return ret_val;
00168     }
00169 
00170 /*     Compute the equilibration matrix R such that */
00171 /*     inv(R)*A*C has unit 1-norm. */
00172 
00173     if (notrans) {
00174         i__1 = *n;
00175         for (i__ = 1; i__ <= i__1; ++i__) {
00176             tmp = 0.f;
00177             if (*cmode == 1) {
00178                 i__2 = *n;
00179                 for (j = 1; j <= i__2; ++j) {
00180                     tmp += (r__1 = a[i__ + j * a_dim1] * c__[j], dabs(r__1));
00181                 }
00182             } else if (*cmode == 0) {
00183                 i__2 = *n;
00184                 for (j = 1; j <= i__2; ++j) {
00185                     tmp += (r__1 = a[i__ + j * a_dim1], dabs(r__1));
00186                 }
00187             } else {
00188                 i__2 = *n;
00189                 for (j = 1; j <= i__2; ++j) {
00190                     tmp += (r__1 = a[i__ + j * a_dim1] / c__[j], dabs(r__1));
00191                 }
00192             }
00193             work[(*n << 1) + i__] = tmp;
00194         }
00195     } else {
00196         i__1 = *n;
00197         for (i__ = 1; i__ <= i__1; ++i__) {
00198             tmp = 0.f;
00199             if (*cmode == 1) {
00200                 i__2 = *n;
00201                 for (j = 1; j <= i__2; ++j) {
00202                     tmp += (r__1 = a[j + i__ * a_dim1] * c__[j], dabs(r__1));
00203                 }
00204             } else if (*cmode == 0) {
00205                 i__2 = *n;
00206                 for (j = 1; j <= i__2; ++j) {
00207                     tmp += (r__1 = a[j + i__ * a_dim1], dabs(r__1));
00208                 }
00209             } else {
00210                 i__2 = *n;
00211                 for (j = 1; j <= i__2; ++j) {
00212                     tmp += (r__1 = a[j + i__ * a_dim1] / c__[j], dabs(r__1));
00213                 }
00214             }
00215             work[(*n << 1) + i__] = tmp;
00216         }
00217     }
00218 
00219 /*     Estimate the norm of inv(op(A)). */
00220 
00221     ainvnm = 0.f;
00222     kase = 0;
00223 L10:
00224     slacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
00225     if (kase != 0) {
00226         if (kase == 2) {
00227 
00228 /*           Multiply by R. */
00229 
00230             i__1 = *n;
00231             for (i__ = 1; i__ <= i__1; ++i__) {
00232                 work[i__] *= work[(*n << 1) + i__];
00233             }
00234             if (notrans) {
00235                 sgetrs_("No transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[
00236                         1], &work[1], n, info);
00237             } else {
00238                 sgetrs_("Transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[1], 
00239                          &work[1], n, info);
00240             }
00241 
00242 /*           Multiply by inv(C). */
00243 
00244             if (*cmode == 1) {
00245                 i__1 = *n;
00246                 for (i__ = 1; i__ <= i__1; ++i__) {
00247                     work[i__] /= c__[i__];
00248                 }
00249             } else if (*cmode == -1) {
00250                 i__1 = *n;
00251                 for (i__ = 1; i__ <= i__1; ++i__) {
00252                     work[i__] *= c__[i__];
00253                 }
00254             }
00255         } else {
00256 
00257 /*           Multiply by inv(C'). */
00258 
00259             if (*cmode == 1) {
00260                 i__1 = *n;
00261                 for (i__ = 1; i__ <= i__1; ++i__) {
00262                     work[i__] /= c__[i__];
00263                 }
00264             } else if (*cmode == -1) {
00265                 i__1 = *n;
00266                 for (i__ = 1; i__ <= i__1; ++i__) {
00267                     work[i__] *= c__[i__];
00268                 }
00269             }
00270             if (notrans) {
00271                 sgetrs_("Transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[1], 
00272                          &work[1], n, info);
00273             } else {
00274                 sgetrs_("No transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[
00275                         1], &work[1], n, info);
00276             }
00277 
00278 /*           Multiply by R. */
00279 
00280             i__1 = *n;
00281             for (i__ = 1; i__ <= i__1; ++i__) {
00282                 work[i__] *= work[(*n << 1) + i__];
00283             }
00284         }
00285         goto L10;
00286     }
00287 
00288 /*     Compute the estimate of the reciprocal condition number. */
00289 
00290     if (ainvnm != 0.f) {
00291         ret_val = 1.f / ainvnm;
00292     }
00293 
00294     return ret_val;
00295 
00296 } /* sla_gercond__ */


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