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