Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / sgelq2.c
1 #include "clapack.h"
2
3 /* Subroutine */ int sgelq2_(integer *m, integer *n, real *a, integer *lda, 
4         real *tau, real *work, integer *info)
5 {
6     /* System generated locals */
7     integer a_dim1, a_offset, i__1, i__2, i__3;
8
9     /* Local variables */
10     integer i__, k;
11     real aii;
12     extern /* Subroutine */ int slarf_(char *, integer *, integer *, real *, 
13             integer *, real *, real *, integer *, real *), xerbla_(
14             char *, integer *), slarfg_(integer *, real *, real *, 
15             integer *, real *);
16
17
18 /*  -- LAPACK routine (version 3.1) -- */
19 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20 /*     November 2006 */
21
22 /*     .. Scalar Arguments .. */
23 /*     .. */
24 /*     .. Array Arguments .. */
25 /*     .. */
26
27 /*  Purpose */
28 /*  ======= */
29
30 /*  SGELQ2 computes an LQ factorization of a real m by n matrix A: */
31 /*  A = L * Q. */
32
33 /*  Arguments */
34 /*  ========= */
35
36 /*  M       (input) INTEGER */
37 /*          The number of rows of the matrix A.  M >= 0. */
38
39 /*  N       (input) INTEGER */
40 /*          The number of columns of the matrix A.  N >= 0. */
41
42 /*  A       (input/output) REAL array, dimension (LDA,N) */
43 /*          On entry, the m by n matrix A. */
44 /*          On exit, the elements on and below the diagonal of the array */
45 /*          contain the m by min(m,n) lower trapezoidal matrix L (L is */
46 /*          lower triangular if m <= n); the elements above the diagonal, */
47 /*          with the array TAU, represent the orthogonal matrix Q as a */
48 /*          product of elementary reflectors (see Further Details). */
49
50 /*  LDA     (input) INTEGER */
51 /*          The leading dimension of the array A.  LDA >= max(1,M). */
52
53 /*  TAU     (output) REAL array, dimension (min(M,N)) */
54 /*          The scalar factors of the elementary reflectors (see Further */
55 /*          Details). */
56
57 /*  WORK    (workspace) REAL array, dimension (M) */
58
59 /*  INFO    (output) INTEGER */
60 /*          = 0: successful exit */
61 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
62
63 /*  Further Details */
64 /*  =============== */
65
66 /*  The matrix Q is represented as a product of elementary reflectors */
67
68 /*     Q = H(k) . . . H(2) H(1), where k = min(m,n). */
69
70 /*  Each H(i) has the form */
71
72 /*     H(i) = I - tau * v * v' */
73
74 /*  where tau is a real scalar, and v is a real vector with */
75 /*  v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n), */
76 /*  and tau in TAU(i). */
77
78 /*  ===================================================================== */
79
80 /*     .. Parameters .. */
81 /*     .. */
82 /*     .. Local Scalars .. */
83 /*     .. */
84 /*     .. External Subroutines .. */
85 /*     .. */
86 /*     .. Intrinsic Functions .. */
87 /*     .. */
88 /*     .. Executable Statements .. */
89
90 /*     Test the input arguments */
91
92     /* Parameter adjustments */
93     a_dim1 = *lda;
94     a_offset = 1 + a_dim1;
95     a -= a_offset;
96     --tau;
97     --work;
98
99     /* Function Body */
100     *info = 0;
101     if (*m < 0) {
102         *info = -1;
103     } else if (*n < 0) {
104         *info = -2;
105     } else if (*lda < max(1,*m)) {
106         *info = -4;
107     }
108     if (*info != 0) {
109         i__1 = -(*info);
110         xerbla_("SGELQ2", &i__1);
111         return 0;
112     }
113
114     k = min(*m,*n);
115
116     i__1 = k;
117     for (i__ = 1; i__ <= i__1; ++i__) {
118
119 /*        Generate elementary reflector H(i) to annihilate A(i,i+1:n) */
120
121         i__2 = *n - i__ + 1;
122 /* Computing MIN */
123         i__3 = i__ + 1;
124         slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3, *n)* a_dim1]
125 , lda, &tau[i__]);
126         if (i__ < *m) {
127
128 /*           Apply H(i) to A(i+1:m,i:n) from the right */
129
130             aii = a[i__ + i__ * a_dim1];
131             a[i__ + i__ * a_dim1] = 1.f;
132             i__2 = *m - i__;
133             i__3 = *n - i__ + 1;
134             slarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[
135                     i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
136             a[i__ + i__ * a_dim1] = aii;
137         }
138 /* L10: */
139     }
140     return 0;
141
142 /*     End of SGELQ2 */
143
144 } /* sgelq2_ */