231 SUBROUTINE cbdsqr( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
232 $ LDU, C, LDC, RWORK, INFO )
240 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
243 REAL D( * ), E( * ), RWORK( * )
244 COMPLEX C( LDC, * ), U( LDU, * ), VT( LDVT, * )
251 parameter( zero = 0.0e0 )
253 parameter( one = 1.0e0 )
255 parameter( negone = -1.0e0 )
257 parameter( hndrth = 0.01e0 )
259 parameter( ten = 10.0e0 )
261 parameter( hndrd = 100.0e0 )
263 parameter( meigth = -0.125e0 )
265 parameter( maxitr = 6 )
268 LOGICAL LOWER, ROTATE
269 INTEGER I, IDIR, ISUB, ITER, ITERDIVN, J, LL, LLL, M,
270 $ maxitdivn, nm1, nm12, nm13, oldll, oldm
271 REAL ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
272 $ oldcs, oldsn, r, shift, sigmn, sigmx, sinl,
273 $ sinr, sll, smax, smin, sminoa,
274 $ sn, thresh, tol, tolmul, unfl
279 EXTERNAL lsame, slamch
287 INTRINSIC abs, max, min, real, sign, sqrt
294 lower = lsame( uplo,
'L' )
295 IF( .NOT.lsame( uplo,
'U' ) .AND. .NOT.lower )
THEN
297 ELSE IF( n.LT.0 )
THEN
299 ELSE IF( ncvt.LT.0 )
THEN
301 ELSE IF( nru.LT.0 )
THEN
303 ELSE IF( ncc.LT.0 )
THEN
305 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
306 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) )
THEN
308 ELSE IF( ldu.LT.max( 1, nru ) )
THEN
310 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
311 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) )
THEN
315 CALL xerbla(
'CBDSQR', -info )
325 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
329 IF( .NOT.rotate )
THEN
330 CALL slasq1( n, d, e, rwork, info )
334 IF( info .NE. 2 )
RETURN
345 eps = slamch(
'Epsilon' )
346 unfl = slamch(
'Safe minimum' )
353 CALL slartg( d( i ), e( i ), cs, sn, r )
356 d( i+1 ) = cs*d( i+1 )
364 $
CALL clasr(
'R',
'V',
'F', nru, n, rwork( 1 ),
368 $
CALL clasr(
'L',
'V',
'F', n, ncc, rwork( 1 ),
377 tolmul = max( ten, min( hndrd, eps**meigth ) )
384 smax = max( smax, abs( d( i ) ) )
387 smax = max( smax, abs( e( i ) ) )
390 IF( tol.GE.zero )
THEN
394 sminoa = abs( d( 1 ) )
399 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
400 sminoa = min( sminoa, mu )
405 sminoa = sminoa / sqrt( real( n ) )
406 thresh = max( tol*sminoa,
407 $ real(maxitr)*(real(n)*(real(n)*unfl)) )
412 thresh = max( abs( tol )*smax,
413 $ real(maxitr)*(real(n)*(real(n)*unfl)) )
440 iterdivn = iterdivn + 1
441 IF( iterdivn.GE.maxitdivn )
447 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
452 abss = abs( d( ll ) )
453 abse = abs( e( ll ) )
454 IF( tol.LT.zero .AND. abss.LE.thresh )
458 smax = max( smax, abss, abse )
483 CALL slasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
492 $
CALL csrot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt,
495 $
CALL csrot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl,
498 $
CALL csrot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
507 IF( ll.GT.oldm .OR. m.LT.oldll )
THEN
508 IF( abs( d( ll ) ).GE.abs( d( m ) ) )
THEN
528 IF( abs( e( m-1 ) ).LE.abs( tol )*abs( d( m ) ) .OR.
529 $ ( tol.LT.zero .AND. abs( e( m-1 ) ).LE.thresh ) )
THEN
534 IF( tol.GE.zero )
THEN
541 DO 100 lll = ll, m - 1
542 IF( abs( e( lll ) ).LE.tol*mu )
THEN
546 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
547 smin = min( smin, mu )
556 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
557 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) )
THEN
562 IF( tol.GE.zero )
THEN
569 DO 110 lll = m - 1, ll, -1
570 IF( abs( e( lll ) ).LE.tol*mu )
THEN
574 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
575 smin = min( smin, mu )
585 IF( tol.GE.zero .AND. real( n )*tol*( smin / smax ).LE.
586 $ max( eps, hndrth*tol ) )
THEN
597 CALL slas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
600 CALL slas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
605 IF( sll.GT.zero )
THEN
606 IF( ( shift / sll )**2.LT.eps )
617 IF( shift.EQ.zero )
THEN
626 CALL slartg( d( i )*cs, e( i ), cs, sn, r )
629 CALL slartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn,
632 rwork( i-ll+1+nm1 ) = sn
633 rwork( i-ll+1+nm12 ) = oldcs
634 rwork( i-ll+1+nm13 ) = oldsn
643 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
644 $ rwork( n ), vt( ll, 1 ), ldvt )
646 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1,
648 $ rwork( nm13+1 ), u( 1, ll ), ldu )
650 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc,
652 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
656 IF( abs( e( m-1 ) ).LE.thresh )
666 DO 130 i = m, ll + 1, -1
667 CALL slartg( d( i )*cs, e( i-1 ), cs, sn, r )
670 CALL slartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn,
673 rwork( i-ll+nm1 ) = -sn
674 rwork( i-ll+nm12 ) = oldcs
675 rwork( i-ll+nm13 ) = -oldsn
684 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt,
686 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
688 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
689 $ rwork( n ), u( 1, ll ), ldu )
691 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
692 $ rwork( n ), c( ll, 1 ), ldc )
696 IF( abs( e( ll ) ).LE.thresh )
708 f = ( abs( d( ll ) )-shift )*
709 $ ( sign( one, d( ll ) )+shift / d( ll ) )
712 CALL slartg( f, g, cosr, sinr, r )
715 f = cosr*d( i ) + sinr*e( i )
716 e( i ) = cosr*e( i ) - sinr*d( i )
718 d( i+1 ) = cosr*d( i+1 )
719 CALL slartg( f, g, cosl, sinl, r )
721 f = cosl*e( i ) + sinl*d( i+1 )
722 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
725 e( i+1 ) = cosl*e( i+1 )
727 rwork( i-ll+1 ) = cosr
728 rwork( i-ll+1+nm1 ) = sinr
729 rwork( i-ll+1+nm12 ) = cosl
730 rwork( i-ll+1+nm13 ) = sinl
737 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
738 $ rwork( n ), vt( ll, 1 ), ldvt )
740 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1,
742 $ rwork( nm13+1 ), u( 1, ll ), ldu )
744 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc,
746 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
750 IF( abs( e( m-1 ) ).LE.thresh )
758 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
761 DO 150 i = m, ll + 1, -1
762 CALL slartg( f, g, cosr, sinr, r )
765 f = cosr*d( i ) + sinr*e( i-1 )
766 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
768 d( i-1 ) = cosr*d( i-1 )
769 CALL slartg( f, g, cosl, sinl, r )
771 f = cosl*e( i-1 ) + sinl*d( i-1 )
772 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
775 e( i-2 ) = cosl*e( i-2 )
778 rwork( i-ll+nm1 ) = -sinr
779 rwork( i-ll+nm12 ) = cosl
780 rwork( i-ll+nm13 ) = -sinl
786 IF( abs( e( ll ) ).LE.thresh )
792 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt,
794 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
796 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
797 $ rwork( n ), u( 1, ll ), ldu )
799 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
800 $ rwork( n ), c( ll, 1 ), ldc )
812 IF( d( i ).EQ.zero )
THEN
818 IF( d( i ).LT.zero )
THEN
824 $
CALL csscal( ncvt, negone, vt( i, 1 ), ldvt )
837 DO 180 j = 2, n + 1 - i
838 IF( d( j ).LE.smin )
THEN
843 IF( isub.NE.n+1-i )
THEN
847 d( isub ) = d( n+1-i )
850 $
CALL cswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
853 $
CALL cswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
855 $
CALL cswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ),