sgetf2.c
Go to the documentation of this file.
00001 /* sgetf2.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 static real c_b8 = -1.f;
00020 
00021 /* Subroutine */ int sgetf2_(integer *m, integer *n, real *a, integer *lda, 
00022         integer *ipiv, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     real r__1;
00027 
00028     /* Local variables */
00029     integer i__, j, jp;
00030     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
00031             integer *, real *, integer *, real *, integer *), sscal_(integer *
00032 , real *, real *, integer *);
00033     real sfmin;
00034     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00035             integer *);
00036     extern doublereal slamch_(char *);
00037     extern /* Subroutine */ int xerbla_(char *, integer *);
00038     extern integer isamax_(integer *, real *, integer *);
00039 
00040 
00041 /*  -- LAPACK routine (version 3.2) -- */
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 /*  SGETF2 computes an LU factorization of a general m-by-n matrix A */
00054 /*  using partial pivoting with row interchanges. */
00055 
00056 /*  The factorization has the form */
00057 /*     A = P * L * U */
00058 /*  where P is a permutation matrix, L is lower triangular with unit */
00059 /*  diagonal elements (lower trapezoidal if m > n), and U is upper */
00060 /*  triangular (upper trapezoidal if m < n). */
00061 
00062 /*  This is the right-looking Level 2 BLAS version of the algorithm. */
00063 
00064 /*  Arguments */
00065 /*  ========= */
00066 
00067 /*  M       (input) INTEGER */
00068 /*          The number of rows of the matrix A.  M >= 0. */
00069 
00070 /*  N       (input) INTEGER */
00071 /*          The number of columns of the matrix A.  N >= 0. */
00072 
00073 /*  A       (input/output) REAL array, dimension (LDA,N) */
00074 /*          On entry, the m by n matrix to be factored. */
00075 /*          On exit, the factors L and U from the factorization */
00076 /*          A = P*L*U; the unit diagonal elements of L are not stored. */
00077 
00078 /*  LDA     (input) INTEGER */
00079 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00080 
00081 /*  IPIV    (output) INTEGER array, dimension (min(M,N)) */
00082 /*          The pivot indices; for 1 <= i <= min(M,N), row i of the */
00083 /*          matrix was interchanged with row IPIV(i). */
00084 
00085 /*  INFO    (output) INTEGER */
00086 /*          = 0: successful exit */
00087 /*          < 0: if INFO = -k, the k-th argument had an illegal value */
00088 /*          > 0: if INFO = k, U(k,k) is exactly zero. The factorization */
00089 /*               has been completed, but the factor U is exactly */
00090 /*               singular, and division by zero will occur if it is used */
00091 /*               to solve a system of equations. */
00092 
00093 /*  ===================================================================== */
00094 
00095 /*     .. Parameters .. */
00096 /*     .. */
00097 /*     .. Local Scalars .. */
00098 /*     .. */
00099 /*     .. External Functions .. */
00100 /*     .. */
00101 /*     .. External Subroutines .. */
00102 /*     .. */
00103 /*     .. Intrinsic Functions .. */
00104 /*     .. */
00105 /*     .. Executable Statements .. */
00106 
00107 /*     Test the input parameters. */
00108 
00109     /* Parameter adjustments */
00110     a_dim1 = *lda;
00111     a_offset = 1 + a_dim1;
00112     a -= a_offset;
00113     --ipiv;
00114 
00115     /* Function Body */
00116     *info = 0;
00117     if (*m < 0) {
00118         *info = -1;
00119     } else if (*n < 0) {
00120         *info = -2;
00121     } else if (*lda < max(1,*m)) {
00122         *info = -4;
00123     }
00124     if (*info != 0) {
00125         i__1 = -(*info);
00126         xerbla_("SGETF2", &i__1);
00127         return 0;
00128     }
00129 
00130 /*     Quick return if possible */
00131 
00132     if (*m == 0 || *n == 0) {
00133         return 0;
00134     }
00135 
00136 /*     Compute machine safe minimum */
00137 
00138     sfmin = slamch_("S");
00139 
00140     i__1 = min(*m,*n);
00141     for (j = 1; j <= i__1; ++j) {
00142 
00143 /*        Find pivot and test for singularity. */
00144 
00145         i__2 = *m - j + 1;
00146         jp = j - 1 + isamax_(&i__2, &a[j + j * a_dim1], &c__1);
00147         ipiv[j] = jp;
00148         if (a[jp + j * a_dim1] != 0.f) {
00149 
00150 /*           Apply the interchange to columns 1:N. */
00151 
00152             if (jp != j) {
00153                 sswap_(n, &a[j + a_dim1], lda, &a[jp + a_dim1], lda);
00154             }
00155 
00156 /*           Compute elements J+1:M of J-th column. */
00157 
00158             if (j < *m) {
00159                 if ((r__1 = a[j + j * a_dim1], dabs(r__1)) >= sfmin) {
00160                     i__2 = *m - j;
00161                     r__1 = 1.f / a[j + j * a_dim1];
00162                     sscal_(&i__2, &r__1, &a[j + 1 + j * a_dim1], &c__1);
00163                 } else {
00164                     i__2 = *m - j;
00165                     for (i__ = 1; i__ <= i__2; ++i__) {
00166                         a[j + i__ + j * a_dim1] /= a[j + j * a_dim1];
00167 /* L20: */
00168                     }
00169                 }
00170             }
00171 
00172         } else if (*info == 0) {
00173 
00174             *info = j;
00175         }
00176 
00177         if (j < min(*m,*n)) {
00178 
00179 /*           Update trailing submatrix. */
00180 
00181             i__2 = *m - j;
00182             i__3 = *n - j;
00183             sger_(&i__2, &i__3, &c_b8, &a[j + 1 + j * a_dim1], &c__1, &a[j + (
00184                     j + 1) * a_dim1], lda, &a[j + 1 + (j + 1) * a_dim1], lda);
00185         }
00186 /* L10: */
00187     }
00188     return 0;
00189 
00190 /*     End of SGETF2 */
00191 
00192 } /* sgetf2_ */


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