001:       SUBROUTINE ZLABRD( M, N, NB, A, LDA, D, E, TAUQ, TAUP, X, LDX, Y,
002:      $                   LDY )
003: *
004: *  -- LAPACK auxiliary routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            LDA, LDX, LDY, M, N, NB
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   D( * ), E( * )
013:       COMPLEX*16         A( LDA, * ), TAUP( * ), TAUQ( * ), X( LDX, * ),
014:      $                   Y( LDY, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZLABRD reduces the first NB rows and columns of a complex general
021: *  m by n matrix A to upper or lower real bidiagonal form by a unitary
022: *  transformation Q' * A * P, and returns the matrices X and Y which
023: *  are needed to apply the transformation to the unreduced part of A.
024: *
025: *  If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower
026: *  bidiagonal form.
027: *
028: *  This is an auxiliary routine called by ZGEBRD
029: *
030: *  Arguments
031: *  =========
032: *
033: *  M       (input) INTEGER
034: *          The number of rows in the matrix A.
035: *
036: *  N       (input) INTEGER
037: *          The number of columns in the matrix A.
038: *
039: *  NB      (input) INTEGER
040: *          The number of leading rows and columns of A to be reduced.
041: *
042: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
043: *          On entry, the m by n general matrix to be reduced.
044: *          On exit, the first NB rows and columns of the matrix are
045: *          overwritten; the rest of the array is unchanged.
046: *          If m >= n, elements on and below the diagonal in the first NB
047: *            columns, with the array TAUQ, represent the unitary
048: *            matrix Q as a product of elementary reflectors; and
049: *            elements above the diagonal in the first NB rows, with the
050: *            array TAUP, represent the unitary matrix P as a product
051: *            of elementary reflectors.
052: *          If m < n, elements below the diagonal in the first NB
053: *            columns, with the array TAUQ, represent the unitary
054: *            matrix Q as a product of elementary reflectors, and
055: *            elements on and above the diagonal in the first NB rows,
056: *            with the array TAUP, represent the unitary matrix P as
057: *            a product of elementary reflectors.
058: *          See Further Details.
059: *
060: *  LDA     (input) INTEGER
061: *          The leading dimension of the array A.  LDA >= max(1,M).
062: *
063: *  D       (output) DOUBLE PRECISION array, dimension (NB)
064: *          The diagonal elements of the first NB rows and columns of
065: *          the reduced matrix.  D(i) = A(i,i).
066: *
067: *  E       (output) DOUBLE PRECISION array, dimension (NB)
068: *          The off-diagonal elements of the first NB rows and columns of
069: *          the reduced matrix.
070: *
071: *  TAUQ    (output) COMPLEX*16 array dimension (NB)
072: *          The scalar factors of the elementary reflectors which
073: *          represent the unitary matrix Q. See Further Details.
074: *
075: *  TAUP    (output) COMPLEX*16 array, dimension (NB)
076: *          The scalar factors of the elementary reflectors which
077: *          represent the unitary matrix P. See Further Details.
078: *
079: *  X       (output) COMPLEX*16 array, dimension (LDX,NB)
080: *          The m-by-nb matrix X required to update the unreduced part
081: *          of A.
082: *
083: *  LDX     (input) INTEGER
084: *          The leading dimension of the array X. LDX >= max(1,M).
085: *
086: *  Y       (output) COMPLEX*16 array, dimension (LDY,NB)
087: *          The n-by-nb matrix Y required to update the unreduced part
088: *          of A.
089: *
090: *  LDY     (input) INTEGER
091: *          The leading dimension of the array Y. LDY >= max(1,N).
092: *
093: *  Further Details
094: *  ===============
095: *
096: *  The matrices Q and P are represented as products of elementary
097: *  reflectors:
098: *
099: *     Q = H(1) H(2) . . . H(nb)  and  P = G(1) G(2) . . . G(nb)
100: *
101: *  Each H(i) and G(i) has the form:
102: *
103: *     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
104: *
105: *  where tauq and taup are complex scalars, and v and u are complex
106: *  vectors.
107: *
108: *  If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in
109: *  A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in
110: *  A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
111: *
112: *  If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in
113: *  A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in
114: *  A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
115: *
116: *  The elements of the vectors v and u together form the m-by-nb matrix
117: *  V and the nb-by-n matrix U' which are needed, with X and Y, to apply
118: *  the transformation to the unreduced part of the matrix, using a block
119: *  update of the form:  A := A - V*Y' - X*U'.
120: *
121: *  The contents of A on exit are illustrated by the following examples
122: *  with nb = 2:
123: *
124: *  m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n):
125: *
126: *    (  1   1   u1  u1  u1 )           (  1   u1  u1  u1  u1  u1 )
127: *    (  v1  1   1   u2  u2 )           (  1   1   u2  u2  u2  u2 )
128: *    (  v1  v2  a   a   a  )           (  v1  1   a   a   a   a  )
129: *    (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  )
130: *    (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  )
131: *    (  v1  v2  a   a   a  )
132: *
133: *  where a denotes an element of the original matrix which is unchanged,
134: *  vi denotes an element of the vector defining H(i), and ui an element
135: *  of the vector defining G(i).
136: *
137: *  =====================================================================
138: *
139: *     .. Parameters ..
140:       COMPLEX*16         ZERO, ONE
141:       PARAMETER          ( ZERO = ( 0.0D+0, 0.0D+0 ),
142:      $                   ONE = ( 1.0D+0, 0.0D+0 ) )
143: *     ..
144: *     .. Local Scalars ..
145:       INTEGER            I
146:       COMPLEX*16         ALPHA
147: *     ..
148: *     .. External Subroutines ..
149:       EXTERNAL           ZGEMV, ZLACGV, ZLARFG, ZSCAL
150: *     ..
151: *     .. Intrinsic Functions ..
152:       INTRINSIC          MIN
153: *     ..
154: *     .. Executable Statements ..
155: *
156: *     Quick return if possible
157: *
158:       IF( M.LE.0 .OR. N.LE.0 )
159:      $   RETURN
160: *
161:       IF( M.GE.N ) THEN
162: *
163: *        Reduce to upper bidiagonal form
164: *
165:          DO 10 I = 1, NB
166: *
167: *           Update A(i:m,i)
168: *
169:             CALL ZLACGV( I-1, Y( I, 1 ), LDY )
170:             CALL ZGEMV( 'No transpose', M-I+1, I-1, -ONE, A( I, 1 ),
171:      $                  LDA, Y( I, 1 ), LDY, ONE, A( I, I ), 1 )
172:             CALL ZLACGV( I-1, Y( I, 1 ), LDY )
173:             CALL ZGEMV( 'No transpose', M-I+1, I-1, -ONE, X( I, 1 ),
174:      $                  LDX, A( 1, I ), 1, ONE, A( I, I ), 1 )
175: *
176: *           Generate reflection Q(i) to annihilate A(i+1:m,i)
177: *
178:             ALPHA = A( I, I )
179:             CALL ZLARFG( M-I+1, ALPHA, A( MIN( I+1, M ), I ), 1,
180:      $                   TAUQ( I ) )
181:             D( I ) = ALPHA
182:             IF( I.LT.N ) THEN
183:                A( I, I ) = ONE
184: *
185: *              Compute Y(i+1:n,i)
186: *
187:                CALL ZGEMV( 'Conjugate transpose', M-I+1, N-I, ONE,
188:      $                     A( I, I+1 ), LDA, A( I, I ), 1, ZERO,
189:      $                     Y( I+1, I ), 1 )
190:                CALL ZGEMV( 'Conjugate transpose', M-I+1, I-1, ONE,
191:      $                     A( I, 1 ), LDA, A( I, I ), 1, ZERO,
192:      $                     Y( 1, I ), 1 )
193:                CALL ZGEMV( 'No transpose', N-I, I-1, -ONE, Y( I+1, 1 ),
194:      $                     LDY, Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
195:                CALL ZGEMV( 'Conjugate transpose', M-I+1, I-1, ONE,
196:      $                     X( I, 1 ), LDX, A( I, I ), 1, ZERO,
197:      $                     Y( 1, I ), 1 )
198:                CALL ZGEMV( 'Conjugate transpose', I-1, N-I, -ONE,
199:      $                     A( 1, I+1 ), LDA, Y( 1, I ), 1, ONE,
200:      $                     Y( I+1, I ), 1 )
201:                CALL ZSCAL( N-I, TAUQ( I ), Y( I+1, I ), 1 )
202: *
203: *              Update A(i,i+1:n)
204: *
205:                CALL ZLACGV( N-I, A( I, I+1 ), LDA )
206:                CALL ZLACGV( I, A( I, 1 ), LDA )
207:                CALL ZGEMV( 'No transpose', N-I, I, -ONE, Y( I+1, 1 ),
208:      $                     LDY, A( I, 1 ), LDA, ONE, A( I, I+1 ), LDA )
209:                CALL ZLACGV( I, A( I, 1 ), LDA )
210:                CALL ZLACGV( I-1, X( I, 1 ), LDX )
211:                CALL ZGEMV( 'Conjugate transpose', I-1, N-I, -ONE,
212:      $                     A( 1, I+1 ), LDA, X( I, 1 ), LDX, ONE,
213:      $                     A( I, I+1 ), LDA )
214:                CALL ZLACGV( I-1, X( I, 1 ), LDX )
215: *
216: *              Generate reflection P(i) to annihilate A(i,i+2:n)
217: *
218:                ALPHA = A( I, I+1 )
219:                CALL ZLARFG( N-I, ALPHA, A( I, MIN( I+2, N ) ), LDA,
220:      $                      TAUP( I ) )
221:                E( I ) = ALPHA
222:                A( I, I+1 ) = ONE
223: *
224: *              Compute X(i+1:m,i)
225: *
226:                CALL ZGEMV( 'No transpose', M-I, N-I, ONE, A( I+1, I+1 ),
227:      $                     LDA, A( I, I+1 ), LDA, ZERO, X( I+1, I ), 1 )
228:                CALL ZGEMV( 'Conjugate transpose', N-I, I, ONE,
229:      $                     Y( I+1, 1 ), LDY, A( I, I+1 ), LDA, ZERO,
230:      $                     X( 1, I ), 1 )
231:                CALL ZGEMV( 'No transpose', M-I, I, -ONE, A( I+1, 1 ),
232:      $                     LDA, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
233:                CALL ZGEMV( 'No transpose', I-1, N-I, ONE, A( 1, I+1 ),
234:      $                     LDA, A( I, I+1 ), LDA, ZERO, X( 1, I ), 1 )
235:                CALL ZGEMV( 'No transpose', M-I, I-1, -ONE, X( I+1, 1 ),
236:      $                     LDX, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
237:                CALL ZSCAL( M-I, TAUP( I ), X( I+1, I ), 1 )
238:                CALL ZLACGV( N-I, A( I, I+1 ), LDA )
239:             END IF
240:    10    CONTINUE
241:       ELSE
242: *
243: *        Reduce to lower bidiagonal form
244: *
245:          DO 20 I = 1, NB
246: *
247: *           Update A(i,i:n)
248: *
249:             CALL ZLACGV( N-I+1, A( I, I ), LDA )
250:             CALL ZLACGV( I-1, A( I, 1 ), LDA )
251:             CALL ZGEMV( 'No transpose', N-I+1, I-1, -ONE, Y( I, 1 ),
252:      $                  LDY, A( I, 1 ), LDA, ONE, A( I, I ), LDA )
253:             CALL ZLACGV( I-1, A( I, 1 ), LDA )
254:             CALL ZLACGV( I-1, X( I, 1 ), LDX )
255:             CALL ZGEMV( 'Conjugate transpose', I-1, N-I+1, -ONE,
256:      $                  A( 1, I ), LDA, X( I, 1 ), LDX, ONE, A( I, I ),
257:      $                  LDA )
258:             CALL ZLACGV( I-1, X( I, 1 ), LDX )
259: *
260: *           Generate reflection P(i) to annihilate A(i,i+1:n)
261: *
262:             ALPHA = A( I, I )
263:             CALL ZLARFG( N-I+1, ALPHA, A( I, MIN( I+1, N ) ), LDA,
264:      $                   TAUP( I ) )
265:             D( I ) = ALPHA
266:             IF( I.LT.M ) THEN
267:                A( I, I ) = ONE
268: *
269: *              Compute X(i+1:m,i)
270: *
271:                CALL ZGEMV( 'No transpose', M-I, N-I+1, ONE, A( I+1, I ),
272:      $                     LDA, A( I, I ), LDA, ZERO, X( I+1, I ), 1 )
273:                CALL ZGEMV( 'Conjugate transpose', N-I+1, I-1, ONE,
274:      $                     Y( I, 1 ), LDY, A( I, I ), LDA, ZERO,
275:      $                     X( 1, I ), 1 )
276:                CALL ZGEMV( 'No transpose', M-I, I-1, -ONE, A( I+1, 1 ),
277:      $                     LDA, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
278:                CALL ZGEMV( 'No transpose', I-1, N-I+1, ONE, A( 1, I ),
279:      $                     LDA, A( I, I ), LDA, ZERO, X( 1, I ), 1 )
280:                CALL ZGEMV( 'No transpose', M-I, I-1, -ONE, X( I+1, 1 ),
281:      $                     LDX, X( 1, I ), 1, ONE, X( I+1, I ), 1 )
282:                CALL ZSCAL( M-I, TAUP( I ), X( I+1, I ), 1 )
283:                CALL ZLACGV( N-I+1, A( I, I ), LDA )
284: *
285: *              Update A(i+1:m,i)
286: *
287:                CALL ZLACGV( I-1, Y( I, 1 ), LDY )
288:                CALL ZGEMV( 'No transpose', M-I, I-1, -ONE, A( I+1, 1 ),
289:      $                     LDA, Y( I, 1 ), LDY, ONE, A( I+1, I ), 1 )
290:                CALL ZLACGV( I-1, Y( I, 1 ), LDY )
291:                CALL ZGEMV( 'No transpose', M-I, I, -ONE, X( I+1, 1 ),
292:      $                     LDX, A( 1, I ), 1, ONE, A( I+1, I ), 1 )
293: *
294: *              Generate reflection Q(i) to annihilate A(i+2:m,i)
295: *
296:                ALPHA = A( I+1, I )
297:                CALL ZLARFG( M-I, ALPHA, A( MIN( I+2, M ), I ), 1,
298:      $                      TAUQ( I ) )
299:                E( I ) = ALPHA
300:                A( I+1, I ) = ONE
301: *
302: *              Compute Y(i+1:n,i)
303: *
304:                CALL ZGEMV( 'Conjugate transpose', M-I, N-I, ONE,
305:      $                     A( I+1, I+1 ), LDA, A( I+1, I ), 1, ZERO,
306:      $                     Y( I+1, I ), 1 )
307:                CALL ZGEMV( 'Conjugate transpose', M-I, I-1, ONE,
308:      $                     A( I+1, 1 ), LDA, A( I+1, I ), 1, ZERO,
309:      $                     Y( 1, I ), 1 )
310:                CALL ZGEMV( 'No transpose', N-I, I-1, -ONE, Y( I+1, 1 ),
311:      $                     LDY, Y( 1, I ), 1, ONE, Y( I+1, I ), 1 )
312:                CALL ZGEMV( 'Conjugate transpose', M-I, I, ONE,
313:      $                     X( I+1, 1 ), LDX, A( I+1, I ), 1, ZERO,
314:      $                     Y( 1, I ), 1 )
315:                CALL ZGEMV( 'Conjugate transpose', I, N-I, -ONE,
316:      $                     A( 1, I+1 ), LDA, Y( 1, I ), 1, ONE,
317:      $                     Y( I+1, I ), 1 )
318:                CALL ZSCAL( N-I, TAUQ( I ), Y( I+1, I ), 1 )
319:             ELSE
320:                CALL ZLACGV( N-I+1, A( I, I ), LDA )
321:             END IF
322:    20    CONTINUE
323:       END IF
324:       RETURN
325: *
326: *     End of ZLABRD
327: *
328:       END
329: