LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
subroutine ctrevc3 ( character  SIDE,
character  HOWMNY,
logical, dimension( * )  SELECT,
integer  N,
complex, dimension( ldt, * )  T,
integer  LDT,
complex, dimension( ldvl, * )  VL,
integer  LDVL,
complex, dimension( ldvr, * )  VR,
integer  LDVR,
integer  MM,
integer  M,
complex, dimension( * )  WORK,
integer  LWORK,
real, dimension( * )  RWORK,
integer  LRWORK,
integer  INFO 
)

CTREVC3

Download CTREVC3 + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CTREVC3 computes some or all of the right and/or left eigenvectors of
 a complex upper triangular matrix T.
 Matrices of this type are produced by the Schur factorization of
 a complex general matrix:  A = Q*T*Q**H, as computed by CHSEQR.

 The right eigenvector x and the left eigenvector y of T corresponding
 to an eigenvalue w are defined by:

              T*x = w*x,     (y**H)*T = w*(y**H)

 where y**H denotes the conjugate transpose of the vector y.
 The eigenvalues are not input to this routine, but are read directly
 from the diagonal of T.

 This routine returns the matrices X and/or Y of right and left
 eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an
 input matrix. If Q is the unitary factor that reduces a matrix A to
 Schur form T, then Q*X and Q*Y are the matrices of right and left
 eigenvectors of A.

 This uses a Level 3 BLAS version of the back transformation.
Parameters
[in]SIDE
          SIDE is CHARACTER*1
          = 'R':  compute right eigenvectors only;
          = 'L':  compute left eigenvectors only;
          = 'B':  compute both right and left eigenvectors.
[in]HOWMNY
          HOWMNY is CHARACTER*1
          = 'A':  compute all right and/or left eigenvectors;
          = 'B':  compute all right and/or left eigenvectors,
                  backtransformed using the matrices supplied in
                  VR and/or VL;
          = 'S':  compute selected right and/or left eigenvectors,
                  as indicated by the logical array SELECT.
[in]SELECT
          SELECT is LOGICAL array, dimension (N)
          If HOWMNY = 'S', SELECT specifies the eigenvectors to be
          computed.
          The eigenvector corresponding to the j-th eigenvalue is
          computed if SELECT(j) = .TRUE..
          Not referenced if HOWMNY = 'A' or 'B'.
[in]N
          N is INTEGER
          The order of the matrix T. N >= 0.
[in,out]T
          T is COMPLEX array, dimension (LDT,N)
          The upper triangular matrix T.  T is modified, but restored
          on exit.
[in]LDT
          LDT is INTEGER
          The leading dimension of the array T. LDT >= max(1,N).
[in,out]VL
          VL is COMPLEX array, dimension (LDVL,MM)
          On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
          contain an N-by-N matrix Q (usually the unitary matrix Q of
          Schur vectors returned by CHSEQR).
          On exit, if SIDE = 'L' or 'B', VL contains:
          if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
          if HOWMNY = 'B', the matrix Q*Y;
          if HOWMNY = 'S', the left eigenvectors of T specified by
                           SELECT, stored consecutively in the columns
                           of VL, in the same order as their
                           eigenvalues.
          Not referenced if SIDE = 'R'.
[in]LDVL
          LDVL is INTEGER
          The leading dimension of the array VL.
          LDVL >= 1, and if SIDE = 'L' or 'B', LDVL >= N.
[in,out]VR
          VR is COMPLEX array, dimension (LDVR,MM)
          On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
          contain an N-by-N matrix Q (usually the unitary matrix Q of
          Schur vectors returned by CHSEQR).
          On exit, if SIDE = 'R' or 'B', VR contains:
          if HOWMNY = 'A', the matrix X of right eigenvectors of T;
          if HOWMNY = 'B', the matrix Q*X;
          if HOWMNY = 'S', the right eigenvectors of T specified by
                           SELECT, stored consecutively in the columns
                           of VR, in the same order as their
                           eigenvalues.
          Not referenced if SIDE = 'L'.
[in]LDVR
          LDVR is INTEGER
          The leading dimension of the array VR.
          LDVR >= 1, and if SIDE = 'R' or 'B', LDVR >= N.
[in]MM
          MM is INTEGER
          The number of columns in the arrays VL and/or VR. MM >= M.
[out]M
          M is INTEGER
          The number of columns in the arrays VL and/or VR actually
          used to store the eigenvectors.
          If HOWMNY = 'A' or 'B', M is set to N.
          Each selected eigenvector occupies one column.
