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