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