[out]WORK
          WORK is COMPLEX array, dimension (MAX(1,LWORK))
[in]LWORK
          LWORK is INTEGER
          The dimension of array WORK. LWORK >= max(1,2*N).
          For optimum performance, LWORK >= N + 2*N*NB, where NB is
          the optimal blocksize.

          If LWORK = -1, then a workspace query is assumed; the routine
          only calculates the optimal size of the WORK array, returns
          this value as the first entry of the WORK array, and no error
          message related to LWORK is issued by XERBLA.
[out]RWORK
          RWORK is REAL array, dimension (LRWORK)
[in]LRWORK
          LRWORK is INTEGER
          The dimension of array RWORK. LRWORK >= max(1,N).

          If LRWORK = -1, then a workspace query is assumed; the routine
          only calculates the optimal size of the RWORK array, returns
          this value as the first entry of the RWORK array, and no error
          message related to LRWORK is issued by XERBLA.
[out]INFO
          INFO is INTEGER
          = 0:  successful exit
          < 0:  if INFO = -i, the i-th argument had an illegal value
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Date
November 2011
Further Details:
  The algorithm used in this program is basically backward (forward)
  substitution, with scaling to make the the code robust against
  possible overflow.

  Each eigenvector is normalized so that the element of largest
  magnitude has magnitude 1; here the magnitude of a complex number
  (x,y) is taken to be |x| + |y|.

Definition at line 248 of file ctrevc3.f.

