3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGBBRD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgbbrd.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgbbrd.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgbbrd.f">
21 * SUBROUTINE SGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q,
22 * LDQ, PT, LDPT, C, LDC, WORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC
28 * .. Array Arguments ..
29 * REAL AB( LDAB, * ), C( LDC, * ), D( * ), E( * ),
30 * $ PT( LDPT, * ), Q( LDQ, * ), WORK( * )
39 *> SGBBRD reduces a real general m-by-n band matrix A to upper
40 *> bidiagonal form B by an orthogonal transformation: Q**T * A * P = B.
42 *> The routine computes B, and optionally forms Q or P**T, or computes
43 *> Q**T*C for a given matrix C.
51 *> VECT is CHARACTER*1
52 *> Specifies whether or not the matrices Q and P**T are to be
54 *> = 'N': do not form Q or P**T;
55 *> = 'Q': form Q only;
56 *> = 'P': form P**T only;
63 *> The number of rows of the matrix A. M >= 0.
69 *> The number of columns of the matrix A. N >= 0.
75 *> The number of columns of the matrix C. NCC >= 0.
81 *> The number of subdiagonals of the matrix A. KL >= 0.
87 *> The number of superdiagonals of the matrix A. KU >= 0.
92 *> AB is REAL array, dimension (LDAB,N)
93 *> On entry, the m-by-n band matrix A, stored in rows 1 to
94 *> KL+KU+1. The j-th column of A is stored in the j-th column of
95 *> the array AB as follows:
96 *> AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl).
97 *> On exit, A is overwritten by values generated during the
104 *> The leading dimension of the array A. LDAB >= KL+KU+1.
109 *> D is REAL array, dimension (min(M,N))
110 *> The diagonal elements of the bidiagonal matrix B.
115 *> E is REAL array, dimension (min(M,N)-1)
116 *> The superdiagonal elements of the bidiagonal matrix B.
121 *> Q is REAL array, dimension (LDQ,M)
122 *> If VECT = 'Q' or 'B', the m-by-m orthogonal matrix Q.
123 *> If VECT = 'N' or 'P', the array Q is not referenced.
129 *> The leading dimension of the array Q.
130 *> LDQ >= max(1,M) if VECT = 'Q' or 'B'; LDQ >= 1 otherwise.
135 *> PT is REAL array, dimension (LDPT,N)
136 *> If VECT = 'P' or 'B', the n-by-n orthogonal matrix P'.
137 *> If VECT = 'N' or 'Q', the array PT is not referenced.
143 *> The leading dimension of the array PT.
144 *> LDPT >= max(1,N) if VECT = 'P' or 'B'; LDPT >= 1 otherwise.
149 *> C is REAL array, dimension (LDC,NCC)
150 *> On entry, an m-by-ncc matrix C.
151 *> On exit, C is overwritten by Q**T*C.
152 *> C is not referenced if NCC = 0.
158 *> The leading dimension of the array C.
159 *> LDC >= max(1,M) if NCC > 0; LDC >= 1 if NCC = 0.
164 *> WORK is REAL array, dimension (2*max(M,N))
170 *> = 0: successful exit.
171 *> < 0: if INFO = -i, the i-th argument had an illegal value.
177 *> \author Univ. of Tennessee
178 *> \author Univ. of California Berkeley
179 *> \author Univ. of Colorado Denver
182 *> \date November 2011
184 *> \ingroup realGBcomputational
186 * =====================================================================
187 SUBROUTINE SGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q,
188 $ LDQ, PT, LDPT, C, LDC, WORK, INFO )
190 * -- LAPACK computational routine (version 3.4.0) --
191 * -- LAPACK is a software package provided by Univ. of Tennessee, --
192 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
195 * .. Scalar Arguments ..
197 INTEGER INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC
199 * .. Array Arguments ..
200 REAL AB( LDAB, * ), C( LDC, * ), D( * ), E( * ),
201 $ PT( LDPT, * ), Q( LDQ, * ), WORK( * )
204 * =====================================================================
208 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
210 * .. Local Scalars ..
211 LOGICAL WANTB, WANTC, WANTPT, WANTQ
212 INTEGER I, INCA, J, J1, J2, KB, KB1, KK, KLM, KLU1,
213 $ KUN, L, MINMN, ML, ML0, MN, MU, MU0, NR, NRT
216 * .. External Subroutines ..
217 EXTERNAL SLARGV, SLARTG, SLARTV, SLASET, SROT, XERBLA
219 * .. Intrinsic Functions ..
222 * .. External Functions ..
226 * .. Executable Statements ..
228 * Test the input parameters
230 WANTB = LSAME( VECT, 'B' )
231 WANTQ = LSAME( VECT, 'Q' ) .OR. WANTB
232 WANTPT = LSAME( VECT, 'P' ) .OR. WANTB
236 IF( .NOT.WANTQ .AND. .NOT.WANTPT .AND. .NOT.LSAME( VECT, 'N' ) )
239 ELSE IF( M.LT.0 ) THEN
241 ELSE IF( N.LT.0 ) THEN
243 ELSE IF( NCC.LT.0 ) THEN
245 ELSE IF( KL.LT.0 ) THEN
247 ELSE IF( KU.LT.0 ) THEN
249 ELSE IF( LDAB.LT.KLU1 ) THEN
251 ELSE IF( LDQ.LT.1 .OR. WANTQ .AND. LDQ.LT.MAX( 1, M ) ) THEN
253 ELSE IF( LDPT.LT.1 .OR. WANTPT .AND. LDPT.LT.MAX( 1, N ) ) THEN
255 ELSE IF( LDC.LT.1 .OR. WANTC .AND. LDC.LT.MAX( 1, M ) ) THEN
259 CALL XERBLA( 'SGBBRD', -INFO )
263 * Initialize Q and P**T to the unit matrix, if needed
266 $ CALL SLASET( 'Full', M, M, ZERO, ONE, Q, LDQ )
268 $ CALL SLASET( 'Full', N, N, ZERO, ONE, PT, LDPT )
270 * Quick return if possible.
272 IF( M.EQ.0 .OR. N.EQ.0 )
277 IF( KL+KU.GT.1 ) THEN
279 * Reduce to upper bidiagonal form if KU > 0; if KU = 0, reduce
280 * first to lower bidiagonal form and then transform to upper
291 * Wherever possible, plane rotations are generated and applied in
292 * vector operations of length NR over the index set J1:J2:KLU1.
294 * The sines of the plane rotations are stored in WORK(1:max(m,n))
295 * and the cosines in WORK(max(m,n)+1:2*max(m,n)).
309 * Reduce i-th column and i-th row of matrix to bidiagonal form
317 * generate plane rotations to annihilate nonzero elements
318 * which have been created below the band
321 $ CALL SLARGV( NR, AB( KLU1, J1-KLM-1 ), INCA,
322 $ WORK( J1 ), KB1, WORK( MN+J1 ), KB1 )
324 * apply plane rotations from the left
327 IF( J2-KLM+L-1.GT.N ) THEN
333 $ CALL SLARTV( NRT, AB( KLU1-L, J1-KLM+L-1 ), INCA,
334 $ AB( KLU1-L+1, J1-KLM+L-1 ), INCA,
335 $ WORK( MN+J1 ), WORK( J1 ), KB1 )
339 IF( ML.LE.M-I+1 ) THEN
341 * generate plane rotation to annihilate a(i+ml-1,i)
342 * within the band, and apply rotation from the left
344 CALL SLARTG( AB( KU+ML-1, I ), AB( KU+ML, I ),
345 $ WORK( MN+I+ML-1 ), WORK( I+ML-1 ),
347 AB( KU+ML-1, I ) = RA
349 $ CALL SROT( MIN( KU+ML-2, N-I ),
350 $ AB( KU+ML-2, I+1 ), LDAB-1,
351 $ AB( KU+ML-1, I+1 ), LDAB-1,
352 $ WORK( MN+I+ML-1 ), WORK( I+ML-1 ) )
360 * accumulate product of plane rotations in Q
362 DO 20 J = J1, J2, KB1
363 CALL SROT( M, Q( 1, J-1 ), 1, Q( 1, J ), 1,
364 $ WORK( MN+J ), WORK( J ) )
370 * apply plane rotations to C
372 DO 30 J = J1, J2, KB1
373 CALL SROT( NCC, C( J-1, 1 ), LDC, C( J, 1 ), LDC,
374 $ WORK( MN+J ), WORK( J ) )
378 IF( J2+KUN.GT.N ) THEN
380 * adjust J2 to keep within the bounds of the matrix
386 DO 40 J = J1, J2, KB1
388 * create nonzero element a(j-1,j+ku) above the band
389 * and store it in WORK(n+1:2*n)
391 WORK( J+KUN ) = WORK( J )*AB( 1, J+KUN )
392 AB( 1, J+KUN ) = WORK( MN+J )*AB( 1, J+KUN )
395 * generate plane rotations to annihilate nonzero elements
396 * which have been generated above the band
399 $ CALL SLARGV( NR, AB( 1, J1+KUN-1 ), INCA,
400 $ WORK( J1+KUN ), KB1, WORK( MN+J1+KUN ),
403 * apply plane rotations from the right
406 IF( J2+L-1.GT.M ) THEN
412 $ CALL SLARTV( NRT, AB( L+1, J1+KUN-1 ), INCA,
413 $ AB( L, J1+KUN ), INCA,
414 $ WORK( MN+J1+KUN ), WORK( J1+KUN ),
418 IF( ML.EQ.ML0 .AND. MU.GT.MU0 ) THEN
419 IF( MU.LE.N-I+1 ) THEN
421 * generate plane rotation to annihilate a(i,i+mu-1)
422 * within the band, and apply rotation from the right
424 CALL SLARTG( AB( KU-MU+3, I+MU-2 ),
425 $ AB( KU-MU+2, I+MU-1 ),
426 $ WORK( MN+I+MU-1 ), WORK( I+MU-1 ),
428 AB( KU-MU+3, I+MU-2 ) = RA
429 CALL SROT( MIN( KL+MU-2, M-I ),
430 $ AB( KU-MU+4, I+MU-2 ), 1,
431 $ AB( KU-MU+3, I+MU-1 ), 1,
432 $ WORK( MN+I+MU-1 ), WORK( I+MU-1 ) )
440 * accumulate product of plane rotations in P**T
442 DO 60 J = J1, J2, KB1
443 CALL SROT( N, PT( J+KUN-1, 1 ), LDPT,
444 $ PT( J+KUN, 1 ), LDPT, WORK( MN+J+KUN ),
449 IF( J2+KB.GT.M ) THEN
451 * adjust J2 to keep within the bounds of the matrix
457 DO 70 J = J1, J2, KB1
459 * create nonzero element a(j+kl+ku,j+ku-1) below the
460 * band and store it in WORK(1:n)
462 WORK( J+KB ) = WORK( J+KUN )*AB( KLU1, J+KUN )
463 AB( KLU1, J+KUN ) = WORK( MN+J+KUN )*AB( KLU1, J+KUN )
475 IF( KU.EQ.0 .AND. KL.GT.0 ) THEN
477 * A has been reduced to lower bidiagonal form
479 * Transform lower bidiagonal form to upper bidiagonal by applying
480 * plane rotations from the left, storing diagonal elements in D
481 * and off-diagonal elements in E
483 DO 100 I = 1, MIN( M-1, N )
484 CALL SLARTG( AB( 1, I ), AB( 2, I ), RC, RS, RA )
487 E( I ) = RS*AB( 1, I+1 )
488 AB( 1, I+1 ) = RC*AB( 1, I+1 )
491 $ CALL SROT( M, Q( 1, I ), 1, Q( 1, I+1 ), 1, RC, RS )
493 $ CALL SROT( NCC, C( I, 1 ), LDC, C( I+1, 1 ), LDC, RC,
497 $ D( M ) = AB( 1, M )
498 ELSE IF( KU.GT.0 ) THEN
500 * A has been reduced to upper bidiagonal form
504 * Annihilate a(m,m+1) by applying plane rotations from the
505 * right, storing diagonal elements in D and off-diagonal
510 CALL SLARTG( AB( KU+1, I ), RB, RC, RS, RA )
514 E( I-1 ) = RC*AB( KU, I )
517 $ CALL SROT( N, PT( I, 1 ), LDPT, PT( M+1, 1 ), LDPT,
522 * Copy off-diagonal elements to E and diagonal elements to D
524 DO 120 I = 1, MINMN - 1
525 E( I ) = AB( KU, I+1 )
528 D( I ) = AB( KU+1, I )
533 * A is diagonal. Set elements of E to zero and copy diagonal
536 DO 140 I = 1, MINMN - 1