Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / sgetf2.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6 static real c_b8 = -1.f;
7
8 /* Subroutine */ int sgetf2_(integer *m, integer *n, real *a, integer *lda, 
9         integer *ipiv, integer *info)
10 {
11     /* System generated locals */
12     integer a_dim1, a_offset, i__1, i__2, i__3;
13     real r__1;
14
15     /* Local variables */
16     integer i__, j, jp;
17     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
18             integer *, real *, integer *, real *, integer *), sscal_(integer *
19 , real *, real *, integer *);
20     real sfmin;
21     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
22             integer *);
23     extern doublereal slamch_(char *);
24     extern /* Subroutine */ int xerbla_(char *, integer *);
25     extern integer isamax_(integer *, real *, integer *);
26
27
28 /*  -- LAPACK routine (version 3.1) -- */
29 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
30 /*     November 2006 */
31
32 /*     .. Scalar Arguments .. */
33 /*     .. */
34 /*     .. Array Arguments .. */
35 /*     .. */
36
37 /*  Purpose */
38 /*  ======= */
39
40 /*  SGETF2 computes an LU factorization of a general m-by-n matrix A */
41 /*  using partial pivoting with row interchanges. */
42
43 /*  The factorization has the form */
44 /*     A = P * L * U */
45 /*  where P is a permutation matrix, L is lower triangular with unit */
46 /*  diagonal elements (lower trapezoidal if m > n), and U is upper */
47 /*  triangular (upper trapezoidal if m < n). */
48
49 /*  This is the right-looking Level 2 BLAS version of the algorithm. */
50
51 /*  Arguments */
52 /*  ========= */
53
54 /*  M       (input) INTEGER */
55 /*          The number of rows of the matrix A.  M >= 0. */
56
57 /*  N       (input) INTEGER */
58 /*          The number of columns of the matrix A.  N >= 0. */
59
60 /*  A       (input/output) REAL array, dimension (LDA,N) */
61 /*          On entry, the m by n matrix to be factored. */
62 /*          On exit, the factors L and U from the factorization */
63 /*          A = P*L*U; the unit diagonal elements of L are not stored. */
64
65 /*  LDA     (input) INTEGER */
66 /*          The leading dimension of the array A.  LDA >= max(1,M). */
67
68 /*  IPIV    (output) INTEGER array, dimension (min(M,N)) */
69 /*          The pivot indices; for 1 <= i <= min(M,N), row i of the */
70 /*          matrix was interchanged with row IPIV(i). */
71
72 /*  INFO    (output) INTEGER */
73 /*          = 0: successful exit */
74 /*          < 0: if INFO = -k, the k-th argument had an illegal value */
75 /*          > 0: if INFO = k, U(k,k) is exactly zero. The factorization */
76 /*               has been completed, but the factor U is exactly */
77 /*               singular, and division by zero will occur if it is used */
78 /*               to solve a system of equations. */
79
80 /*  ===================================================================== */
81
82 /*     .. Parameters .. */
83 /*     .. */
84 /*     .. Local Scalars .. */
85 /*     .. */
86 /*     .. External Functions .. */
87 /*     .. */
88 /*     .. External Subroutines .. */
89 /*     .. */
90 /*     .. Intrinsic Functions .. */
91 /*     .. */
92 /*     .. Executable Statements .. */
93
94 /*     Test the input parameters. */
95
96     /* Parameter adjustments */
97     a_dim1 = *lda;
98     a_offset = 1 + a_dim1;
99     a -= a_offset;
100     --ipiv;
101
102     /* Function Body */
103     *info = 0;
104     if (*m < 0) {
105         *info = -1;
106     } else if (*n < 0) {
107         *info = -2;
108     } else if (*lda < max(1,*m)) {
109         *info = -4;
110     }
111     if (*info != 0) {
112         i__1 = -(*info);
113         xerbla_("SGETF2", &i__1);
114         return 0;
115     }
116
117 /*     Quick return if possible */
118
119     if (*m == 0 || *n == 0) {
120         return 0;
121     }
122
123 /*     Compute machine safe minimum */
124
125     sfmin = slamch_("S");
126
127     i__1 = min(*m,*n);
128     for (j = 1; j <= i__1; ++j) {
129
130 /*        Find pivot and test for singularity. */
131
132         i__2 = *m - j + 1;
133         jp = j - 1 + isamax_(&i__2, &a[j + j * a_dim1], &c__1);
134         ipiv[j] = jp;
135         if (a[jp + j * a_dim1] != 0.f) {
136
137 /*           Apply the interchange to columns 1:N. */
138
139             if (jp != j) {
140                 sswap_(n, &a[j + a_dim1], lda, &a[jp + a_dim1], lda);
141             }
142
143 /*           Compute elements J+1:M of J-th column. */
144
145             if (j < *m) {
146                 if ((r__1 = a[j + j * a_dim1], dabs(r__1)) >= sfmin) {
147                     i__2 = *m - j;
148                     r__1 = 1.f / a[j + j * a_dim1];
149                     sscal_(&i__2, &r__1, &a[j + 1 + j * a_dim1], &c__1);
150                 } else {
151                     i__2 = *m - j;
152                     for (i__ = 1; i__ <= i__2; ++i__) {
153                         a[j + i__ + j * a_dim1] /= a[j + j * a_dim1];
154 /* L20: */
155                     }
156                 }
157             }
158
159         } else if (*info == 0) {
160
161             *info = j;
162         }
163
164         if (j < min(*m,*n)) {
165
166 /*           Update trailing submatrix. */
167
168             i__2 = *m - j;
169             i__3 = *n - j;
170             sger_(&i__2, &i__3, &c_b8, &a[j + 1 + j * a_dim1], &c__1, &a[j + (
171                     j + 1) * a_dim1], lda, &a[j + 1 + (j + 1) * a_dim1], lda);
172         }
173 /* L10: */
174     }
175     return 0;
176
177 /*     End of SGETF2 */
178
179 } /* sgetf2_ */