248  IMPLICIT NONE
249 *
250 * -- LAPACK computational routine (version 3.4.0) --
251 * -- LAPACK is a software package provided by Univ. of Tennessee, --
252 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
253 * November 2011
254 *
255 * .. Scalar Arguments ..
256  CHARACTER howmny, side
257  INTEGER info, ldt, ldvl, ldvr, lwork, lrwork, m, mm, n
258 * ..
259 * .. Array Arguments ..
260  LOGICAL select( * )
261  REAL rwork( * )
262  COMPLEX t( ldt, * ), vl( ldvl, * ), vr( ldvr, * ),
263  $ work( * )
264 * ..
265 *
266 * =====================================================================
267 *
268 * .. Parameters ..
269  REAL zero, one
270  parameter ( zero = 0.0e+0, one = 1.0e+0 )
271  COMPLEX czero, cone
272  parameter ( czero = ( 0.0e+0, 0.0e+0 ),
273  $ cone = ( 1.0e+0, 0.0e+0 ) )
274  INTEGER nbmin, nbmax
275  parameter ( nbmin = 8, nbmax = 128 )
276 * ..
277 * .. Local Scalars ..
278  LOGICAL allv, bothv, leftv, lquery, over, rightv, somev
279  INTEGER i, ii, is, j, k, ki, iv, maxwrk, nb
280  REAL ovfl, remax, scale, smin, smlnum, ulp, unfl
281  COMPLEX cdum
282 * ..
283 * .. External Functions ..
284  LOGICAL lsame
285  INTEGER ilaenv, icamax
286  REAL slamch, scasum
287  EXTERNAL lsame, ilaenv, icamax, slamch, scasum
288 * ..
289 * .. External Subroutines ..
290  EXTERNAL xerbla, ccopy, csscal, cgemv, clatrs
291 * ..
292 * .. Intrinsic Functions ..
293  INTRINSIC abs, REAL, cmplx, conjg, aimag, max
294 * ..
295 * .. Statement Functions ..
296  REAL cabs1
297 * ..
298 * .. Statement Function definitions ..
299  cabs1( cdum ) = abs( REAL( CDUM ) ) + abs( aimag( cdum ) )
300 * ..
301 * .. Executable Statements ..
302 *
303 * Decode and test the input parameters
304 *
305  bothv = lsame( side, 'B' )
306  rightv = lsame( side, 'R' ) .OR. bothv
307  leftv = lsame( side, 'L' ) .OR. bothv
308 *
309  allv = lsame( howmny, 'A' )
310  over = lsame( howmny, 'B' )
311  somev = lsame( howmny, 'S' )
312 *
313 * Set M to the number of columns required to store the selected
314 * eigenvectors.
315 *
316  IF( somev ) THEN
317  m = 0
318  DO 10 j = 1, n
319  IF( SELECT( j ) )
320  $ m = m + 1
321  10 CONTINUE
322  ELSE
323  m = n
324  END IF
325 *
326  info = 0
327  nb = ilaenv( 1, 'CTREVC', side // howmny, n, -1, -1, -1 )
328  maxwrk = n + 2*n*nb
329  work(1) = maxwrk
330  rwork(1) = n
331  lquery = ( lwork.EQ.-1 .OR. lrwork.EQ.-1 )
332  IF( .NOT.rightv .AND. .NOT.leftv ) THEN
333  info = -1
334  ELSE IF( .NOT.allv .AND. .NOT.over .AND. .NOT.somev ) THEN
335  info = -2
336  ELSE IF( n.LT.0 ) THEN
337  info = -4
338  ELSE IF( ldt.LT.max( 1, n ) ) THEN
339  info = -6
340  ELSE IF( ldvl.LT.1 .OR. ( leftv .AND. ldvl.LT.n ) ) THEN
341  info = -8
342  ELSE IF( ldvr.LT.1 .OR. ( rightv .AND. ldvr.LT.n ) ) THEN
343  info = -10
344  ELSE IF( mm.LT.m ) THEN
345  info = -11
346  ELSE IF( lwork.LT.max( 1, 2*n ) .AND. .NOT.lquery ) THEN
347  info = -14
348  ELSE IF ( lrwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
349  info = -16
350  END IF
351  IF( info.NE.0 ) THEN
352  CALL xerbla( 'CTREVC3', -info )
353  RETURN
354  ELSE IF( lquery ) THEN
355  RETURN
356  END IF
357 *
358 * Quick return if possible.
359 *
360  IF( n.EQ.0 )
361  $ RETURN
362 *
363 * Use blocked version of back-transformation if sufficient workspace.
364 * Zero-out the workspace to avoid potential NaN propagation.
365 *
366  IF( over .AND. lwork .GE. n + 2*n*nbmin ) THEN
367  nb = (lwork - n) / (2*n)
368  nb = min( nb, nbmax )
369  CALL claset( 'F', n, 1+2*nb, czero, czero, work, n )
370  ELSE
371  nb = 1
372  END IF
373 *
374 * Set the constants to control overflow.
375 *
376  unfl = slamch( 'Safe minimum' )
377  ovfl = one / unfl
378  CALL slabad( unfl, ovfl )
379  ulp = slamch( 'Precision' )
380  smlnum = unfl*( n / ulp )
381 *
382 * Store the diagonal elements of T in working array WORK.
383 *
384  DO 20 i = 1, n
385  work( i ) = t( i, i )
386  20 CONTINUE
387 *
388 * Compute 1-norm of each column of strictly upper triangular
389 * part of T to control overflow in triangular solver.
390 *
391  rwork( 1 ) = zero
392  DO 30 j = 2, n
393  rwork( j ) = scasum( j-1, t( 1, j ), 1 )
394  30 CONTINUE
395 *
396  IF( rightv ) THEN
397 *
398 * ============================================================
399 * Compute right eigenvectors.
400 *
401 * IV is index of column in current block.
402 * Non-blocked version always uses IV=NB=1;
403 * blocked version starts with IV=NB, goes down to 1.
404 * (Note the "0-th" column is used to store the original diagonal.)
405  iv = nb
406  is = m
407  DO 80 ki = n, 1, -1
408  IF( somev ) THEN
409  IF( .NOT.SELECT( ki ) )
410  $ GO TO 80
411  END IF
412  smin = max( ulp*( cabs1( t( ki, ki ) ) ), smlnum )
413 *
414 * --------------------------------------------------------
415 * Complex right eigenvector
416 *
417  work( ki + iv*n ) = cone
418 *
419 * Form right-hand side.
420 *
421  DO 40 k = 1, ki - 1
422  work( k + iv*n ) = -t( k, ki )
423  40 CONTINUE
424 *
425 * Solve upper triangular system:
426 * [ T(1:KI-1,1:KI-1) - T(KI,KI) ]*X = SCALE*WORK.
427 *
428  DO 50 k = 1, ki - 1
429  t( k, k ) = t( k, k ) - t( ki, ki )
430  IF( cabs1( t( k, k ) ).LT.smin )
431  $ t( k, k ) = smin
432  50 CONTINUE
433 *
434  IF( ki.GT.1 ) THEN
435  CALL clatrs( 'Upper', 'No transpose', 'Non-unit', 'Y',
436  $ ki-1, t, ldt, work( 1 + iv*n ), scale,
437  $ rwork, info )
438  work( ki + iv*n ) = scale
439  END IF
440 *
441 * Copy the vector x or Q*x to VR and normalize.
442 *
443  IF( .NOT.over ) THEN
444 * ------------------------------
445 * no back-transform: copy x to VR and normalize.
446  CALL ccopy( ki, work( 1 + iv*n ), 1, vr( 1, is ), 1 )
447 *
448  ii = icamax( ki, vr( 1, is ), 1 )
449  remax = one / cabs1( vr( ii, is ) )
450  CALL csscal( ki, remax, vr( 1, is ), 1 )
451 *
452  DO 60 k = ki + 1, n
453  vr( k, is ) = czero
454  60 CONTINUE
455 *
456  ELSE IF( nb.EQ.1 ) THEN
457 * ------------------------------
458 * version 1: back-transform each vector with GEMV, Q*x.
459  IF( ki.GT.1 )
460  $ CALL cgemv( 'N', n, ki-1, cone, vr, ldvr,
461  $ work( 1 + iv*n ), 1, cmplx( scale ),
462  $ vr( 1, ki ), 1 )
463 *
464  ii = icamax( n, vr( 1, ki ), 1 )
465  remax = one / cabs1( vr( ii, ki ) )
466  CALL csscal( n, remax, vr( 1, ki ), 1 )
467 *
468  ELSE
469 * ------------------------------
470 * version 2: back-transform block of vectors with GEMM
471 * zero out below vector
472  DO k = ki + 1, n
473  work( k + iv*n ) = czero
474  END DO
475 *
476 * Columns IV:NB of work are valid vectors.
477 * When the number of vectors stored reaches NB,
478 * or if this was last vector, do the GEMM
479  IF( (iv.EQ.1) .OR. (ki.EQ.1) ) THEN
480  CALL cgemm( 'N', 'N', n, nb-iv+1, ki+nb-iv, cone,
481  $ vr, ldvr,
482  $ work( 1 + (iv)*n ), n,
483  $ czero,
484  $ work( 1 + (nb+iv)*n ), n )
485 * normalize vectors
486  DO k = iv, nb
487  ii = icamax( n, work( 1 + (nb+k)*n ), 1 )
488  remax = one / cabs1( work( ii + (nb+k)*n ) )
489  CALL csscal( n, remax, work( 1 + (nb+k)*n ), 1 )
490  END DO
491  CALL clacpy( 'F', n, nb-iv+1,
492  $ work( 1 + (nb+iv)*n ), n,
493  $ vr( 1, ki ), ldvr )
494  iv = nb
495  ELSE
496  iv = iv - 1
497  END IF
498  END IF
499 *
500 * Restore the original diagonal elements of T.
501 *
502  DO 70 k = 1, ki - 1
503  t( k, k ) = work( k )
504  70 CONTINUE
505 *
506  is = is - 1
507  80 CONTINUE
508  END IF
509 *
510  IF( leftv ) THEN
511 *
512 * ============================================================
513 * Compute left eigenvectors.
514 *
515 * IV is index of column in current block.
516 * Non-blocked version always uses IV=1;
517 * blocked version starts with IV=1, goes up to NB.
518 * (Note the "0-th" column is used to store the original diagonal.)
519  iv = 1
520  is = 1
521  DO 130 ki = 1, n
522 *
523  IF( somev ) THEN
524  IF( .NOT.SELECT( ki ) )
525  $ GO TO 130
526  END IF
527  smin = max( ulp*( cabs1( t( ki, ki ) ) ), smlnum )
528 *
529 * --------------------------------------------------------
530 * Complex left eigenvector
531 *
532  work( ki + iv*n ) = cone
533 *
534 * Form right-hand side.
535 *
536  DO 90 k = ki + 1, n
537  work( k + iv*n ) = -conjg( t( ki, k ) )
538  90 CONTINUE
539 *
540 * Solve conjugate-transposed triangular system:
541 * [ T(KI+1:N,KI+1:N) - T(KI,KI) ]**H * X = SCALE*WORK.
542 *
543  DO 100 k = ki + 1, n
544  t( k, k ) = t( k, k ) - t( ki, ki )
545  IF( cabs1( t( k, k ) ).LT.smin )
546  $ t( k, k ) = smin
547  100 CONTINUE
548 *
549  IF( ki.LT.n ) THEN
550  CALL clatrs( 'Upper', 'Conjugate transpose', 'Non-unit',
551  $ 'Y', n-ki, t( ki+1, ki+1 ), ldt,
552  $ work( ki+1 + iv*n ), scale, rwork, info )
553  work( ki + iv*n ) = scale
554  END IF
555 *
556 * Copy the vector x or Q*x to VL and normalize.
557 *
558  IF( .NOT.over ) THEN
559 * ------------------------------
560 * no back-transform: copy x to VL and normalize.
561  CALL ccopy( n-ki+1, work( ki + iv*n ), 1, vl(ki,is), 1 )
562 *
563  ii = icamax( n-ki+1, vl( ki, is ), 1 ) + ki - 1
564  remax = one / cabs1( vl( ii, is ) )
565  CALL csscal( n-ki+1, remax, vl( ki, is ), 1 )
566 *
567  DO 110 k = 1, ki - 1
568  vl( k, is ) = czero
569  110 CONTINUE
570 *
571  ELSE IF( nb.EQ.1 ) THEN
572 * ------------------------------
573 * version 1: back-transform each vector with GEMV, Q*x.
574  IF( ki.LT.n )
575  $ CALL cgemv( 'N', n, n-ki, cone, vl( 1, ki+1 ), ldvl,
576  $ work( ki+1 + iv*n ), 1, cmplx( scale ),
577  $ vl( 1, ki ), 1 )
578 *
579  ii = icamax( n, vl( 1, ki ), 1 )
580  remax = one / cabs1( vl( ii, ki ) )
581  CALL csscal( n, remax, vl( 1, ki ), 1 )
582 *
583  ELSE
584 * ------------------------------
585 * version 2: back-transform block of vectors with GEMM
586 * zero out above vector
587 * could go from KI-NV+1 to KI-1
588  DO k = 1, ki - 1
589  work( k + iv*n ) = czero
590  END DO
591 *
592 * Columns 1:IV of work are valid vectors.
593 * When the number of vectors stored reaches NB,
594 * or if this was last vector, do the GEMM
595  IF( (iv.EQ.nb) .OR. (ki.EQ.n) ) THEN
596  CALL cgemm( 'N', 'N', n, iv, n-ki+iv, one,
597  $ vl( 1, ki-iv+1 ), ldvl,
598  $ work( ki-iv+1 + (1)*n ), n,
599  $ czero,
600  $ work( 1 + (nb+1)*n ), n )
601 * normalize vectors
602  DO k = 1, iv
603  ii = icamax( n, work( 1 + (nb+k)*n ), 1 )
604  remax = one / cabs1( work( ii + (nb+k)*n ) )
605  CALL csscal( n, remax, work( 1 + (nb+k)*n ), 1 )
606  END DO
607  CALL clacpy( 'F', n, iv,
608  $ work( 1 + (nb+1)*n ), n,
609  $ vl( 1, ki-iv+1 ), ldvl )
610  iv = 1
611  ELSE
612  iv = iv + 1
613  END IF
614  END IF
615 *
616 * Restore the original diagonal elements of T.
617 *
618  DO 120 k = ki + 1, n
619  t( k, k ) = work( k )
620  120 CONTINUE
621 *
622  is = is + 1
623  130 CONTINUE
624  END IF
625 *
626  RETURN
627 *
628 * End of CTREVC3
629 *
real function scasum(N, CX, INCX)
SCASUM
Definition: scasum.f:54
subroutine slabad(SMALL, LARGE)
SLABAD
Definition: slabad.f:76
subroutine clatrs(UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, CNORM, INFO)
CLATRS solves a triangular system of equations with the scale factor set to prevent overflow...
Definition: clatrs.f:241
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine cgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
CGEMV
Definition: cgemv.f:160
subroutine claset(UPLO, M, N, ALPHA, BETA, A, LDA)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values...
Definition: claset.f:108
integer function icamax(N, CX, INCX)
ICAMAX
Definition: icamax.f:53
subroutine clacpy(UPLO, M, N, A, LDA, B, LDB)
CLACPY copies all or part of one two-dimensional array to another.
Definition: clacpy.f:105
integer function ilaenv(ISPEC, NAME, OPTS, N1, N2, N3, N4)
Definition: tstiee.f:83
subroutine ccopy(N, CX, INCX, CY, INCY)
CCOPY
Definition: ccopy.f:52
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:69
subroutine cgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
CGEMM
Definition: cgemm.f:189
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine csscal(N, SA, CX, INCX)
CSSCAL
Definition: csscal.f:54

Here is the call graph for this function:

Here is the caller graph for this function: