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
286 INTRINSIC abs, max, min, real, sign, sqrt
293 lower = lsame( uplo,
'L' )
294 IF( .NOT.lsame( uplo,
'U' ) .AND. .NOT.lower )
THEN
296 ELSE IF( n.LT.0 )
THEN
298 ELSE IF( ncvt.LT.0 )
THEN
300 ELSE IF( nru.LT.0 )
THEN
302 ELSE IF( ncc.LT.0 )
THEN
304 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
305 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) )
THEN
307 ELSE IF( ldu.LT.max( 1, nru ) )
THEN
309 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
310 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) )
THEN
314 CALL xerbla(
'CBDSQR', -info )
324 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
328 IF( .NOT.rotate )
THEN
329 CALL slasq1( n, d, e, rwork, info )
333 IF( info .NE. 2 )
RETURN
344 eps = slamch(
'Epsilon' )
345 unfl = slamch(
'Safe minimum' )
352 CALL slartg( d( i ), e( i ), cs, sn, r )
355 d( i+1 ) = cs*d( i+1 )
363 $
CALL clasr(
'R',
'V',
'F', nru, n, rwork( 1 ), rwork( n ),
366 $
CALL clasr(
'L',
'V',
'F', n, ncc, rwork( 1 ), rwork( n ),
374 tolmul = max( ten, min( hndrd, eps**meigth ) )
381 smax = max( smax, abs( d( i ) ) )
384 smax = max( smax, abs( e( i ) ) )
387 IF( tol.GE.zero )
THEN
391 sminoa = abs( d( 1 ) )
396 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
397 sminoa = min( sminoa, mu )
402 sminoa = sminoa / sqrt( real( n ) )
403 thresh = max( tol*sminoa, maxitr*(n*(n*unfl)) )
408 thresh = max( abs( tol )*smax, maxitr*(n*(n*unfl)) )
435 iterdivn = iterdivn + 1
436 IF( iterdivn.GE.maxitdivn )
442 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
447 abss = abs( d( ll ) )
448 abse = abs( e( ll ) )
449 IF( tol.LT.zero .AND. abss.LE.thresh )
453 smax = max( smax, abss, abse )
478 CALL slasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
487 $
CALL csrot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt,
490 $
CALL csrot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl, sinl )
492 $
CALL csrot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
501 IF( ll.GT.oldm .OR. m.LT.oldll )
THEN
502 IF( abs( d( ll ) ).GE.abs( d( m ) ) )
THEN
522 IF( abs( e( m-1 ) ).LE.abs( tol )*abs( d( m ) ) .OR.
523 $ ( tol.LT.zero .AND. abs( e( m-1 ) ).LE.thresh ) )
THEN
528 IF( tol.GE.zero )
THEN
535 DO 100 lll = ll, m - 1
536 IF( abs( e( lll ) ).LE.tol*mu )
THEN
540 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
541 smin = min( smin, mu )
550 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
551 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) )
THEN
556 IF( tol.GE.zero )
THEN
563 DO 110 lll = m - 1, ll, -1
564 IF( abs( e( lll ) ).LE.tol*mu )
THEN
568 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
569 smin = min( smin, mu )
579 IF( tol.GE.zero .AND. n*tol*( smin / smax ).LE.
580 $ max( eps, hndrth*tol ) )
THEN
591 CALL slas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
594 CALL slas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
599 IF( sll.GT.zero )
THEN
600 IF( ( shift / sll )**2.LT.eps )
611 IF( shift.EQ.zero )
THEN
620 CALL slartg( d( i )*cs, e( i ), cs, sn, r )
623 CALL slartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn, d( i ) )
625 rwork( i-ll+1+nm1 ) = sn
626 rwork( i-ll+1+nm12 ) = oldcs
627 rwork( i-ll+1+nm13 ) = oldsn
636 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
637 $ rwork( n ), vt( ll, 1 ), ldvt )
639 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1, rwork( nm12+1 ),
640 $ rwork( nm13+1 ), u( 1, ll ), ldu )
642 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc, rwork( nm12+1 ),
643 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
647 IF( abs( e( m-1 ) ).LE.thresh )
657 DO 130 i = m, ll + 1, -1
658 CALL slartg( d( i )*cs, e( i-1 ), cs, sn, r )
661 CALL slartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn, d( i ) )
663 rwork( i-ll+nm1 ) = -sn
664 rwork( i-ll+nm12 ) = oldcs
665 rwork( i-ll+nm13 ) = -oldsn
674 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt, rwork( nm12+1 ),
675 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
677 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
678 $ rwork( n ), u( 1, ll ), ldu )
680 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
681 $ rwork( n ), c( ll, 1 ), ldc )
685 IF( abs( e( ll ) ).LE.thresh )
697 f = ( abs( d( ll ) )-shift )*
698 $ ( sign( one, d( ll ) )+shift / d( ll ) )
701 CALL slartg( f, g, cosr, sinr, r )
704 f = cosr*d( i ) + sinr*e( i )
705 e( i ) = cosr*e( i ) - sinr*d( i )
707 d( i+1 ) = cosr*d( i+1 )
708 CALL slartg( f, g, cosl, sinl, r )
710 f = cosl*e( i ) + sinl*d( i+1 )
711 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
714 e( i+1 ) = cosl*e( i+1 )
716 rwork( i-ll+1 ) = cosr
717 rwork( i-ll+1+nm1 ) = sinr
718 rwork( i-ll+1+nm12 ) = cosl
719 rwork( i-ll+1+nm13 ) = sinl
726 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncvt, rwork( 1 ),
727 $ rwork( n ), vt( ll, 1 ), ldvt )
729 $
CALL clasr(
'R',
'V',
'F', nru, m-ll+1, rwork( nm12+1 ),
730 $ rwork( nm13+1 ), u( 1, ll ), ldu )
732 $
CALL clasr(
'L',
'V',
'F', m-ll+1, ncc, rwork( nm12+1 ),
733 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
737 IF( abs( e( m-1 ) ).LE.thresh )
745 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
748 DO 150 i = m, ll + 1, -1
749 CALL slartg( f, g, cosr, sinr, r )
752 f = cosr*d( i ) + sinr*e( i-1 )
753 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
755 d( i-1 ) = cosr*d( i-1 )
756 CALL slartg( f, g, cosl, sinl, r )
758 f = cosl*e( i-1 ) + sinl*d( i-1 )
759 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
762 e( i-2 ) = cosl*e( i-2 )
765 rwork( i-ll+nm1 ) = -sinr
766 rwork( i-ll+nm12 ) = cosl
767 rwork( i-ll+nm13 ) = -sinl
773 IF( abs( e( ll ) ).LE.thresh )
779 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncvt, rwork( nm12+1 ),
780 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
782 $
CALL clasr(
'R',
'V',
'B', nru, m-ll+1, rwork( 1 ),
783 $ rwork( n ), u( 1, ll ), ldu )
785 $
CALL clasr(
'L',
'V',
'B', m-ll+1, ncc, rwork( 1 ),
786 $ rwork( n ), c( ll, 1 ), ldc )
798 IF( d( i ).LT.zero )
THEN
804 $
CALL csscal( ncvt, negone, vt( i, 1 ), ldvt )
817 DO 180 j = 2, n + 1 - i
818 IF( d( j ).LE.smin )
THEN
823 IF( isub.NE.n+1-i )
THEN
827 d( isub ) = d( n+1-i )
830 $
CALL cswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
833 $
CALL cswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
835 $
CALL cswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ), ldc )
subroutine xerbla(srname, info)
subroutine cbdsqr(uplo, n, ncvt, nru, ncc, d, e, vt, ldvt, u, ldu, c, ldc, rwork, info)
CBDSQR
subroutine slartg(f, g, c, s, r)
SLARTG generates a plane rotation with real cosine and real sine.
subroutine slas2(f, g, h, ssmin, ssmax)
SLAS2 computes singular values of a 2-by-2 triangular matrix.
subroutine slasq1(n, d, e, work, info)
SLASQ1 computes the singular values of a real square bidiagonal matrix. Used by sbdsqr.
subroutine clasr(side, pivot, direct, m, n, c, s, a, lda)
CLASR applies a sequence of plane rotations to a general rectangular matrix.
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 csrot(n, cx, incx, cy, incy, c, s)
CSROT
subroutine csscal(n, sa, cx, incx)
CSSCAL
subroutine cswap(n, cx, incx, cy, incy)
CSWAP