LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ cbdsqr()

subroutine cbdsqr ( character uplo,
integer n,
integer ncvt,
integer nru,
integer ncc,
real, dimension( * ) d,
real, dimension( * ) e,
complex, dimension( ldvt, * ) vt,
integer ldvt,
complex, dimension( ldu, * ) u,
integer ldu,
complex, dimension( ldc, * ) c,
integer ldc,
real, dimension( * ) rwork,
integer info )

CBDSQR

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

Purpose:
!>
!> CBDSQR computes the singular values and, optionally, the right and/or
!> left singular vectors from the singular value decomposition (SVD) of
!> a real N-by-N (upper or lower) bidiagonal matrix B using the implicit
!> zero-shift QR algorithm.  The SVD of B has the form
!>
!>    B = Q * S * P**H
!>
!> where S is the diagonal matrix of singular values, Q is an orthogonal
!> matrix of left singular vectors, and P is an orthogonal matrix of
!> right singular vectors.  If left singular vectors are requested, this
!> subroutine actually returns U*Q instead of Q, and, if right singular
!> vectors are requested, this subroutine returns P**H*VT instead of
!> P**H, for given complex input matrices U and VT.  When U and VT are
!> the unitary matrices that reduce a general matrix A to bidiagonal
!> form: A = U*B*VT, as computed by CGEBRD, then
!>
!>    A = (U*Q) * S * (P**H*VT)
!>
!> is the SVD of A.  Optionally, the subroutine may also compute Q**H*C
!> for a given complex input matrix C.
!>
!> See  by J. Demmel and W. Kahan,
!> LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11,
!> no. 5, pp. 873-912, Sept 1990) and
!>  by
!> B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics
!> Department, University of California at Berkeley, July 1992
!> for a detailed description of the algorithm.
!> 
Parameters
[in]UPLO
!>          UPLO is CHARACTER*1
!>          = 'U':  B is upper bidiagonal;
!>          = 'L':  B is lower bidiagonal.
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix B.  N >= 0.
!> 
[in]NCVT
!>          NCVT is INTEGER
!>          The number of columns of the matrix VT. NCVT >= 0.
!> 
[in]NRU
!>          NRU is INTEGER
!>          The number of rows of the matrix U. NRU >= 0.
!> 
[in]NCC
!>          NCC is INTEGER
!>          The number of columns of the matrix C. NCC >= 0.
!> 
[in,out]D
!>          D is REAL array, dimension (N)
!>          On entry, the n diagonal elements of the bidiagonal matrix B.
!>          On exit, if INFO=0, the singular values of B in decreasing
!>          order.
!> 
[in,out]E
!>          E is REAL array, dimension (N-1)
!>          On entry, the N-1 offdiagonal elements of the bidiagonal
!>          matrix B.
!>          On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E
!>          will contain the diagonal and superdiagonal elements of a
!>          bidiagonal matrix orthogonally equivalent to the one given
!>          as input.
!> 
[in,out]VT
!>          VT is COMPLEX array, dimension (LDVT, NCVT)
!>          On entry, an N-by-NCVT matrix VT.
!>          On exit, VT is overwritten by P**H * VT.
!>          Not referenced if NCVT = 0.
!> 
[in]LDVT
!>          LDVT is INTEGER
!>          The leading dimension of the array VT.
!>          LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0.
!> 
[in,out]U
!>          U is COMPLEX array, dimension (LDU, N)
!>          On entry, an NRU-by-N matrix U.
!>          On exit, U is overwritten by U * Q.
!>          Not referenced if NRU = 0.
!> 
[in]LDU
!>          LDU is INTEGER
!>          The leading dimension of the array U.  LDU >= max(1,NRU).
!> 
[in,out]C
!>          C is COMPLEX array, dimension (LDC, NCC)
!>          On entry, an N-by-NCC matrix C.
!>          On exit, C is overwritten by Q**H * C.
!>          Not referenced if NCC = 0.
!> 
[in]LDC
!>          LDC is INTEGER
!>          The leading dimension of the array C.
!>          LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0.
!> 
[out]RWORK
!>          RWORK is REAL array, dimension (LRWORK)
!>          LRWORK = 4*N, if NCVT = NRU = NCC = 0, and
!>          LRWORK = 4*(N-1), otherwise
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  If INFO = -i, the i-th argument had an illegal value
!>          > 0:  the algorithm did not converge; D and E contain the
!>                elements of a bidiagonal matrix which is orthogonally
!>                similar to the input matrix B;  if INFO = i, i
!>                elements of E have not converged to zero.
!> 
Internal Parameters:
!>  TOLMUL  REAL, default = max(10,min(100,EPS**(-1/8)))
!>          TOLMUL controls the convergence criterion of the QR loop.
!>          If it is positive, TOLMUL*EPS is the desired relative
!>             precision in the computed singular values.
!>          If it is negative, abs(TOLMUL*EPS*sigma_max) is the
!>             desired absolute accuracy in the computed singular
!>             values (corresponds to relative accuracy
!>             abs(TOLMUL*EPS) in the largest singular value.
!>          abs(TOLMUL) should be between 1 and 1/EPS, and preferably
!>             between 10 (for fast convergence) and .1/EPS
!>             (for there to be some accuracy in the results).
!>          Default is to lose at either one eighth or 2 of the
!>             available decimal digits in each computed singular value
!>             (whichever is smaller).
!>
!>  MAXITR  INTEGER, default = 6
!>          MAXITR controls the maximum number of passes of the
!>          algorithm through its inner loop. The algorithms stops
!>          (and so fails to converge) if the number of passes
!>          through the inner loop exceeds MAXITR*N**2.
!>
!> 
Note:
!>  Bug report from Cezary Dendek.
!>  On November 3rd 2023, the INTEGER variable MAXIT = MAXITR*N**2 is
!>  removed since it can overflow pretty easily (for N larger or equal
!>  than 18,919). We instead use MAXITDIVN = MAXITR*N.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 231 of file cbdsqr.f.

233*
234* -- LAPACK computational routine --
235* -- LAPACK is a software package provided by Univ. of Tennessee, --
236* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
237*
238* .. Scalar Arguments ..
239 CHARACTER UPLO
240 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
241* ..
242* .. Array Arguments ..
243 REAL D( * ), E( * ), RWORK( * )
244 COMPLEX C( LDC, * ), U( LDU, * ), VT( LDVT, * )
245* ..
246*
247* =====================================================================
248*
249* .. Parameters ..
250 REAL ZERO
251 parameter( zero = 0.0e0 )
252 REAL ONE
253 parameter( one = 1.0e0 )
254 REAL NEGONE
255 parameter( negone = -1.0e0 )
256 REAL HNDRTH
257 parameter( hndrth = 0.01e0 )
258 REAL TEN
259 parameter( ten = 10.0e0 )
260 REAL HNDRD
261 parameter( hndrd = 100.0e0 )
262 REAL MEIGTH
263 parameter( meigth = -0.125e0 )
264 INTEGER MAXITR
265 parameter( maxitr = 6 )
266* ..
267* .. Local Scalars ..
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
275* ..
276* .. External Functions ..
277 LOGICAL LSAME
278 REAL SLAMCH
279 EXTERNAL lsame, slamch
280* ..
281* .. External Subroutines ..
282 EXTERNAL clasr, csrot, csscal, cswap, slartg,
283 $ slas2,
285* ..
286* .. Intrinsic Functions ..
287 INTRINSIC abs, max, min, real, sign, sqrt
288* ..
289* .. Executable Statements ..
290*
291* Test the input parameters.
292*
293 info = 0
294 lower = lsame( uplo, 'L' )
295 IF( .NOT.lsame( uplo, 'U' ) .AND. .NOT.lower ) THEN
296 info = -1
297 ELSE IF( n.LT.0 ) THEN
298 info = -2
299 ELSE IF( ncvt.LT.0 ) THEN
300 info = -3
301 ELSE IF( nru.LT.0 ) THEN
302 info = -4
303 ELSE IF( ncc.LT.0 ) THEN
304 info = -5
305 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
306 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) ) THEN
307 info = -9
308 ELSE IF( ldu.LT.max( 1, nru ) ) THEN
309 info = -11
310 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
311 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) ) THEN
312 info = -13
313 END IF
314 IF( info.NE.0 ) THEN
315 CALL xerbla( 'CBDSQR', -info )
316 RETURN
317 END IF
318 IF( n.EQ.0 )
319 $ RETURN
320 IF( n.EQ.1 )
321 $ GO TO 160
322*
323* ROTATE is true if any singular vectors desired, false otherwise
324*
325 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
326*
327* If no singular vectors desired, use qd algorithm
328*
329 IF( .NOT.rotate ) THEN
330 CALL slasq1( n, d, e, rwork, info )
331*
332* If INFO equals 2, dqds didn't finish, try to finish
333*
334 IF( info .NE. 2 ) RETURN
335 info = 0
336 END IF
337*
338 nm1 = n - 1
339 nm12 = nm1 + nm1
340 nm13 = nm12 + nm1
341 idir = 0
342*
343* Get machine constants
344*
345 eps = slamch( 'Epsilon' )
346 unfl = slamch( 'Safe minimum' )
347*
348* If matrix lower bidiagonal, rotate to be upper bidiagonal
349* by applying Givens rotations on the left
350*
351 IF( lower ) THEN
352 DO 10 i = 1, n - 1
353 CALL slartg( d( i ), e( i ), cs, sn, r )
354 d( i ) = r
355 e( i ) = sn*d( i+1 )
356 d( i+1 ) = cs*d( i+1 )
357 rwork( i ) = cs
358 rwork( nm1+i ) = sn
359 10 CONTINUE
360*
361* Update singular vectors if desired
362*
363 IF( nru.GT.0 )
364 $ CALL clasr( 'R', 'V', 'F', nru, n, rwork( 1 ),
365 $ rwork( n ),
366 $ u, ldu )
367 IF( ncc.GT.0 )
368 $ CALL clasr( 'L', 'V', 'F', n, ncc, rwork( 1 ),
369 $ rwork( n ),
370 $ c, ldc )
371 END IF
372*
373* Compute singular values to relative accuracy TOL
374* (By setting TOL to be negative, algorithm will compute
375* singular values to absolute accuracy ABS(TOL)*norm(input matrix))
376*
377 tolmul = max( ten, min( hndrd, eps**meigth ) )
378 tol = tolmul*eps
379*
380* Compute approximate maximum, minimum singular values
381*
382 smax = zero
383 DO 20 i = 1, n
384 smax = max( smax, abs( d( i ) ) )
385 20 CONTINUE
386 DO 30 i = 1, n - 1
387 smax = max( smax, abs( e( i ) ) )
388 30 CONTINUE
389 smin = zero
390 IF( tol.GE.zero ) THEN
391*
392* Relative accuracy desired
393*
394 sminoa = abs( d( 1 ) )
395 IF( sminoa.EQ.zero )
396 $ GO TO 50
397 mu = sminoa
398 DO 40 i = 2, n
399 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
400 sminoa = min( sminoa, mu )
401 IF( sminoa.EQ.zero )
402 $ GO TO 50
403 40 CONTINUE
404 50 CONTINUE
405 sminoa = sminoa / sqrt( real( n ) )
406 thresh = max( tol*sminoa,
407 $ real(maxitr)*(real(n)*(real(n)*unfl)) )
408 ELSE
409*
410* Absolute accuracy desired
411*
412 thresh = max( abs( tol )*smax,
413 $ real(maxitr)*(real(n)*(real(n)*unfl)) )
414 END IF
415*
416* Prepare for main iteration loop for the singular values
417* (MAXIT is the maximum number of passes through the inner
418* loop permitted before nonconvergence signalled.)
419*
420 maxitdivn = maxitr*n
421 iterdivn = 0
422 iter = -1
423 oldll = -1
424 oldm = -1
425*
426* M points to last element of unconverged part of matrix
427*
428 m = n
429*
430* Begin main iteration loop
431*
432 60 CONTINUE
433*
434* Check for convergence or exceeding iteration count
435*
436 IF( m.LE.1 )
437 $ GO TO 160
438 IF( iter.GE.n ) THEN
439 iter = iter - n
440 iterdivn = iterdivn + 1
441 IF( iterdivn.GE.maxitdivn )
442 $ GO TO 200
443 END IF
444*
445* Find diagonal block of matrix to work on
446*
447 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
448 $ d( m ) = zero
449 smax = abs( d( m ) )
450 DO 70 lll = 1, m - 1
451 ll = m - lll
452 abss = abs( d( ll ) )
453 abse = abs( e( ll ) )
454 IF( tol.LT.zero .AND. abss.LE.thresh )
455 $ d( ll ) = zero
456 IF( abse.LE.thresh )
457 $ GO TO 80
458 smax = max( smax, abss, abse )
459 70 CONTINUE
460 ll = 0
461 GO TO 90
462 80 CONTINUE
463 e( ll ) = zero
464*
465* Matrix splits since E(LL) = 0
466*
467 IF( ll.EQ.m-1 ) THEN
468*
469* Convergence of bottom singular value, return to top of loop
470*
471 m = m - 1
472 GO TO 60
473 END IF
474 90 CONTINUE
475 ll = ll + 1
476*
477* E(LL) through E(M-1) are nonzero, E(LL-1) is zero
478*
479 IF( ll.EQ.m-1 ) THEN
480*
481* 2 by 2 block, handle separately
482*
483 CALL slasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
484 $ cosr, sinl, cosl )
485 d( m-1 ) = sigmx
486 e( m-1 ) = zero
487 d( m ) = sigmn
488*
489* Compute singular vectors, if desired
490*
491 IF( ncvt.GT.0 )
492 $ CALL csrot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt,
493 $ cosr, sinr )
494 IF( nru.GT.0 )
495 $ CALL csrot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl,
496 $ sinl )
497 IF( ncc.GT.0 )
498 $ CALL csrot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
499 $ sinl )
500 m = m - 2
501 GO TO 60
502 END IF
503*
504* If working on new submatrix, choose shift direction
505* (from larger end diagonal element towards smaller)
506*
507 IF( ll.GT.oldm .OR. m.LT.oldll ) THEN
508 IF( abs( d( ll ) ).GE.abs( d( m ) ) ) THEN
509*
510* Chase bulge from top (big end) to bottom (small end)
511*
512 idir = 1
513 ELSE
514*
515* Chase bulge from bottom (big end) to top (small end)
516*
517 idir = 2
518 END IF
519 END IF
520*
521* Apply convergence tests
522*
523 IF( idir.EQ.1 ) THEN
524*
525* Run convergence test in forward direction
526* First apply standard test to bottom of matrix
527*
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
530 e( m-1 ) = zero
531 GO TO 60
532 END IF
533*
534 IF( tol.GE.zero ) THEN
535*
536* If relative accuracy desired,
537* apply convergence criterion forward
538*
539 mu = abs( d( ll ) )
540 smin = mu
541 DO 100 lll = ll, m - 1
542 IF( abs( e( lll ) ).LE.tol*mu ) THEN
543 e( lll ) = zero
544 GO TO 60
545 END IF
546 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
547 smin = min( smin, mu )
548 100 CONTINUE
549 END IF
550*
551 ELSE
552*
553* Run convergence test in backward direction
554* First apply standard test to top of matrix
555*
556 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
557 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) ) THEN
558 e( ll ) = zero
559 GO TO 60
560 END IF
561*
562 IF( tol.GE.zero ) THEN
563*
564* If relative accuracy desired,
565* apply convergence criterion backward
566*
567 mu = abs( d( m ) )
568 smin = mu
569 DO 110 lll = m - 1, ll, -1
570 IF( abs( e( lll ) ).LE.tol*mu ) THEN
571 e( lll ) = zero
572 GO TO 60
573 END IF
574 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
575 smin = min( smin, mu )
576 110 CONTINUE
577 END IF
578 END IF
579 oldll = ll
580 oldm = m
581*
582* Compute shift. First, test if shifting would ruin relative
583* accuracy, and if so set the shift to zero.
584*
585 IF( tol.GE.zero .AND. real( n )*tol*( smin / smax ).LE.
586 $ max( eps, hndrth*tol ) ) THEN
587*
588* Use a zero shift to avoid loss of relative accuracy
589*
590 shift = zero
591 ELSE
592*
593* Compute the shift from 2-by-2 block at end of matrix
594*
595 IF( idir.EQ.1 ) THEN
596 sll = abs( d( ll ) )
597 CALL slas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
598 ELSE
599 sll = abs( d( m ) )
600 CALL slas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
601 END IF
602*
603* Test if shift negligible, and if so set to zero
604*
605 IF( sll.GT.zero ) THEN
606 IF( ( shift / sll )**2.LT.eps )
607 $ shift = zero
608 END IF
609 END IF
610*
611* Increment iteration count
612*
613 iter = iter + m - ll
614*
615* If SHIFT = 0, do simplified QR iteration
616*
617 IF( shift.EQ.zero ) THEN
618 IF( idir.EQ.1 ) THEN
619*
620* Chase bulge from top to bottom
621* Save cosines and sines for later singular vector updates
622*
623 cs = one
624 oldcs = one
625 DO 120 i = ll, m - 1
626 CALL slartg( d( i )*cs, e( i ), cs, sn, r )
627 IF( i.GT.ll )
628 $ e( i-1 ) = oldsn*r
629 CALL slartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn,
630 $ d( i ) )
631 rwork( i-ll+1 ) = cs
632 rwork( i-ll+1+nm1 ) = sn
633 rwork( i-ll+1+nm12 ) = oldcs
634 rwork( i-ll+1+nm13 ) = oldsn
635 120 CONTINUE
636 h = d( m )*cs
637 d( m ) = h*oldcs
638 e( m-1 ) = h*oldsn
639*
640* Update singular vectors
641*
642 IF( ncvt.GT.0 )
643 $ CALL clasr( 'L', 'V', 'F', m-ll+1, ncvt, rwork( 1 ),
644 $ rwork( n ), vt( ll, 1 ), ldvt )
645 IF( nru.GT.0 )
646 $ CALL clasr( 'R', 'V', 'F', nru, m-ll+1,
647 $ rwork( nm12+1 ),
648 $ rwork( nm13+1 ), u( 1, ll ), ldu )
649 IF( ncc.GT.0 )
650 $ CALL clasr( 'L', 'V', 'F', m-ll+1, ncc,
651 $ rwork( nm12+1 ),
652 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
653*
654* Test convergence
655*
656 IF( abs( e( m-1 ) ).LE.thresh )
657 $ e( m-1 ) = zero
658*
659 ELSE
660*
661* Chase bulge from bottom to top
662* Save cosines and sines for later singular vector updates
663*
664 cs = one
665 oldcs = one
666 DO 130 i = m, ll + 1, -1
667 CALL slartg( d( i )*cs, e( i-1 ), cs, sn, r )
668 IF( i.LT.m )
669 $ e( i ) = oldsn*r
670 CALL slartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn,
671 $ d( i ) )
672 rwork( i-ll ) = cs
673 rwork( i-ll+nm1 ) = -sn
674 rwork( i-ll+nm12 ) = oldcs
675 rwork( i-ll+nm13 ) = -oldsn
676 130 CONTINUE
677 h = d( ll )*cs
678 d( ll ) = h*oldcs
679 e( ll ) = h*oldsn
680*
681* Update singular vectors
682*
683 IF( ncvt.GT.0 )
684 $ CALL clasr( 'L', 'V', 'B', m-ll+1, ncvt,
685 $ rwork( nm12+1 ),
686 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
687 IF( nru.GT.0 )
688 $ CALL clasr( 'R', 'V', 'B', nru, m-ll+1, rwork( 1 ),
689 $ rwork( n ), u( 1, ll ), ldu )
690 IF( ncc.GT.0 )
691 $ CALL clasr( 'L', 'V', 'B', m-ll+1, ncc, rwork( 1 ),
692 $ rwork( n ), c( ll, 1 ), ldc )
693*
694* Test convergence
695*
696 IF( abs( e( ll ) ).LE.thresh )
697 $ e( ll ) = zero
698 END IF
699 ELSE
700*
701* Use nonzero shift
702*
703 IF( idir.EQ.1 ) THEN
704*
705* Chase bulge from top to bottom
706* Save cosines and sines for later singular vector updates
707*
708 f = ( abs( d( ll ) )-shift )*
709 $ ( sign( one, d( ll ) )+shift / d( ll ) )
710 g = e( ll )
711 DO 140 i = ll, m - 1
712 CALL slartg( f, g, cosr, sinr, r )
713 IF( i.GT.ll )
714 $ e( i-1 ) = r
715 f = cosr*d( i ) + sinr*e( i )
716 e( i ) = cosr*e( i ) - sinr*d( i )
717 g = sinr*d( i+1 )
718 d( i+1 ) = cosr*d( i+1 )
719 CALL slartg( f, g, cosl, sinl, r )
720 d( i ) = r
721 f = cosl*e( i ) + sinl*d( i+1 )
722 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
723 IF( i.LT.m-1 ) THEN
724 g = sinl*e( i+1 )
725 e( i+1 ) = cosl*e( i+1 )
726 END IF
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
731 140 CONTINUE
732 e( m-1 ) = f
733*
734* Update singular vectors
735*
736 IF( ncvt.GT.0 )
737 $ CALL clasr( 'L', 'V', 'F', m-ll+1, ncvt, rwork( 1 ),
738 $ rwork( n ), vt( ll, 1 ), ldvt )
739 IF( nru.GT.0 )
740 $ CALL clasr( 'R', 'V', 'F', nru, m-ll+1,
741 $ rwork( nm12+1 ),
742 $ rwork( nm13+1 ), u( 1, ll ), ldu )
743 IF( ncc.GT.0 )
744 $ CALL clasr( 'L', 'V', 'F', m-ll+1, ncc,
745 $ rwork( nm12+1 ),
746 $ rwork( nm13+1 ), c( ll, 1 ), ldc )
747*
748* Test convergence
749*
750 IF( abs( e( m-1 ) ).LE.thresh )
751 $ e( m-1 ) = zero
752*
753 ELSE
754*
755* Chase bulge from bottom to top
756* Save cosines and sines for later singular vector updates
757*
758 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
759 $ d( m ) )
760 g = e( m-1 )
761 DO 150 i = m, ll + 1, -1
762 CALL slartg( f, g, cosr, sinr, r )
763 IF( i.LT.m )
764 $ e( i ) = r
765 f = cosr*d( i ) + sinr*e( i-1 )
766 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
767 g = sinr*d( i-1 )
768 d( i-1 ) = cosr*d( i-1 )
769 CALL slartg( f, g, cosl, sinl, r )
770 d( i ) = r
771 f = cosl*e( i-1 ) + sinl*d( i-1 )
772 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
773 IF( i.GT.ll+1 ) THEN
774 g = sinl*e( i-2 )
775 e( i-2 ) = cosl*e( i-2 )
776 END IF
777 rwork( i-ll ) = cosr
778 rwork( i-ll+nm1 ) = -sinr
779 rwork( i-ll+nm12 ) = cosl
780 rwork( i-ll+nm13 ) = -sinl
781 150 CONTINUE
782 e( ll ) = f
783*
784* Test convergence
785*
786 IF( abs( e( ll ) ).LE.thresh )
787 $ e( ll ) = zero
788*
789* Update singular vectors if desired
790*
791 IF( ncvt.GT.0 )
792 $ CALL clasr( 'L', 'V', 'B', m-ll+1, ncvt,
793 $ rwork( nm12+1 ),
794 $ rwork( nm13+1 ), vt( ll, 1 ), ldvt )
795 IF( nru.GT.0 )
796 $ CALL clasr( 'R', 'V', 'B', nru, m-ll+1, rwork( 1 ),
797 $ rwork( n ), u( 1, ll ), ldu )
798 IF( ncc.GT.0 )
799 $ CALL clasr( 'L', 'V', 'B', m-ll+1, ncc, rwork( 1 ),
800 $ rwork( n ), c( ll, 1 ), ldc )
801 END IF
802 END IF
803*
804* QR iteration finished, go back and check convergence
805*
806 GO TO 60
807*
808* All singular values converged, so make them positive
809*
810 160 CONTINUE
811 DO 170 i = 1, n
812 IF( d( i ).EQ.zero ) THEN
813*
814* Avoid -ZERO
815*
816 d( i ) = zero
817 END IF
818 IF( d( i ).LT.zero ) THEN
819 d( i ) = -d( i )
820*
821* Change sign of singular vectors, if desired
822*
823 IF( ncvt.GT.0 )
824 $ CALL csscal( ncvt, negone, vt( i, 1 ), ldvt )
825 END IF
826 170 CONTINUE
827*
828* Sort the singular values into decreasing order (insertion sort on
829* singular values, but only one transposition per singular vector)
830*
831 DO 190 i = 1, n - 1
832*
833* Scan for smallest D(I)
834*
835 isub = 1
836 smin = d( 1 )
837 DO 180 j = 2, n + 1 - i
838 IF( d( j ).LE.smin ) THEN
839 isub = j
840 smin = d( j )
841 END IF
842 180 CONTINUE
843 IF( isub.NE.n+1-i ) THEN
844*
845* Swap singular values and vectors
846*
847 d( isub ) = d( n+1-i )
848 d( n+1-i ) = smin
849 IF( ncvt.GT.0 )
850 $ CALL cswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
851 $ ldvt )
852 IF( nru.GT.0 )
853 $ CALL cswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
854 IF( ncc.GT.0 )
855 $ CALL cswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ),
856 $ ldc )
857 END IF
858 190 CONTINUE
859 GO TO 220
860*
861* Maximum number of iterations exceeded, failure to converge
862*
863 200 CONTINUE
864 info = 0
865 DO 210 i = 1, n - 1
866 IF( e( i ).NE.zero )
867 $ info = info + 1
868 210 CONTINUE
869 220 CONTINUE
870 RETURN
871*
872* End of CBDSQR
873*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
subroutine slartg(f, g, c, s, r)
SLARTG generates a plane rotation with real cosine and real sine.
Definition slartg.f90:111
subroutine slas2(f, g, h, ssmin, ssmax)
SLAS2 computes singular values of a 2-by-2 triangular matrix.
Definition slas2.f:103
subroutine slasq1(n, d, e, work, info)
SLASQ1 computes the singular values of a real square bidiagonal matrix. Used by sbdsqr.
Definition slasq1.f:106
subroutine clasr(side, pivot, direct, m, n, c, s, a, lda)
CLASR applies a sequence of plane rotations to a general rectangular matrix.
Definition clasr.f:198
subroutine slasv2(f, g, h, ssmin, ssmax, snr, csr, snl, csl)
SLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
Definition slasv2.f:134
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine csrot(n, cx, incx, cy, incy, c, s)
CSROT
Definition csrot.f:98
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
Definition cswap.f:81
Here is the call graph for this function:
Here is the caller graph for this function: