222 SUBROUTINE cbdsqr( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
223 $ ldu, c, ldc, rwork, info )
232 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
235 REAL D( * ), E( * ), RWORK( * )
236 COMPLEX C( ldc, * ), U( ldu, * ), VT( ldvt, * )
243 parameter ( zero = 0.0e0 )
245 parameter ( one = 1.0e0 )
247 parameter ( negone = -1.0e0 )
249 parameter ( hndrth = 0.01e0 )
251 parameter ( ten = 10.0e0 )
253 parameter ( hndrd = 100.0e0 )
255 parameter ( meigth = -0.125e0 )
257 parameter ( maxitr = 6 )
260 LOGICAL LOWER, ROTATE
261 INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1,
262 $ nm12, nm13, oldll, oldm
263 REAL ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
264 $ oldcs, oldsn, r, shift, sigmn, sigmx, sinl,
265 $ sinr, sll, smax, smin, sminl, sminoa,
266 $ sn, thresh, tol, tolmul, unfl
271 EXTERNAL lsame, slamch
278 INTRINSIC abs, max, min,
REAL, SIGN, SQRT
285 lower = lsame( uplo,
'L' )
286 IF( .NOT.lsame( uplo,
'U' ) .AND. .NOT.lower )
THEN
288 ELSE IF( n.LT.0 )
THEN
290 ELSE IF( ncvt.LT.0 )
THEN
292 ELSE IF( nru.LT.0 )
THEN
294 ELSE IF( ncc.LT.0 )
THEN
296 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
297 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) )
THEN
299 ELSE IF( ldu.LT.max( 1, nru ) )
THEN
301 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
302 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) )
THEN
306 CALL xerbla(
'CBDSQR', -info )
316 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
320 IF( .NOT.rotate )
THEN
321 CALL slasq1( n, d, e, rwork, info )
325 IF( info .NE. 2 )
RETURN
336 eps = slamch(
'Epsilon' )
337 unfl = slamch(
'Safe minimum' )
344 CALL slartg( d( i ), e( i ), cs, sn, r )
347 d( i+1 ) = cs*d( i+1 )
355 $
CALL clasr(
'R',
'V',
'F', nru, n, rwork( 1 ), rwork( n ),
358 $
CALL clasr(
'L',
'V',
'F', n, ncc, rwork( 1 ), rwork( n ),
366 tolmul = max( ten, min( hndrd, eps**meigth ) )
373 smax = max( smax, abs( d( i ) ) )
376 smax = max( smax, abs( e( i ) ) )
379 IF( tol.GE.zero )
THEN
383 sminoa = abs( d( 1 ) )
388 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
389 sminoa = min( sminoa, mu )
394 sminoa = sminoa / sqrt(
REAL( N ) )
395 thresh = max( tol*sminoa, maxitr*n*n*unfl )
400 thresh = max( abs( tol )*smax, maxitr*n*n*unfl )
429 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
435 abss = abs( d( ll ) )
436 abse = abs( e( ll ) )
437 IF( tol.LT.zero .AND. abss.LE.thresh )
441 smin = min( smin, abss )
442 smax = max( smax, abss, abse )
467 CALL slasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
476 $
CALL csrot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt,
479 $
CALL csrot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl, sinl )
481 $
CALL csrot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
490 IF( ll.GT.oldm .OR. m.LT.oldll )
THEN
491 IF( abs( d( ll ) ).GE.abs( d( m ) ) )
THEN
511 IF( abs( e( m-1 ) ).LE.abs( tol )*abs( d( m ) ) .OR.
512 $ ( tol.LT.zero .AND. abs( e( m-1 ) ).LE.thresh ) )
THEN
517 IF( tol.GE.zero )
THEN
524 DO 100 lll = ll, m - 1
525 IF( abs( e( lll ) ).LE.tol*mu )
THEN
529 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
530 sminl = min( sminl, mu )
539 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
540 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) )
THEN
545 IF( tol.GE.zero )
THEN
552 DO 110 lll = m - 1, ll, -1
553 IF( abs( e( lll ) ).LE.tol*mu )
THEN
557 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
558 sminl = min( sminl, mu )
568 IF( tol.GE.zero .AND. n*tol*( sminl / smax ).LE.
569 $ max( eps, hndrth*tol ) )
THEN
580 CALL slas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
583 CALL slas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
588 IF( sll.GT.zero )
THEN
589 IF( ( shift / sll )**2.LT.eps )
600 IF( shift.EQ.zero )
THEN
609 CALL slartg( d( i )*cs, e( i ), cs, sn, r )
612 CALL slartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn, d( i ) )
614 rwork( i-ll+1+nm1 ) = sn
615 rwork( i-ll+1+nm12 ) = oldcs
616 rwork( i-ll+1+nm13 ) = oldsn
625 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
626 $ rwork( n ), vt( ll, 1 ), ldvt )
628 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1, rwork( nm12+1 ),
629 $ rwork( nm13+1 ), u( 1, ll ), ldu )
631 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc, rwork( nm12+1 ),
632 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
636 IF( abs( e( m-1 ) ).LE.thresh )
646 DO 130 i = m, ll + 1, -1
647 CALL slartg( d( i )*cs, e( i-1 ), cs, sn, r )
650 CALL slartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn, d( i ) )
652 rwork( i-ll+nm1 ) = -sn
653 rwork( i-ll+nm12 ) = oldcs
654 rwork( i-ll+nm13 ) = -oldsn
663 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt, rwork( nm12+1 ),
664 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
666 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
667 $ rwork( n ), u( 1, ll ), ldu )
669 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
670 $ rwork( n ), c( ll, 1 ), ldc )
674 IF( abs( e( ll ) ).LE.thresh )
686 f = ( abs( d( ll ) )-shift )*
687 $ ( sign( one, d( ll ) )+shift / d( ll ) )
690 CALL slartg( f, g, cosr, sinr, r )
693 f = cosr*d( i ) + sinr*e( i )
694 e( i ) = cosr*e( i ) - sinr*d( i )
696 d( i+1 ) = cosr*d( i+1 )
697 CALL slartg( f, g, cosl, sinl, r )
699 f = cosl*e( i ) + sinl*d( i+1 )
700 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
703 e( i+1 ) = cosl*e( i+1 )
705 rwork( i-ll+1 ) = cosr
706 rwork( i-ll+1+nm1 ) = sinr
707 rwork( i-ll+1+nm12 ) = cosl
708 rwork( i-ll+1+nm13 ) = sinl
715 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
716 $ rwork( n ), vt( ll, 1 ), ldvt )
718 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1, rwork( nm12+1 ),
719 $ rwork( nm13+1 ), u( 1, ll ), ldu )
721 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc, rwork( nm12+1 ),
722 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
726 IF( abs( e( m-1 ) ).LE.thresh )
734 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
737 DO 150 i = m, ll + 1, -1
738 CALL slartg( f, g, cosr, sinr, r )
741 f = cosr*d( i ) + sinr*e( i-1 )
742 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
744 d( i-1 ) = cosr*d( i-1 )
745 CALL slartg( f, g, cosl, sinl, r )
747 f = cosl*e( i-1 ) + sinl*d( i-1 )
748 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
751 e( i-2 ) = cosl*e( i-2 )
754 rwork( i-ll+nm1 ) = -sinr
755 rwork( i-ll+nm12 ) = cosl
756 rwork( i-ll+nm13 ) = -sinl
762 IF( abs( e( ll ) ).LE.thresh )
768 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt, rwork( nm12+1 ),
769 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
771 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
772 $ rwork( n ), u( 1, ll ), ldu )
774 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
775 $ rwork( n ), c( ll, 1 ), ldc )
787 IF( d( i ).LT.zero )
THEN
793 $
CALL csscal( ncvt, negone, vt( i, 1 ), ldvt )
806 DO 180 j = 2, n + 1 - i
807 IF( d( j ).LE.smin )
THEN
812 IF( isub.NE.n+1-i )
THEN
816 d( isub ) = d( n+1-i )
819 $
CALL cswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
822 $
CALL cswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
824 $
CALL cswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ), ldc )
subroutine slas2(F, G, H, SSMIN, SSMAX)
SLAS2 computes singular values of a 2-by-2 triangular matrix.
subroutine cbdsqr(UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, LDU, C, LDC, RWORK, INFO)
CBDSQR
subroutine xerbla(SRNAME, INFO)
XERBLA
subroutine slartg(F, G, CS, SN, R)
SLARTG generates a plane rotation with real cosine and real sine.
subroutine slasv2(F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL)
SLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
subroutine clasr(SIDE, PIVOT, DIRECT, M, N, C, S, A, LDA)
CLASR applies a sequence of plane rotations to a general rectangular matrix.
subroutine csrot(N, CX, INCX, CY, INCY, C, S)
CSROT
subroutine cswap(N, CX, INCX, CY, INCY)
CSWAP
subroutine slasq1(N, D, E, WORK, INFO)
SLASQ1 computes the singular values of a real square bidiagonal matrix. Used by sbdsqr.
subroutine csscal(N, SA, CX, INCX)
CSSCAL