219 SUBROUTINE stgex2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
220 $ LDZ, J1, N1, N2, WORK, LWORK, INFO )
228 INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
231 REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
232 $ work( * ), z( ldz, * )
241 parameter( zero = 0.0e+0, one = 1.0e+0 )
243 parameter( twenty = 2.0e+01 )
245 parameter( ldst = 4 )
247 parameter( wands = .true. )
251 INTEGER I, IDUM, LINFO, M
252 REAL BQRA21, BRQA21, DDUM, DNORMA, DNORMB,
254 $ dsum, eps, f, g, sa, sb, scale, smlnum,
258 INTEGER IWORK( LDST + 2 )
259 REAL AI( 2 ), AR( 2 ), BE( 2 ), IR( LDST, LDST ),
260 $ ircop( ldst, ldst ), li( ldst, ldst ),
261 $ licop( ldst, ldst ), s( ldst, ldst ),
262 $ scpy( ldst, ldst ), t( ldst, ldst ),
263 $ taul( ldst ), taur( ldst ), tcpy( ldst, ldst )
275 INTRINSIC abs, max, sqrt
283 IF( n.LE.1 .OR. n1.LE.0 .OR. n2.LE.0 )
285 IF( n1.GT.n .OR. ( j1+n1 ).GT.n )
288 IF( lwork.LT.max( n*m, m*m*2 ) )
THEN
290 work( 1 ) = max( n*m, m*m*2 )
299 CALL slaset(
'Full', ldst, ldst, zero, zero, li, ldst )
300 CALL slaset(
'Full', ldst, ldst, zero, zero, ir, ldst )
301 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda, s, ldst )
302 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb, t, ldst )
307 smlnum = slamch(
'S' ) / eps
310 CALL slacpy(
'Full', m, m, s, ldst, work, m )
311 CALL slassq( m*m, work, 1, dscale, dsum )
312 dnorma = dscale*sqrt( dsum )
315 CALL slacpy(
'Full', m, m, t, ldst, work, m )
316 CALL slassq( m*m, work, 1, dscale, dsum )
317 dnormb = dscale*sqrt( dsum )
327 thresha = max( twenty*eps*dnorma, smlnum )
328 threshb = max( twenty*eps*dnormb, smlnum )
337 f = s( 2, 2 )*t( 1, 1 ) - t( 2, 2 )*s( 1, 1 )
338 g = s( 2, 2 )*t( 1, 2 ) - t( 2, 2 )*s( 1, 2 )
339 sa = abs( s( 2, 2 ) ) * abs( t( 1, 1 ) )
340 sb = abs( s( 1, 1 ) ) * abs( t( 2, 2 ) )
341 CALL slartg( f, g, ir( 1, 2 ), ir( 1, 1 ), ddum )
342 ir( 2, 1 ) = -ir( 1, 2 )
343 ir( 2, 2 ) = ir( 1, 1 )
344 CALL srot( 2, s( 1, 1 ), 1, s( 1, 2 ), 1, ir( 1, 1 ),
346 CALL srot( 2, t( 1, 1 ), 1, t( 1, 2 ), 1, ir( 1, 1 ),
349 CALL slartg( s( 1, 1 ), s( 2, 1 ), li( 1, 1 ), li( 2, 1 ),
352 CALL slartg( t( 1, 1 ), t( 2, 1 ), li( 1, 1 ), li( 2, 1 ),
355 CALL srot( 2, s( 1, 1 ), ldst, s( 2, 1 ), ldst, li( 1, 1 ),
357 CALL srot( 2, t( 1, 1 ), ldst, t( 2, 1 ), ldst, li( 1, 1 ),
359 li( 2, 2 ) = li( 1, 1 )
360 li( 1, 2 ) = -li( 2, 1 )
365 weak = abs( s( 2, 1 ) ) .LE. thresha .AND.
366 $ abs( t( 2, 1 ) ) .LE. threshb
377 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda, work( m*m+1 ),
379 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, s, ldst, zero,
381 CALL sgemm(
'N',
'T', m, m, m, -one, work, m, ir, ldst, one,
385 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
386 sa = dscale*sqrt( dsum )
388 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb, work( m*m+1 ),
390 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, t, ldst, zero,
392 CALL sgemm(
'N',
'T', m, m, m, -one, work, m, ir, ldst, one,
396 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
397 sb = dscale*sqrt( dsum )
398 strong = sa.LE.thresha .AND. sb.LE.threshb
406 CALL srot( j1+1, a( 1, j1 ), 1, a( 1, j1+1 ), 1, ir( 1, 1 ),
408 CALL srot( j1+1, b( 1, j1 ), 1, b( 1, j1+1 ), 1, ir( 1, 1 ),
410 CALL srot( n-j1+1, a( j1, j1 ), lda, a( j1+1, j1 ), lda,
411 $ li( 1, 1 ), li( 2, 1 ) )
412 CALL srot( n-j1+1, b( j1, j1 ), ldb, b( j1+1, j1 ), ldb,
413 $ li( 1, 1 ), li( 2, 1 ) )
423 $
CALL srot( n, z( 1, j1 ), 1, z( 1, j1+1 ), 1, ir( 1, 1 ),
426 $
CALL srot( n, q( 1, j1 ), 1, q( 1, j1+1 ), 1, li( 1, 1 ),
443 CALL slacpy(
'Full', n1, n2, t( 1, n1+1 ), ldst, li, ldst )
444 CALL slacpy(
'Full', n1, n2, s( 1, n1+1 ), ldst,
445 $ ir( n2+1, n1+1 ), ldst )
446 CALL stgsy2(
'N', 0, n1, n2, s, ldst, s( n1+1, n1+1 ), ldst,
447 $ ir( n2+1, n1+1 ), ldst, t, ldst, t( n1+1, n1+1 ),
448 $ ldst, li, ldst, scale, dsum, dscale, iwork, idum,
462 CALL sscal( n1, -one, li( 1, i ), 1 )
463 li( n1+i, i ) = scale
465 CALL sgeqr2( m, n2, li, ldst, taul, work, linfo )
468 CALL sorg2r( m, m, n2, li, ldst, taul, work, linfo )
479 ir( n2+i, i ) = scale
481 CALL sgerq2( n1, m, ir( n2+1, 1 ), ldst, taur, work, linfo )
484 CALL sorgr2( m, m, n1, ir, ldst, taur, work, linfo )
490 CALL sgemm(
'T',
'N', m, m, m, one, li, ldst, s, ldst, zero,
492 CALL sgemm(
'N',
'T', m, m, m, one, work, m, ir, ldst, zero, s,
494 CALL sgemm(
'T',
'N', m, m, m, one, li, ldst, t, ldst, zero,
496 CALL sgemm(
'N',
'T', m, m, m, one, work, m, ir, ldst, zero, t,
498 CALL slacpy(
'F', m, m, s, ldst, scpy, ldst )
499 CALL slacpy(
'F', m, m, t, ldst, tcpy, ldst )
500 CALL slacpy(
'F', m, m, ir, ldst, ircop, ldst )
501 CALL slacpy(
'F', m, m, li, ldst, licop, ldst )
506 CALL sgerq2( m, m, t, ldst, taur, work, linfo )
509 CALL sormr2(
'R',
'T', m, m, m, t, ldst, taur, s, ldst, work,
513 CALL sormr2(
'L',
'N', m, m, m, t, ldst, taur, ir, ldst, work,
523 CALL slassq( n1, s( n2+1, i ), 1, dscale, dsum )
525 brqa21 = dscale*sqrt( dsum )
530 CALL sgeqr2( m, m, tcpy, ldst, taul, work, linfo )
533 CALL sorm2r(
'L',
'T', m, m, m, tcpy, ldst, taul, scpy, ldst,
535 CALL sorm2r(
'R',
'N', m, m, m, tcpy, ldst, taul, licop, ldst,
545 CALL slassq( n1, scpy( n2+1, i ), 1, dscale, dsum )
547 bqra21 = dscale*sqrt( dsum )
553 IF( bqra21.LE.brqa21 .AND. bqra21.LE.thresha )
THEN
554 CALL slacpy(
'F', m, m, scpy, ldst, s, ldst )
555 CALL slacpy(
'F', m, m, tcpy, ldst, t, ldst )
556 CALL slacpy(
'F', m, m, ircop, ldst, ir, ldst )
557 CALL slacpy(
'F', m, m, licop, ldst, li, ldst )
558 ELSE IF( brqa21.GE.thresha )
THEN
564 CALL slaset(
'Lower', m-1, m-1, zero, zero, t(2,1), ldst )
573 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda, work( m*m+1 ),
575 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, s, ldst, zero,
577 CALL sgemm(
'N',
'N', m, m, m, -one, work, m, ir, ldst, one,
581 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
582 sa = dscale*sqrt( dsum )
584 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb, work( m*m+1 ),
586 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, t, ldst, zero,
588 CALL sgemm(
'N',
'N', m, m, m, -one, work, m, ir, ldst, one,
592 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
593 sb = dscale*sqrt( dsum )
594 strong = sa.LE.thresha .AND. sb.LE.threshb
603 CALL slaset(
'Full', n1, n2, zero, zero, s(n2+1,1), ldst )
607 CALL slacpy(
'F', m, m, s, ldst, a( j1, j1 ), lda )
608 CALL slacpy(
'F', m, m, t, ldst, b( j1, j1 ), ldb )
609 CALL slaset(
'Full', ldst, ldst, zero, zero, t, ldst )
613 CALL slaset(
'Full', m, m, zero, zero, work, m )
616 idum = lwork - m*m - 2
618 CALL slagv2( a( j1, j1 ), lda, b( j1, j1 ), ldb, ar, ai, be,
619 $ work( 1 ), work( 2 ), t( 1, 1 ), t( 2, 1 ) )
620 work( m+1 ) = -work( 2 )
621 work( m+2 ) = work( 1 )
622 t( n2, n2 ) = t( 1, 1 )
623 t( 1, 2 ) = -t( 2, 1 )
629 CALL slagv2( a( j1+n2, j1+n2 ), lda, b( j1+n2, j1+n2 ), ldb,
630 $ taur, taul, work( m*m+1 ), work( n2*m+n2+1 ),
631 $ work( n2*m+n2+2 ), t( n2+1, n2+1 ),
633 work( m*m ) = work( n2*m+n2+1 )
634 work( m*m-1 ) = -work( n2*m+n2+2 )
635 t( m, m ) = t( n2+1, n2+1 )
636 t( m-1, m ) = -t( m, m-1 )
638 CALL sgemm(
'T',
'N', n2, n1, n2, one, work, m, a( j1, j1+n2 ),
639 $ lda, zero, work( m*m+1 ), n2 )
640 CALL slacpy(
'Full', n2, n1, work( m*m+1 ), n2, a( j1, j1+n2 ),
642 CALL sgemm(
'T',
'N', n2, n1, n2, one, work, m, b( j1, j1+n2 ),
643 $ ldb, zero, work( m*m+1 ), n2 )
644 CALL slacpy(
'Full', n2, n1, work( m*m+1 ), n2, b( j1, j1+n2 ),
646 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, work, m, zero,
648 CALL slacpy(
'Full', m, m, work( m*m+1 ), m, li, ldst )
649 CALL sgemm(
'N',
'N', n2, n1, n1, one, a( j1, j1+n2 ), lda,
650 $ t( n2+1, n2+1 ), ldst, zero, work, n2 )
651 CALL slacpy(
'Full', n2, n1, work, n2, a( j1, j1+n2 ), lda )
652 CALL sgemm(
'N',
'N', n2, n1, n1, one, b( j1, j1+n2 ), ldb,
653 $ t( n2+1, n2+1 ), ldst, zero, work, n2 )
654 CALL slacpy(
'Full', n2, n1, work, n2, b( j1, j1+n2 ), ldb )
655 CALL sgemm(
'T',
'N', m, m, m, one, ir, ldst, t, ldst, zero,
657 CALL slacpy(
'Full', m, m, work, m, ir, ldst )
662 CALL sgemm(
'N',
'N', n, m, m, one, q( 1, j1 ), ldq, li,
663 $ ldst, zero, work, n )
664 CALL slacpy(
'Full', n, m, work, n, q( 1, j1 ), ldq )
669 CALL sgemm(
'N',
'N', n, m, m, one, z( 1, j1 ), ldz, ir,
670 $ ldst, zero, work, n )
671 CALL slacpy(
'Full', n, m, work, n, z( 1, j1 ), ldz )
680 CALL sgemm(
'T',
'N', m, n-i+1, m, one, li, ldst,
681 $ a( j1, i ), lda, zero, work, m )
682 CALL slacpy(
'Full', m, n-i+1, work, m, a( j1, i ), lda )
683 CALL sgemm(
'T',
'N', m, n-i+1, m, one, li, ldst,
684 $ b( j1, i ), ldb, zero, work, m )
685 CALL slacpy(
'Full', m, n-i+1, work, m, b( j1, i ), ldb )
689 CALL sgemm(
'N',
'N', i, m, m, one, a( 1, j1 ), lda, ir,
690 $ ldst, zero, work, i )
691 CALL slacpy(
'Full', i, m, work, i, a( 1, j1 ), lda )
692 CALL sgemm(
'N',
'N', i, m, m, one, b( 1, j1 ), ldb, ir,
693 $ ldst, zero, work, i )
694 CALL slacpy(
'Full', i, m, work, i, b( 1, j1 ), ldb )
subroutine sgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
SGEMM
subroutine sgeqr2(m, n, a, lda, tau, work, info)
SGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorithm.
subroutine sgerq2(m, n, a, lda, tau, work, info)
SGERQ2 computes the RQ factorization of a general rectangular matrix using an unblocked algorithm.
subroutine slacpy(uplo, m, n, a, lda, b, ldb)
SLACPY copies all or part of one two-dimensional array to another.
subroutine slagv2(a, lda, b, ldb, alphar, alphai, beta, csl, snl, csr, snr)
SLAGV2 computes the Generalized Schur factorization of a real 2-by-2 matrix pencil (A,...
subroutine slartg(f, g, c, s, r)
SLARTG generates a plane rotation with real cosine and real sine.
subroutine slaset(uplo, m, n, alpha, beta, a, lda)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine slassq(n, x, incx, scale, sumsq)
SLASSQ updates a sum of squares represented in scaled form.
subroutine srot(n, sx, incx, sy, incy, c, s)
SROT
subroutine sscal(n, sa, sx, incx)
SSCAL
subroutine stgex2(wantq, wantz, n, a, lda, b, ldb, q, ldq, z, ldz, j1, n1, n2, work, lwork, info)
STGEX2 swaps adjacent diagonal blocks in an upper (quasi) triangular matrix pair by an orthogonal equ...
subroutine stgsy2(trans, ijob, m, n, a, lda, b, ldb, c, ldc, d, ldd, e, lde, f, ldf, scale, rdsum, rdscal, iwork, pq, info)
STGSY2 solves the generalized Sylvester equation (unblocked algorithm).
subroutine sorg2r(m, n, k, a, lda, tau, work, info)
SORG2R generates all or part of the orthogonal matrix Q from a QR factorization determined by sgeqrf ...
subroutine sorgr2(m, n, k, a, lda, tau, work, info)
SORGR2 generates all or part of the orthogonal matrix Q from an RQ factorization determined by sgerqf...
subroutine sorm2r(side, trans, m, n, k, a, lda, tau, c, ldc, work, info)
SORM2R multiplies a general matrix by the orthogonal matrix from a QR factorization determined by sge...
subroutine sormr2(side, trans, m, n, k, a, lda, tau, c, ldc, work, info)
SORMR2 multiplies a general matrix by the orthogonal matrix from a RQ factorization determined by sge...