Merge branch 'master' of https://github.com/Reference-LAPACK/lapack
[platform/upstream/lapack.git] / SRC / cgelqt3.f
1 *  Definition:
2 *  ===========
3 *
4 *       RECURSIVE SUBROUTINE CGELQT3( M, N, A, LDA, T, LDT, INFO )
5 *
6 *       .. Scalar Arguments ..
7 *       INTEGER   INFO, LDA, M, N, LDT
8 *       ..
9 *       .. Array Arguments ..
10 *       COMPLEX   A( LDA, * ), T( LDT, * )
11 *       ..
12 *
13 *
14 *> \par Purpose:
15 *  =============
16 *>
17 *> \verbatim
18 *>
19 *> CGELQT3 recursively computes a LQ factorization of a complex M-by-N
20 *> matrix A, using the compact WY representation of Q.
21 *>
22 *> Based on the algorithm of Elmroth and Gustavson,
23 *> IBM J. Res. Develop. Vol 44 No. 4 July 2000.
24 *> \endverbatim
25 *
26 *  Arguments:
27 *  ==========
28 *
29 *> \param[in] M
30 *> \verbatim
31 *>          M is INTEGER
32 *>          The number of rows of the matrix A.  M =< N.
33 *> \endverbatim
34 *>
35 *> \param[in] N
36 *> \verbatim
37 *>          N is INTEGER
38 *>          The number of columns of the matrix A.  N >= 0.
39 *> \endverbatim
40 *>
41 *> \param[in,out] A
42 *> \verbatim
43 *>          A is COMPLEX array, dimension (LDA,N)
44 *>          On entry, the real M-by-N matrix A.  On exit, the elements on and
45 *>          below the diagonal contain the N-by-N lower triangular matrix L; the
46 *>          elements above the diagonal are the rows of V.  See below for
47 *>          further details.
48 *> \endverbatim
49 *>
50 *> \param[in] LDA
51 *> \verbatim
52 *>          LDA is INTEGER
53 *>          The leading dimension of the array A.  LDA >= max(1,M).
54 *> \endverbatim
55 *>
56 *> \param[out] T
57 *> \verbatim
58 *>          T is COMPLEX array, dimension (LDT,N)
59 *>          The N-by-N upper triangular factor of the block reflector.
60 *>          The elements on and above the diagonal contain the block
61 *>          reflector T; the elements below the diagonal are not used.
62 *>          See below for further details.
63 *> \endverbatim
64 *>
65 *> \param[in] LDT
66 *> \verbatim
67 *>          LDT is INTEGER
68 *>          The leading dimension of the array T.  LDT >= max(1,N).
69 *> \endverbatim
70 *>
71 *> \param[out] INFO
72 *> \verbatim
73 *>          INFO is INTEGER
74 *>          = 0: successful exit
75 *>          < 0: if INFO = -i, the i-th argument had an illegal value
76 *> \endverbatim
77 *
78 *  Authors:
79 *  ========
80 *
81 *> \author Univ. of Tennessee
82 *> \author Univ. of California Berkeley
83 *> \author Univ. of Colorado Denver
84 *> \author NAG Ltd.
85 *
86 *> \date December 2016
87 *
88 *> \ingroup doubleGEcomputational
89 *
90 *> \par Further Details:
91 *  =====================
92 *>
93 *> \verbatim
94 *>
95 *>  The matrix V stores the elementary reflectors H(i) in the i-th row
96 *>  above the diagonal. For example, if M=5 and N=3, the matrix V is
97 *>
98 *>               V = (  1  v1 v1 v1 v1 )
99 *>                   (     1  v2 v2 v2 )
100 *>                   (     1  v3 v3 v3 )
101 *>
102 *>
103 *>  where the vi's represent the vectors which define H(i), which are returned
104 *>  in the matrix A.  The 1's along the diagonal of V are not stored in A.  The
105 *>  block reflector H is then given by
106 *>
107 *>               H = I - V * T * V**T
108 *>
109 *>  where V**T is the transpose of V.
110 *>
111 *>  For details of the algorithm, see Elmroth and Gustavson (cited above).
112 *> \endverbatim
113 *>
114 *  =====================================================================
115       RECURSIVE SUBROUTINE CGELQT3( M, N, A, LDA, T, LDT, INFO )
116 *
117 *  -- LAPACK computational routine (version 3.7.0) --
118 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
119 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
120 *     December 2016
121 *
122 *     .. Scalar Arguments ..
123       INTEGER   INFO, LDA, M, N, LDT
124 *     ..
125 *     .. Array Arguments ..
126       COMPLEX   A( LDA, * ), T( LDT, * )
127 *     ..
128 *
129 *  =====================================================================
130 *
131 *     .. Parameters ..
132       COMPLEX   ONE, ZERO
133       PARAMETER ( ONE = (1.0E+00,0.0E+00) )
134       PARAMETER ( ZERO = (0.0E+00,0.0E+00))
135 *     ..
136 *     .. Local Scalars ..
137       INTEGER   I, I1, J, J1, M1, M2, N1, N2, IINFO
138 *     ..
139 *     .. External Subroutines ..
140       EXTERNAL  CLARFG, CTRMM, CGEMM, XERBLA
141 *     ..
142 *     .. Executable Statements ..
143 *
144       INFO = 0
145       IF( M .LT. 0 ) THEN
146          INFO = -1
147       ELSE IF( N .LT. M ) THEN
148          INFO = -2
149       ELSE IF( LDA .LT. MAX( 1, M ) ) THEN
150          INFO = -4
151       ELSE IF( LDT .LT. MAX( 1, M ) ) THEN
152          INFO = -6
153       END IF
154       IF( INFO.NE.0 ) THEN
155          CALL XERBLA( 'CGELQT3', -INFO )
156          RETURN
157       END IF
158 *
159       IF( M.EQ.1 ) THEN
160 *
161 *        Compute Householder transform when N=1
162 *
163          CALL CLARFG( N, A, A( 1, MIN( 2, N ) ), LDA, T )
164          T(1,1)=CONJG(T(1,1))
165 *
166       ELSE
167 *
168 *        Otherwise, split A into blocks...
169 *
170          M1 = M/2
171          M2 = M-M1
172          I1 = MIN( M1+1, M )
173          J1 = MIN( M+1, N )
174 *
175 *        Compute A(1:M1,1:N) <- (Y1,R1,T1), where Q1 = I - Y1 T1 Y1^H
176 *
177          CALL CGELQT3( M1, N, A, LDA, T, LDT, IINFO )
178 *
179 *        Compute A(J1:M,1:N) =  A(J1:M,1:N) Q1^H [workspace: T(1:N1,J1:N)]
180 *
181          DO I=1,M2
182             DO J=1,M1
183                T(  I+M1, J ) = A( I+M1, J )
184             END DO
185          END DO
186          CALL CTRMM( 'R', 'U', 'C', 'U', M2, M1, ONE,
187      &               A, LDA, T( I1, 1 ), LDT )
188 *
189          CALL CGEMM( 'N', 'C', M2, M1, N-M1, ONE, A( I1, I1 ), LDA,
190      &               A( 1, I1 ), LDA, ONE, T( I1, 1 ), LDT)
191 *
192          CALL CTRMM( 'R', 'U', 'N', 'N', M2, M1, ONE,
193      &               T, LDT, T( I1, 1 ), LDT )
194 *
195          CALL CGEMM( 'N', 'N', M2, N-M1, M1, -ONE, T( I1, 1 ), LDT,
196      &                A( 1, I1 ), LDA, ONE, A( I1, I1 ), LDA )
197 *
198          CALL CTRMM( 'R', 'U', 'N', 'U', M2, M1 , ONE,
199      &               A, LDA, T( I1, 1 ), LDT )
200 *
201          DO I=1,M2
202             DO J=1,M1
203                A(  I+M1, J ) = A( I+M1, J ) - T( I+M1, J )
204                T( I+M1, J )= ZERO
205             END DO
206          END DO
207 *
208 *        Compute A(J1:M,J1:N) <- (Y2,R2,T2) where Q2 = I - Y2 T2 Y2^H
209 *
210          CALL CGELQT3( M2, N-M1, A( I1, I1 ), LDA,
211      &                T( I1, I1 ), LDT, IINFO )
212 *
213 *        Compute T3 = T(J1:N1,1:N) = -T1 Y1^H Y2 T2
214 *
215          DO I=1,M2
216             DO J=1,M1
217                T( J, I+M1  ) = (A( J, I+M1 ))
218             END DO
219          END DO
220 *
221          CALL CTRMM( 'R', 'U', 'C', 'U', M1, M2, ONE,
222      &               A( I1, I1 ), LDA, T( 1, I1 ), LDT )
223 *
224          CALL CGEMM( 'N', 'C', M1, M2, N-M, ONE, A( 1, J1 ), LDA,
225      &               A( I1, J1 ), LDA, ONE, T( 1, I1 ), LDT )
226 *
227          CALL CTRMM( 'L', 'U', 'N', 'N', M1, M2, -ONE, T, LDT,
228      &               T( 1, I1 ), LDT )
229 *
230          CALL CTRMM( 'R', 'U', 'N', 'N', M1, M2, ONE,
231      &               T( I1, I1 ), LDT, T( 1, I1 ), LDT )
232 *
233 *
234 *
235 *        Y = (Y1,Y2); L = [ L1            0  ];  T = [T1 T3]
236 *                         [ A(1:N1,J1:N)  L2 ]       [ 0 T2]
237 *
238       END IF
239 *
240       RETURN
241 *
242 *     End of CGELQT3
243 *
244       END