3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CHBGST + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chbgst.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chbgst.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chbgst.f">
21 * SUBROUTINE CHBGST( VECT, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, X,
22 * LDX, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER UPLO, VECT
26 * INTEGER INFO, KA, KB, LDAB, LDBB, LDX, N
28 * .. Array Arguments ..
30 * COMPLEX AB( LDAB, * ), BB( LDBB, * ), WORK( * ),
40 *> CHBGST reduces a complex Hermitian-definite banded generalized
41 *> eigenproblem A*x = lambda*B*x to standard form C*y = lambda*y,
42 *> such that C has the same bandwidth as A.
44 *> B must have been previously factorized as S**H*S by CPBSTF, using a
45 *> split Cholesky factorization. A is overwritten by C = X**H*A*X, where
46 *> X = S**(-1)*Q and Q is a unitary matrix chosen to preserve the
55 *> VECT is CHARACTER*1
56 *> = 'N': do not form the transformation matrix X;
62 *> UPLO is CHARACTER*1
63 *> = 'U': Upper triangle of A is stored;
64 *> = 'L': Lower triangle of A is stored.
70 *> The order of the matrices A and B. N >= 0.
76 *> The number of superdiagonals of the matrix A if UPLO = 'U',
77 *> or the number of subdiagonals if UPLO = 'L'. KA >= 0.
83 *> The number of superdiagonals of the matrix B if UPLO = 'U',
84 *> or the number of subdiagonals if UPLO = 'L'. KA >= KB >= 0.
89 *> AB is COMPLEX array, dimension (LDAB,N)
90 *> On entry, the upper or lower triangle of the Hermitian band
91 *> matrix A, stored in the first ka+1 rows of the array. The
92 *> j-th column of A is stored in the j-th column of the array AB
94 *> if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j;
95 *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka).
97 *> On exit, the transformed matrix X**H*A*X, stored in the same
104 *> The leading dimension of the array AB. LDAB >= KA+1.
109 *> BB is COMPLEX array, dimension (LDBB,N)
110 *> The banded factor S from the split Cholesky factorization of
111 *> B, as returned by CPBSTF, stored in the first kb+1 rows of
118 *> The leading dimension of the array BB. LDBB >= KB+1.
123 *> X is COMPLEX array, dimension (LDX,N)
124 *> If VECT = 'V', the n-by-n matrix X.
125 *> If VECT = 'N', the array X is not referenced.
131 *> The leading dimension of the array X.
132 *> LDX >= max(1,N) if VECT = 'V'; LDX >= 1 otherwise.
137 *> WORK is COMPLEX array, dimension (N)
142 *> RWORK is REAL array, dimension (N)
148 *> = 0: successful exit
149 *> < 0: if INFO = -i, the i-th argument had an illegal value.
155 *> \author Univ. of Tennessee
156 *> \author Univ. of California Berkeley
157 *> \author Univ. of Colorado Denver
160 *> \date November 2011
162 *> \ingroup complexOTHERcomputational
164 * =====================================================================
165 SUBROUTINE CHBGST( VECT, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, X,
166 $ LDX, WORK, RWORK, INFO )
168 * -- LAPACK computational routine (version 3.4.0) --
169 * -- LAPACK is a software package provided by Univ. of Tennessee, --
170 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
173 * .. Scalar Arguments ..
175 INTEGER INFO, KA, KB, LDAB, LDBB, LDX, N
177 * .. Array Arguments ..
179 COMPLEX AB( LDAB, * ), BB( LDBB, * ), WORK( * ),
183 * =====================================================================
188 PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
189 $ CONE = ( 1.0E+0, 0.0E+0 ), ONE = 1.0E+0 )
191 * .. Local Scalars ..
192 LOGICAL UPDATE, UPPER, WANTX
193 INTEGER I, I0, I1, I2, INCA, J, J1, J1T, J2, J2T, K,
194 $ KA1, KB1, KBT, L, M, NR, NRT, NX
198 * .. External Functions ..
202 * .. External Subroutines ..
203 EXTERNAL CGERC, CGERU, CLACGV, CLAR2V, CLARGV, CLARTG,
204 $ CLARTV, CLASET, CROT, CSSCAL, XERBLA
206 * .. Intrinsic Functions ..
207 INTRINSIC CONJG, MAX, MIN, REAL
209 * .. Executable Statements ..
211 * Test the input parameters
213 WANTX = LSAME( VECT, 'V' )
214 UPPER = LSAME( UPLO, 'U' )
218 IF( .NOT.WANTX .AND. .NOT.LSAME( VECT, 'N' ) ) THEN
220 ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
222 ELSE IF( N.LT.0 ) THEN
224 ELSE IF( KA.LT.0 ) THEN
226 ELSE IF( KB.LT.0 .OR. KB.GT.KA ) THEN
228 ELSE IF( LDAB.LT.KA+1 ) THEN
230 ELSE IF( LDBB.LT.KB+1 ) THEN
232 ELSE IF( LDX.LT.1 .OR. WANTX .AND. LDX.LT.MAX( 1, N ) ) THEN
236 CALL XERBLA( 'CHBGST', -INFO )
240 * Quick return if possible
247 * Initialize X to the unit matrix, if needed
250 $ CALL CLASET( 'Full', N, N, CZERO, CONE, X, LDX )
252 * Set M to the splitting point m. It must be the same value as is
253 * used in CPBSTF. The chosen value allows the arrays WORK and RWORK
254 * to be of dimension (N).
258 * The routine works in two phases, corresponding to the two halves
259 * of the split Cholesky factorization of B as S**H*S where
264 * with U upper triangular of order m, and L lower triangular of
265 * order n-m. S has the same bandwidth as B.
267 * S is treated as a product of elementary matrices:
269 * S = S(m)*S(m-1)*...*S(2)*S(1)*S(m+1)*S(m+2)*...*S(n-1)*S(n)
271 * where S(i) is determined by the i-th row of S.
273 * In phase 1, the index i takes the values n, n-1, ... , m+1;
274 * in phase 2, it takes the values 1, 2, ... , m.
276 * For each value of i, the current matrix A is updated by forming
277 * inv(S(i))**H*A*inv(S(i)). This creates a triangular bulge outside
278 * the band of A. The bulge is then pushed down toward the bottom of
279 * A in phase 1, and up toward the top of A in phase 2, by applying
282 * There are kb*(kb+1)/2 elements in the bulge, but at most 2*kb-1
283 * of them are linearly independent, so annihilating a bulge requires
284 * only 2*kb-1 plane rotations. The rotations are divided into a 1st
285 * set of kb-1 rotations, and a 2nd set of kb rotations.
287 * Wherever possible, rotations are generated and applied in vector
288 * operations of length NR between the indices J1 and J2 (sometimes
289 * replaced by modified values NRT, J1T or J2T).
291 * The real cosines and complex sines of the rotations are stored in
292 * the arrays RWORK and WORK, those of the 1st set in elements
293 * 2:m-kb-1, and those of the 2nd set in elements m-kb+1:n.
295 * The bulges are not formed explicitly; nonzero elements outside the
296 * band are created only when they are required for generating new
297 * rotations; they are stored in the array WORK, in positions where
298 * they are later overwritten by the sines of the rotations which
301 * **************************** Phase 1 *****************************
303 * The logical structure of this phase is:
306 * DO I = N, M + 1, -1
307 * use S(i) to update A and create a new bulge
308 * apply rotations to push all bulges KA positions downward
311 * DO I = M + KA + 1, N - 1
312 * apply rotations to push all bulges KA positions downward
315 * To avoid duplicating code, the two loops are merged.
342 * Transform A, working with the upper triangle
346 * Form inv(S(i))**H * A * inv(S(i))
348 BII = REAL( BB( KB1, I ) )
349 AB( KA1, I ) = ( REAL( AB( KA1, I ) ) / BII ) / BII
351 AB( I-J+KA1, J ) = AB( I-J+KA1, J ) / BII
353 DO 30 J = MAX( 1, I-KA ), I - 1
354 AB( J-I+KA1, I ) = AB( J-I+KA1, I ) / BII
356 DO 60 K = I - KBT, I - 1
358 AB( J-K+KA1, K ) = AB( J-K+KA1, K ) -
360 $ CONJG( AB( K-I+KA1, I ) ) -
361 $ CONJG( BB( K-I+KB1, I ) )*
363 $ REAL( AB( KA1, I ) )*
365 $ CONJG( BB( K-I+KB1, I ) )
367 DO 50 J = MAX( 1, I-KA ), I - KBT - 1
368 AB( J-K+KA1, K ) = AB( J-K+KA1, K ) -
369 $ CONJG( BB( K-I+KB1, I ) )*
374 DO 70 K = MAX( J-KA, I-KBT ), I - 1
375 AB( K-J+KA1, J ) = AB( K-J+KA1, J ) -
376 $ BB( K-I+KB1, I )*AB( I-J+KA1, J )
382 * post-multiply X by inv(S(i))
384 CALL CSSCAL( N-M, ONE / BII, X( M+1, I ), 1 )
386 $ CALL CGERC( N-M, KBT, -CONE, X( M+1, I ), 1,
387 $ BB( KB1-KBT, I ), 1, X( M+1, I-KBT ),
391 * store a(i,i1) in RA1 for use in next loop over K
393 RA1 = AB( I-I1+KA1, I1 )
396 * Generate and apply vectors of rotations to chase all the
397 * existing bulges KA positions down toward the bottom of the
403 * Determine the rotations which would annihilate the bulge
404 * which has in theory just been created
406 IF( I-K+KA.LT.N .AND. I-K.GT.1 ) THEN
408 * generate rotation to annihilate a(i,i-k+ka+1)
410 CALL CLARTG( AB( K+1, I-K+KA ), RA1,
411 $ RWORK( I-K+KA-M ), WORK( I-K+KA-M ), RA )
413 * create nonzero element a(i-k,i-k+ka+1) outside the
414 * band and store it in WORK(i-k)
416 T = -BB( KB1-K, I )*RA1
417 WORK( I-K ) = RWORK( I-K+KA-M )*T -
418 $ CONJG( WORK( I-K+KA-M ) )*
420 AB( 1, I-K+KA ) = WORK( I-K+KA-M )*T +
421 $ RWORK( I-K+KA-M )*AB( 1, I-K+KA )
425 J2 = I - K - 1 + MAX( 1, K-I0+2 )*KA1
426 NR = ( N-J2+KA ) / KA1
427 J1 = J2 + ( NR-1 )*KA1
429 J2T = MAX( J2, I+2*KA-K+1 )
433 NRT = ( N-J2T+KA ) / KA1
434 DO 90 J = J2T, J1, KA1
436 * create nonzero element a(j-ka,j+1) outside the band
437 * and store it in WORK(j-m)
439 WORK( J-M ) = WORK( J-M )*AB( 1, J+1 )
440 AB( 1, J+1 ) = RWORK( J-M )*AB( 1, J+1 )
443 * generate rotations in 1st set to annihilate elements which
444 * have been created outside the band
447 $ CALL CLARGV( NRT, AB( 1, J2T ), INCA, WORK( J2T-M ), KA1,
448 $ RWORK( J2T-M ), KA1 )
451 * apply rotations in 1st set from the right
454 CALL CLARTV( NR, AB( KA1-L, J2 ), INCA,
455 $ AB( KA-L, J2+1 ), INCA, RWORK( J2-M ),
456 $ WORK( J2-M ), KA1 )
459 * apply rotations in 1st set from both sides to diagonal
462 CALL CLAR2V( NR, AB( KA1, J2 ), AB( KA1, J2+1 ),
463 $ AB( KA, J2+1 ), INCA, RWORK( J2-M ),
464 $ WORK( J2-M ), KA1 )
466 CALL CLACGV( NR, WORK( J2-M ), KA1 )
469 * start applying rotations in 1st set from the left
471 DO 110 L = KA - 1, KB - K + 1, -1
472 NRT = ( N-J2+L ) / KA1
474 $ CALL CLARTV( NRT, AB( L, J2+KA1-L ), INCA,
475 $ AB( L+1, J2+KA1-L ), INCA, RWORK( J2-M ),
476 $ WORK( J2-M ), KA1 )
481 * post-multiply X by product of rotations in 1st set
483 DO 120 J = J2, J1, KA1
484 CALL CROT( N-M, X( M+1, J ), 1, X( M+1, J+1 ), 1,
485 $ RWORK( J-M ), CONJG( WORK( J-M ) ) )
491 IF( I2.LE.N .AND. KBT.GT.0 ) THEN
493 * create nonzero element a(i-kbt,i-kbt+ka+1) outside the
494 * band and store it in WORK(i-kbt)
496 WORK( I-KBT ) = -BB( KB1-KBT, I )*RA1
502 J2 = I - K - 1 + MAX( 2, K-I0+1 )*KA1
504 J2 = I - K - 1 + MAX( 1, K-I0+1 )*KA1
507 * finish applying rotations in 2nd set from the left
509 DO 140 L = KB - K, 1, -1
510 NRT = ( N-J2+KA+L ) / KA1
512 $ CALL CLARTV( NRT, AB( L, J2-L+1 ), INCA,
513 $ AB( L+1, J2-L+1 ), INCA, RWORK( J2-KA ),
514 $ WORK( J2-KA ), KA1 )
516 NR = ( N-J2+KA ) / KA1
517 J1 = J2 + ( NR-1 )*KA1
518 DO 150 J = J1, J2, -KA1
519 WORK( J ) = WORK( J-KA )
520 RWORK( J ) = RWORK( J-KA )
522 DO 160 J = J2, J1, KA1
524 * create nonzero element a(j-ka,j+1) outside the band
525 * and store it in WORK(j)
527 WORK( J ) = WORK( J )*AB( 1, J+1 )
528 AB( 1, J+1 ) = RWORK( J )*AB( 1, J+1 )
531 IF( I-K.LT.N-KA .AND. K.LE.KBT )
532 $ WORK( I-K+KA ) = WORK( I-K )
537 J2 = I - K - 1 + MAX( 1, K-I0+1 )*KA1
538 NR = ( N-J2+KA ) / KA1
539 J1 = J2 + ( NR-1 )*KA1
542 * generate rotations in 2nd set to annihilate elements
543 * which have been created outside the band
545 CALL CLARGV( NR, AB( 1, J2 ), INCA, WORK( J2 ), KA1,
548 * apply rotations in 2nd set from the right
551 CALL CLARTV( NR, AB( KA1-L, J2 ), INCA,
552 $ AB( KA-L, J2+1 ), INCA, RWORK( J2 ),
556 * apply rotations in 2nd set from both sides to diagonal
559 CALL CLAR2V( NR, AB( KA1, J2 ), AB( KA1, J2+1 ),
560 $ AB( KA, J2+1 ), INCA, RWORK( J2 ),
563 CALL CLACGV( NR, WORK( J2 ), KA1 )
566 * start applying rotations in 2nd set from the left
568 DO 190 L = KA - 1, KB - K + 1, -1
569 NRT = ( N-J2+L ) / KA1
571 $ CALL CLARTV( NRT, AB( L, J2+KA1-L ), INCA,
572 $ AB( L+1, J2+KA1-L ), INCA, RWORK( J2 ),
578 * post-multiply X by product of rotations in 2nd set
580 DO 200 J = J2, J1, KA1
581 CALL CROT( N-M, X( M+1, J ), 1, X( M+1, J+1 ), 1,
582 $ RWORK( J ), CONJG( WORK( J ) ) )
588 J2 = I - K - 1 + MAX( 1, K-I0+2 )*KA1
590 * finish applying rotations in 1st set from the left
592 DO 220 L = KB - K, 1, -1
593 NRT = ( N-J2+L ) / KA1
595 $ CALL CLARTV( NRT, AB( L, J2+KA1-L ), INCA,
596 $ AB( L+1, J2+KA1-L ), INCA, RWORK( J2-M ),
597 $ WORK( J2-M ), KA1 )
602 DO 240 J = N - 1, J2 + KA, -1
603 RWORK( J-M ) = RWORK( J-KA-M )
604 WORK( J-M ) = WORK( J-KA-M )
610 * Transform A, working with the lower triangle
614 * Form inv(S(i))**H * A * inv(S(i))
616 BII = REAL( BB( 1, I ) )
617 AB( 1, I ) = ( REAL( AB( 1, I ) ) / BII ) / BII
619 AB( J-I+1, I ) = AB( J-I+1, I ) / BII
621 DO 260 J = MAX( 1, I-KA ), I - 1
622 AB( I-J+1, J ) = AB( I-J+1, J ) / BII
624 DO 290 K = I - KBT, I - 1
625 DO 270 J = I - KBT, K
626 AB( K-J+1, J ) = AB( K-J+1, J ) -
627 $ BB( I-J+1, J )*CONJG( AB( I-K+1,
628 $ K ) ) - CONJG( BB( I-K+1, K ) )*
629 $ AB( I-J+1, J ) + REAL( AB( 1, I ) )*
630 $ BB( I-J+1, J )*CONJG( BB( I-K+1,
633 DO 280 J = MAX( 1, I-KA ), I - KBT - 1
634 AB( K-J+1, J ) = AB( K-J+1, J ) -
635 $ CONJG( BB( I-K+1, K ) )*
640 DO 300 K = MAX( J-KA, I-KBT ), I - 1
641 AB( J-K+1, K ) = AB( J-K+1, K ) -
642 $ BB( I-K+1, K )*AB( J-I+1, I )
648 * post-multiply X by inv(S(i))
650 CALL CSSCAL( N-M, ONE / BII, X( M+1, I ), 1 )
652 $ CALL CGERU( N-M, KBT, -CONE, X( M+1, I ), 1,
653 $ BB( KBT+1, I-KBT ), LDBB-1,
654 $ X( M+1, I-KBT ), LDX )
657 * store a(i1,i) in RA1 for use in next loop over K
659 RA1 = AB( I1-I+1, I )
662 * Generate and apply vectors of rotations to chase all the
663 * existing bulges KA positions down toward the bottom of the
669 * Determine the rotations which would annihilate the bulge
670 * which has in theory just been created
672 IF( I-K+KA.LT.N .AND. I-K.GT.1 ) THEN
674 * generate rotation to annihilate a(i-k+ka+1,i)
676 CALL CLARTG( AB( KA1-K, I ), RA1, RWORK( I-K+KA-M ),
677 $ WORK( I-K+KA-M ), RA )
679 * create nonzero element a(i-k+ka+1,i-k) outside the
680 * band and store it in WORK(i-k)
682 T = -BB( K+1, I-K )*RA1
683 WORK( I-K ) = RWORK( I-K+KA-M )*T -
684 $ CONJG( WORK( I-K+KA-M ) )*AB( KA1, I-K )
685 AB( KA1, I-K ) = WORK( I-K+KA-M )*T +
686 $ RWORK( I-K+KA-M )*AB( KA1, I-K )
690 J2 = I - K - 1 + MAX( 1, K-I0+2 )*KA1
691 NR = ( N-J2+KA ) / KA1
692 J1 = J2 + ( NR-1 )*KA1
694 J2T = MAX( J2, I+2*KA-K+1 )
698 NRT = ( N-J2T+KA ) / KA1
699 DO 320 J = J2T, J1, KA1
701 * create nonzero element a(j+1,j-ka) outside the band
702 * and store it in WORK(j-m)
704 WORK( J-M ) = WORK( J-M )*AB( KA1, J-KA+1 )
705 AB( KA1, J-KA+1 ) = RWORK( J-M )*AB( KA1, J-KA+1 )
708 * generate rotations in 1st set to annihilate elements which
709 * have been created outside the band
712 $ CALL CLARGV( NRT, AB( KA1, J2T-KA ), INCA, WORK( J2T-M ),
713 $ KA1, RWORK( J2T-M ), KA1 )
716 * apply rotations in 1st set from the left
719 CALL CLARTV( NR, AB( L+1, J2-L ), INCA,
720 $ AB( L+2, J2-L ), INCA, RWORK( J2-M ),
721 $ WORK( J2-M ), KA1 )
724 * apply rotations in 1st set from both sides to diagonal
727 CALL CLAR2V( NR, AB( 1, J2 ), AB( 1, J2+1 ), AB( 2, J2 ),
728 $ INCA, RWORK( J2-M ), WORK( J2-M ), KA1 )
730 CALL CLACGV( NR, WORK( J2-M ), KA1 )
733 * start applying rotations in 1st set from the right
735 DO 340 L = KA - 1, KB - K + 1, -1
736 NRT = ( N-J2+L ) / KA1
738 $ CALL CLARTV( NRT, AB( KA1-L+1, J2 ), INCA,
739 $ AB( KA1-L, J2+1 ), INCA, RWORK( J2-M ),
740 $ WORK( J2-M ), KA1 )
745 * post-multiply X by product of rotations in 1st set
747 DO 350 J = J2, J1, KA1
748 CALL CROT( N-M, X( M+1, J ), 1, X( M+1, J+1 ), 1,
749 $ RWORK( J-M ), WORK( J-M ) )
755 IF( I2.LE.N .AND. KBT.GT.0 ) THEN
757 * create nonzero element a(i-kbt+ka+1,i-kbt) outside the
758 * band and store it in WORK(i-kbt)
760 WORK( I-KBT ) = -BB( KBT+1, I-KBT )*RA1
766 J2 = I - K - 1 + MAX( 2, K-I0+1 )*KA1
768 J2 = I - K - 1 + MAX( 1, K-I0+1 )*KA1
771 * finish applying rotations in 2nd set from the right
773 DO 370 L = KB - K, 1, -1
774 NRT = ( N-J2+KA+L ) / KA1
776 $ CALL CLARTV( NRT, AB( KA1-L+1, J2-KA ), INCA,
777 $ AB( KA1-L, J2-KA+1 ), INCA,
778 $ RWORK( J2-KA ), WORK( J2-KA ), KA1 )
780 NR = ( N-J2+KA ) / KA1
781 J1 = J2 + ( NR-1 )*KA1
782 DO 380 J = J1, J2, -KA1
783 WORK( J ) = WORK( J-KA )
784 RWORK( J ) = RWORK( J-KA )
786 DO 390 J = J2, J1, KA1
788 * create nonzero element a(j+1,j-ka) outside the band
789 * and store it in WORK(j)
791 WORK( J ) = WORK( J )*AB( KA1, J-KA+1 )
792 AB( KA1, J-KA+1 ) = RWORK( J )*AB( KA1, J-KA+1 )
795 IF( I-K.LT.N-KA .AND. K.LE.KBT )
796 $ WORK( I-K+KA ) = WORK( I-K )
801 J2 = I - K - 1 + MAX( 1, K-I0+1 )*KA1
802 NR = ( N-J2+KA ) / KA1
803 J1 = J2 + ( NR-1 )*KA1
806 * generate rotations in 2nd set to annihilate elements
807 * which have been created outside the band
809 CALL CLARGV( NR, AB( KA1, J2-KA ), INCA, WORK( J2 ), KA1,
812 * apply rotations in 2nd set from the left
815 CALL CLARTV( NR, AB( L+1, J2-L ), INCA,
816 $ AB( L+2, J2-L ), INCA, RWORK( J2 ),
820 * apply rotations in 2nd set from both sides to diagonal
823 CALL CLAR2V( NR, AB( 1, J2 ), AB( 1, J2+1 ), AB( 2, J2 ),
824 $ INCA, RWORK( J2 ), WORK( J2 ), KA1 )
826 CALL CLACGV( NR, WORK( J2 ), KA1 )
829 * start applying rotations in 2nd set from the right
831 DO 420 L = KA - 1, KB - K + 1, -1
832 NRT = ( N-J2+L ) / KA1
834 $ CALL CLARTV( NRT, AB( KA1-L+1, J2 ), INCA,
835 $ AB( KA1-L, J2+1 ), INCA, RWORK( J2 ),
841 * post-multiply X by product of rotations in 2nd set
843 DO 430 J = J2, J1, KA1
844 CALL CROT( N-M, X( M+1, J ), 1, X( M+1, J+1 ), 1,
845 $ RWORK( J ), WORK( J ) )
851 J2 = I - K - 1 + MAX( 1, K-I0+2 )*KA1
853 * finish applying rotations in 1st set from the right
855 DO 450 L = KB - K, 1, -1
856 NRT = ( N-J2+L ) / KA1
858 $ CALL CLARTV( NRT, AB( KA1-L+1, J2 ), INCA,
859 $ AB( KA1-L, J2+1 ), INCA, RWORK( J2-M ),
860 $ WORK( J2-M ), KA1 )
865 DO 470 J = N - 1, J2 + KA, -1
866 RWORK( J-M ) = RWORK( J-KA-M )
867 WORK( J-M ) = WORK( J-KA-M )
877 * **************************** Phase 2 *****************************
879 * The logical structure of this phase is:
883 * use S(i) to update A and create a new bulge
884 * apply rotations to push all bulges KA positions upward
887 * DO I = M - KA - 1, 2, -1
888 * apply rotations to push all bulges KA positions upward
891 * To avoid duplicating code, the two loops are merged.
916 IF( I.LT.M-KBT ) THEN
924 * Transform A, working with the upper triangle
928 * Form inv(S(i))**H * A * inv(S(i))
930 BII = REAL( BB( KB1, I ) )
931 AB( KA1, I ) = ( REAL( AB( KA1, I ) ) / BII ) / BII
933 AB( J-I+KA1, I ) = AB( J-I+KA1, I ) / BII
935 DO 510 J = I + 1, MIN( N, I+KA )
936 AB( I-J+KA1, J ) = AB( I-J+KA1, J ) / BII
938 DO 540 K = I + 1, I + KBT
939 DO 520 J = K, I + KBT
940 AB( K-J+KA1, J ) = AB( K-J+KA1, J ) -
942 $ CONJG( AB( I-K+KA1, K ) ) -
943 $ CONJG( BB( I-K+KB1, K ) )*
945 $ REAL( AB( KA1, I ) )*
947 $ CONJG( BB( I-K+KB1, K ) )
949 DO 530 J = I + KBT + 1, MIN( N, I+KA )
950 AB( K-J+KA1, J ) = AB( K-J+KA1, J ) -
951 $ CONJG( BB( I-K+KB1, K ) )*
956 DO 550 K = I + 1, MIN( J+KA, I+KBT )
957 AB( J-K+KA1, K ) = AB( J-K+KA1, K ) -
958 $ BB( I-K+KB1, K )*AB( J-I+KA1, I )
964 * post-multiply X by inv(S(i))
966 CALL CSSCAL( NX, ONE / BII, X( 1, I ), 1 )
968 $ CALL CGERU( NX, KBT, -CONE, X( 1, I ), 1,
969 $ BB( KB, I+1 ), LDBB-1, X( 1, I+1 ), LDX )
972 * store a(i1,i) in RA1 for use in next loop over K
974 RA1 = AB( I1-I+KA1, I )
977 * Generate and apply vectors of rotations to chase all the
978 * existing bulges KA positions up toward the top of the band
983 * Determine the rotations which would annihilate the bulge
984 * which has in theory just been created
986 IF( I+K-KA1.GT.0 .AND. I+K.LT.M ) THEN
988 * generate rotation to annihilate a(i+k-ka-1,i)
990 CALL CLARTG( AB( K+1, I ), RA1, RWORK( I+K-KA ),
991 $ WORK( I+K-KA ), RA )
993 * create nonzero element a(i+k-ka-1,i+k) outside the
994 * band and store it in WORK(m-kb+i+k)
996 T = -BB( KB1-K, I+K )*RA1
997 WORK( M-KB+I+K ) = RWORK( I+K-KA )*T -
998 $ CONJG( WORK( I+K-KA ) )*
1000 AB( 1, I+K ) = WORK( I+K-KA )*T +
1001 $ RWORK( I+K-KA )*AB( 1, I+K )
1005 J2 = I + K + 1 - MAX( 1, K+I0-M+1 )*KA1
1006 NR = ( J2+KA-1 ) / KA1
1007 J1 = J2 - ( NR-1 )*KA1
1009 J2T = MIN( J2, I-2*KA+K-1 )
1013 NRT = ( J2T+KA-1 ) / KA1
1014 DO 570 J = J1, J2T, KA1
1016 * create nonzero element a(j-1,j+ka) outside the band
1017 * and store it in WORK(j)
1019 WORK( J ) = WORK( J )*AB( 1, J+KA-1 )
1020 AB( 1, J+KA-1 ) = RWORK( J )*AB( 1, J+KA-1 )
1023 * generate rotations in 1st set to annihilate elements which
1024 * have been created outside the band
1027 $ CALL CLARGV( NRT, AB( 1, J1+KA ), INCA, WORK( J1 ), KA1,
1028 $ RWORK( J1 ), KA1 )
1031 * apply rotations in 1st set from the left
1033 DO 580 L = 1, KA - 1
1034 CALL CLARTV( NR, AB( KA1-L, J1+L ), INCA,
1035 $ AB( KA-L, J1+L ), INCA, RWORK( J1 ),
1039 * apply rotations in 1st set from both sides to diagonal
1042 CALL CLAR2V( NR, AB( KA1, J1 ), AB( KA1, J1-1 ),
1043 $ AB( KA, J1 ), INCA, RWORK( J1 ), WORK( J1 ),
1046 CALL CLACGV( NR, WORK( J1 ), KA1 )
1049 * start applying rotations in 1st set from the right
1051 DO 590 L = KA - 1, KB - K + 1, -1
1052 NRT = ( J2+L-1 ) / KA1
1053 J1T = J2 - ( NRT-1 )*KA1
1055 $ CALL CLARTV( NRT, AB( L, J1T ), INCA,
1056 $ AB( L+1, J1T-1 ), INCA, RWORK( J1T ),
1057 $ WORK( J1T ), KA1 )
1062 * post-multiply X by product of rotations in 1st set
1064 DO 600 J = J1, J2, KA1
1065 CALL CROT( NX, X( 1, J ), 1, X( 1, J-1 ), 1,
1066 $ RWORK( J ), WORK( J ) )
1072 IF( I2.GT.0 .AND. KBT.GT.0 ) THEN
1074 * create nonzero element a(i+kbt-ka-1,i+kbt) outside the
1075 * band and store it in WORK(m-kb+i+kbt)
1077 WORK( M-KB+I+KBT ) = -BB( KB1-KBT, I+KBT )*RA1
1081 DO 650 K = KB, 1, -1
1083 J2 = I + K + 1 - MAX( 2, K+I0-M )*KA1
1085 J2 = I + K + 1 - MAX( 1, K+I0-M )*KA1
1088 * finish applying rotations in 2nd set from the right
1090 DO 620 L = KB - K, 1, -1
1091 NRT = ( J2+KA+L-1 ) / KA1
1092 J1T = J2 - ( NRT-1 )*KA1
1094 $ CALL CLARTV( NRT, AB( L, J1T+KA ), INCA,
1095 $ AB( L+1, J1T+KA-1 ), INCA,
1096 $ RWORK( M-KB+J1T+KA ),
1097 $ WORK( M-KB+J1T+KA ), KA1 )
1099 NR = ( J2+KA-1 ) / KA1
1100 J1 = J2 - ( NR-1 )*KA1
1101 DO 630 J = J1, J2, KA1
1102 WORK( M-KB+J ) = WORK( M-KB+J+KA )
1103 RWORK( M-KB+J ) = RWORK( M-KB+J+KA )
1105 DO 640 J = J1, J2, KA1
1107 * create nonzero element a(j-1,j+ka) outside the band
1108 * and store it in WORK(m-kb+j)
1110 WORK( M-KB+J ) = WORK( M-KB+J )*AB( 1, J+KA-1 )
1111 AB( 1, J+KA-1 ) = RWORK( M-KB+J )*AB( 1, J+KA-1 )
1114 IF( I+K.GT.KA1 .AND. K.LE.KBT )
1115 $ WORK( M-KB+I+K-KA ) = WORK( M-KB+I+K )
1119 DO 690 K = KB, 1, -1
1120 J2 = I + K + 1 - MAX( 1, K+I0-M )*KA1
1121 NR = ( J2+KA-1 ) / KA1
1122 J1 = J2 - ( NR-1 )*KA1
1125 * generate rotations in 2nd set to annihilate elements
1126 * which have been created outside the band
1128 CALL CLARGV( NR, AB( 1, J1+KA ), INCA, WORK( M-KB+J1 ),
1129 $ KA1, RWORK( M-KB+J1 ), KA1 )
1131 * apply rotations in 2nd set from the left
1133 DO 660 L = 1, KA - 1
1134 CALL CLARTV( NR, AB( KA1-L, J1+L ), INCA,
1135 $ AB( KA-L, J1+L ), INCA, RWORK( M-KB+J1 ),
1136 $ WORK( M-KB+J1 ), KA1 )
1139 * apply rotations in 2nd set from both sides to diagonal
1142 CALL CLAR2V( NR, AB( KA1, J1 ), AB( KA1, J1-1 ),
1143 $ AB( KA, J1 ), INCA, RWORK( M-KB+J1 ),
1144 $ WORK( M-KB+J1 ), KA1 )
1146 CALL CLACGV( NR, WORK( M-KB+J1 ), KA1 )
1149 * start applying rotations in 2nd set from the right
1151 DO 670 L = KA - 1, KB - K + 1, -1
1152 NRT = ( J2+L-1 ) / KA1
1153 J1T = J2 - ( NRT-1 )*KA1
1155 $ CALL CLARTV( NRT, AB( L, J1T ), INCA,
1156 $ AB( L+1, J1T-1 ), INCA,
1157 $ RWORK( M-KB+J1T ), WORK( M-KB+J1T ),
1163 * post-multiply X by product of rotations in 2nd set
1165 DO 680 J = J1, J2, KA1
1166 CALL CROT( NX, X( 1, J ), 1, X( 1, J-1 ), 1,
1167 $ RWORK( M-KB+J ), WORK( M-KB+J ) )
1172 DO 710 K = 1, KB - 1
1173 J2 = I + K + 1 - MAX( 1, K+I0-M+1 )*KA1
1175 * finish applying rotations in 1st set from the right
1177 DO 700 L = KB - K, 1, -1
1178 NRT = ( J2+L-1 ) / KA1
1179 J1T = J2 - ( NRT-1 )*KA1
1181 $ CALL CLARTV( NRT, AB( L, J1T ), INCA,
1182 $ AB( L+1, J1T-1 ), INCA, RWORK( J1T ),
1183 $ WORK( J1T ), KA1 )
1188 DO 720 J = 2, I2 - KA
1189 RWORK( J ) = RWORK( J+KA )
1190 WORK( J ) = WORK( J+KA )
1196 * Transform A, working with the lower triangle
1200 * Form inv(S(i))**H * A * inv(S(i))
1202 BII = REAL( BB( 1, I ) )
1203 AB( 1, I ) = ( REAL( AB( 1, I ) ) / BII ) / BII
1204 DO 730 J = I1, I - 1
1205 AB( I-J+1, J ) = AB( I-J+1, J ) / BII
1207 DO 740 J = I + 1, MIN( N, I+KA )
1208 AB( J-I+1, I ) = AB( J-I+1, I ) / BII
1210 DO 770 K = I + 1, I + KBT
1211 DO 750 J = K, I + KBT
1212 AB( J-K+1, K ) = AB( J-K+1, K ) -
1213 $ BB( J-I+1, I )*CONJG( AB( K-I+1,
1214 $ I ) ) - CONJG( BB( K-I+1, I ) )*
1215 $ AB( J-I+1, I ) + REAL( AB( 1, I ) )*
1216 $ BB( J-I+1, I )*CONJG( BB( K-I+1,
1219 DO 760 J = I + KBT + 1, MIN( N, I+KA )
1220 AB( J-K+1, K ) = AB( J-K+1, K ) -
1221 $ CONJG( BB( K-I+1, I ) )*
1226 DO 780 K = I + 1, MIN( J+KA, I+KBT )
1227 AB( K-J+1, J ) = AB( K-J+1, J ) -
1228 $ BB( K-I+1, I )*AB( I-J+1, J )
1234 * post-multiply X by inv(S(i))
1236 CALL CSSCAL( NX, ONE / BII, X( 1, I ), 1 )
1238 $ CALL CGERC( NX, KBT, -CONE, X( 1, I ), 1, BB( 2, I ),
1239 $ 1, X( 1, I+1 ), LDX )
1242 * store a(i,i1) in RA1 for use in next loop over K
1244 RA1 = AB( I-I1+1, I1 )
1247 * Generate and apply vectors of rotations to chase all the
1248 * existing bulges KA positions up toward the top of the band
1250 DO 840 K = 1, KB - 1
1253 * Determine the rotations which would annihilate the bulge
1254 * which has in theory just been created
1256 IF( I+K-KA1.GT.0 .AND. I+K.LT.M ) THEN
1258 * generate rotation to annihilate a(i,i+k-ka-1)
1260 CALL CLARTG( AB( KA1-K, I+K-KA ), RA1,
1261 $ RWORK( I+K-KA ), WORK( I+K-KA ), RA )
1263 * create nonzero element a(i+k,i+k-ka-1) outside the
1264 * band and store it in WORK(m-kb+i+k)
1266 T = -BB( K+1, I )*RA1
1267 WORK( M-KB+I+K ) = RWORK( I+K-KA )*T -
1268 $ CONJG( WORK( I+K-KA ) )*
1270 AB( KA1, I+K-KA ) = WORK( I+K-KA )*T +
1271 $ RWORK( I+K-KA )*AB( KA1, I+K-KA )
1275 J2 = I + K + 1 - MAX( 1, K+I0-M+1 )*KA1
1276 NR = ( J2+KA-1 ) / KA1
1277 J1 = J2 - ( NR-1 )*KA1
1279 J2T = MIN( J2, I-2*KA+K-1 )
1283 NRT = ( J2T+KA-1 ) / KA1
1284 DO 800 J = J1, J2T, KA1
1286 * create nonzero element a(j+ka,j-1) outside the band
1287 * and store it in WORK(j)
1289 WORK( J ) = WORK( J )*AB( KA1, J-1 )
1290 AB( KA1, J-1 ) = RWORK( J )*AB( KA1, J-1 )
1293 * generate rotations in 1st set to annihilate elements which
1294 * have been created outside the band
1297 $ CALL CLARGV( NRT, AB( KA1, J1 ), INCA, WORK( J1 ), KA1,
1298 $ RWORK( J1 ), KA1 )
1301 * apply rotations in 1st set from the right
1303 DO 810 L = 1, KA - 1
1304 CALL CLARTV( NR, AB( L+1, J1 ), INCA, AB( L+2, J1-1 ),
1305 $ INCA, RWORK( J1 ), WORK( J1 ), KA1 )
1308 * apply rotations in 1st set from both sides to diagonal
1311 CALL CLAR2V( NR, AB( 1, J1 ), AB( 1, J1-1 ),
1312 $ AB( 2, J1-1 ), INCA, RWORK( J1 ),
1315 CALL CLACGV( NR, WORK( J1 ), KA1 )
1318 * start applying rotations in 1st set from the left
1320 DO 820 L = KA - 1, KB - K + 1, -1
1321 NRT = ( J2+L-1 ) / KA1
1322 J1T = J2 - ( NRT-1 )*KA1
1324 $ CALL CLARTV( NRT, AB( KA1-L+1, J1T-KA1+L ), INCA,
1325 $ AB( KA1-L, J1T-KA1+L ), INCA,
1326 $ RWORK( J1T ), WORK( J1T ), KA1 )
1331 * post-multiply X by product of rotations in 1st set
1333 DO 830 J = J1, J2, KA1
1334 CALL CROT( NX, X( 1, J ), 1, X( 1, J-1 ), 1,
1335 $ RWORK( J ), CONJG( WORK( J ) ) )
1341 IF( I2.GT.0 .AND. KBT.GT.0 ) THEN
1343 * create nonzero element a(i+kbt,i+kbt-ka-1) outside the
1344 * band and store it in WORK(m-kb+i+kbt)
1346 WORK( M-KB+I+KBT ) = -BB( KBT+1, I )*RA1
1350 DO 880 K = KB, 1, -1
1352 J2 = I + K + 1 - MAX( 2, K+I0-M )*KA1
1354 J2 = I + K + 1 - MAX( 1, K+I0-M )*KA1
1357 * finish applying rotations in 2nd set from the left
1359 DO 850 L = KB - K, 1, -1
1360 NRT = ( J2+KA+L-1 ) / KA1
1361 J1T = J2 - ( NRT-1 )*KA1
1363 $ CALL CLARTV( NRT, AB( KA1-L+1, J1T+L-1 ), INCA,
1364 $ AB( KA1-L, J1T+L-1 ), INCA,
1365 $ RWORK( M-KB+J1T+KA ),
1366 $ WORK( M-KB+J1T+KA ), KA1 )
1368 NR = ( J2+KA-1 ) / KA1
1369 J1 = J2 - ( NR-1 )*KA1
1370 DO 860 J = J1, J2, KA1
1371 WORK( M-KB+J ) = WORK( M-KB+J+KA )
1372 RWORK( M-KB+J ) = RWORK( M-KB+J+KA )
1374 DO 870 J = J1, J2, KA1
1376 * create nonzero element a(j+ka,j-1) outside the band
1377 * and store it in WORK(m-kb+j)
1379 WORK( M-KB+J ) = WORK( M-KB+J )*AB( KA1, J-1 )
1380 AB( KA1, J-1 ) = RWORK( M-KB+J )*AB( KA1, J-1 )
1383 IF( I+K.GT.KA1 .AND. K.LE.KBT )
1384 $ WORK( M-KB+I+K-KA ) = WORK( M-KB+I+K )
1388 DO 920 K = KB, 1, -1
1389 J2 = I + K + 1 - MAX( 1, K+I0-M )*KA1
1390 NR = ( J2+KA-1 ) / KA1
1391 J1 = J2 - ( NR-1 )*KA1
1394 * generate rotations in 2nd set to annihilate elements
1395 * which have been created outside the band
1397 CALL CLARGV( NR, AB( KA1, J1 ), INCA, WORK( M-KB+J1 ),
1398 $ KA1, RWORK( M-KB+J1 ), KA1 )
1400 * apply rotations in 2nd set from the right
1402 DO 890 L = 1, KA - 1
1403 CALL CLARTV( NR, AB( L+1, J1 ), INCA, AB( L+2, J1-1 ),
1404 $ INCA, RWORK( M-KB+J1 ), WORK( M-KB+J1 ),
1408 * apply rotations in 2nd set from both sides to diagonal
1411 CALL CLAR2V( NR, AB( 1, J1 ), AB( 1, J1-1 ),
1412 $ AB( 2, J1-1 ), INCA, RWORK( M-KB+J1 ),
1413 $ WORK( M-KB+J1 ), KA1 )
1415 CALL CLACGV( NR, WORK( M-KB+J1 ), KA1 )
1418 * start applying rotations in 2nd set from the left
1420 DO 900 L = KA - 1, KB - K + 1, -1
1421 NRT = ( J2+L-1 ) / KA1
1422 J1T = J2 - ( NRT-1 )*KA1
1424 $ CALL CLARTV( NRT, AB( KA1-L+1, J1T-KA1+L ), INCA,
1425 $ AB( KA1-L, J1T-KA1+L ), INCA,
1426 $ RWORK( M-KB+J1T ), WORK( M-KB+J1T ),
1432 * post-multiply X by product of rotations in 2nd set
1434 DO 910 J = J1, J2, KA1
1435 CALL CROT( NX, X( 1, J ), 1, X( 1, J-1 ), 1,
1436 $ RWORK( M-KB+J ), CONJG( WORK( M-KB+J ) ) )
1441 DO 940 K = 1, KB - 1
1442 J2 = I + K + 1 - MAX( 1, K+I0-M+1 )*KA1
1444 * finish applying rotations in 1st set from the left
1446 DO 930 L = KB - K, 1, -1
1447 NRT = ( J2+L-1 ) / KA1
1448 J1T = J2 - ( NRT-1 )*KA1
1450 $ CALL CLARTV( NRT, AB( KA1-L+1, J1T-KA1+L ), INCA,
1451 $ AB( KA1-L, J1T-KA1+L ), INCA,
1452 $ RWORK( J1T ), WORK( J1T ), KA1 )
1457 DO 950 J = 2, I2 - KA
1458 RWORK( J ) = RWORK( J+KA )
1459 WORK( J ) = WORK( J+KA )