241
242
243
244
245
246
247 CHARACTER UPLO
248 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
249
250
251 DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
252 $ VT( LDVT, * ), WORK( * )
253
254
255
256
257
258 DOUBLE PRECISION ZERO
259 parameter( zero = 0.0d0 )
260 DOUBLE PRECISION ONE
261 parameter( one = 1.0d0 )
262 DOUBLE PRECISION NEGONE
263 parameter( negone = -1.0d0 )
264 DOUBLE PRECISION HNDRTH
265 parameter( hndrth = 0.01d0 )
266 DOUBLE PRECISION TEN
267 parameter( ten = 10.0d0 )
268 DOUBLE PRECISION HNDRD
269 parameter( hndrd = 100.0d0 )
270 DOUBLE PRECISION MEIGTH
271 parameter( meigth = -0.125d0 )
272 INTEGER MAXITR
273 parameter( maxitr = 6 )
274
275
276 LOGICAL LOWER, ROTATE
277 INTEGER I, IDIR, ISUB, ITER, ITERDIVN, J, LL, LLL, M,
278 $ MAXITDIVN, NM1, NM12, NM13, OLDLL, OLDM
279 DOUBLE PRECISION ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
280 $ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL,
281 $ SINR, SLL, SMAX, SMIN, SMINOA,
282 $ SN, THRESH, TOL, TOLMUL, UNFL
283
284
285 LOGICAL LSAME
286 DOUBLE PRECISION DLAMCH
288
289
292
293
294 INTRINSIC abs, dble, max, min, sign, sqrt
295
296
297
298
299
300 info = 0
301 lower =
lsame( uplo,
'L' )
302 IF( .NOT.
lsame( uplo,
'U' ) .AND. .NOT.lower )
THEN
303 info = -1
304 ELSE IF( n.LT.0 ) THEN
305 info = -2
306 ELSE IF( ncvt.LT.0 ) THEN
307 info = -3
308 ELSE IF( nru.LT.0 ) THEN
309 info = -4
310 ELSE IF( ncc.LT.0 ) THEN
311 info = -5
312 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
313 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) ) THEN
314 info = -9
315 ELSE IF( ldu.LT.max( 1, nru ) ) THEN
316 info = -11
317 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
318 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) ) THEN
319 info = -13
320 END IF
321 IF( info.NE.0 ) THEN
322 CALL xerbla(
'DBDSQR', -info )
323 RETURN
324 END IF
325 IF( n.EQ.0 )
326 $ RETURN
327 IF( n.EQ.1 )
328 $ GO TO 160
329
330
331
332 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
333
334
335
336 IF( .NOT.rotate ) THEN
337 CALL dlasq1( n, d, e, work, info )
338
339
340
341 IF( info .NE. 2 ) RETURN
342 info = 0
343 END IF
344
345 nm1 = n - 1
346 nm12 = nm1 + nm1
347 nm13 = nm12 + nm1
348 idir = 0
349
350
351
353 unfl =
dlamch(
'Safe minimum' )
354
355
356
357
358 IF( lower ) THEN
359 DO 10 i = 1, n - 1
360 CALL dlartg( d( i ), e( i ), cs, sn, r )
361 d( i ) = r
362 e( i ) = sn*d( i+1 )
363 d( i+1 ) = cs*d( i+1 )
364 work( i ) = cs
365 work( nm1+i ) = sn
366 10 CONTINUE
367
368
369
370 IF( nru.GT.0 )
371 $
CALL dlasr(
'R',
'V',
'F', nru, n, work( 1 ), work( n ), u,
372 $ ldu )
373 IF( ncc.GT.0 )
374 $
CALL dlasr(
'L',
'V',
'F', n, ncc, work( 1 ), work( n ), c,
375 $ ldc )
376 END IF
377
378
379
380
381
382 tolmul = max( ten, min( hndrd, eps**meigth ) )
383 tol = tolmul*eps
384
385
386
387 smax = zero
388 DO 20 i = 1, n
389 smax = max( smax, abs( d( i ) ) )
390 20 CONTINUE
391 DO 30 i = 1, n - 1
392 smax = max( smax, abs( e( i ) ) )
393 30 CONTINUE
394 smin = zero
395 IF( tol.GE.zero ) THEN
396
397
398
399 sminoa = abs( d( 1 ) )
400 IF( sminoa.EQ.zero )
401 $ GO TO 50
402 mu = sminoa
403 DO 40 i = 2, n
404 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
405 sminoa = min( sminoa, mu )
406 IF( sminoa.EQ.zero )
407 $ GO TO 50
408 40 CONTINUE
409 50 CONTINUE
410 sminoa = sminoa / sqrt( dble( n ) )
411 thresh = max( tol*sminoa, maxitr*(n*(n*unfl)) )
412 ELSE
413
414
415
416 thresh = max( abs( tol )*smax, maxitr*(n*(n*unfl)) )
417 END IF
418
419
420
421
422
423 maxitdivn = maxitr*n
424 iterdivn = 0
425 iter = -1
426 oldll = -1
427 oldm = -1
428
429
430
431 m = n
432
433
434
435 60 CONTINUE
436
437
438
439 IF( m.LE.1 )
440 $ GO TO 160
441
442 IF( iter.GE.n ) THEN
443 iter = iter - n
444 iterdivn = iterdivn + 1
445 IF( iterdivn.GE.maxitdivn )
446 $ GO TO 200
447 END IF
448
449
450
451 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
452 $ d( m ) = zero
453 smax = abs( d( m ) )
454 DO 70 lll = 1, m - 1
455 ll = m - lll
456 abss = abs( d( ll ) )
457 abse = abs( e( ll ) )
458 IF( tol.LT.zero .AND. abss.LE.thresh )
459 $ d( ll ) = zero
460 IF( abse.LE.thresh )
461 $ GO TO 80
462 smax = max( smax, abss, abse )
463 70 CONTINUE
464 ll = 0
465 GO TO 90
466 80 CONTINUE
467 e( ll ) = zero
468
469
470
471 IF( ll.EQ.m-1 ) THEN
472
473
474
475 m = m - 1
476 GO TO 60
477 END IF
478 90 CONTINUE
479 ll = ll + 1
480
481
482
483 IF( ll.EQ.m-1 ) THEN
484
485
486
487 CALL dlasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
488 $ cosr, sinl, cosl )
489 d( m-1 ) = sigmx
490 e( m-1 ) = zero
491 d( m ) = sigmn
492
493
494
495 IF( ncvt.GT.0 )
496 $
CALL drot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt, cosr,
497 $ sinr )
498 IF( nru.GT.0 )
499 $
CALL drot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl, sinl )
500 IF( ncc.GT.0 )
501 $
CALL drot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
502 $ sinl )
503 m = m - 2
504 GO TO 60
505 END IF
506
507
508
509
510 IF( ll.GT.oldm .OR. m.LT.oldll ) THEN
511 IF( abs( d( ll ) ).GE.abs( d( m ) ) ) THEN
512
513
514
515 idir = 1
516 ELSE
517
518
519
520 idir = 2
521 END IF
522 END IF
523
524
525
526 IF( idir.EQ.1 ) THEN
527
528
529
530
531 IF( abs( e( m-1 ) ).LE.abs( tol )*abs( d( m ) ) .OR.
532 $ ( tol.LT.zero .AND. abs( e( m-1 ) ).LE.thresh ) ) THEN
533 e( m-1 ) = zero
534 GO TO 60
535 END IF
536
537 IF( tol.GE.zero ) THEN
538
539
540
541
542 mu = abs( d( ll ) )
543 smin = mu
544 DO 100 lll = ll, m - 1
545 IF( abs( e( lll ) ).LE.tol*mu ) THEN
546 e( lll ) = zero
547 GO TO 60
548 END IF
549 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
550 smin = min( smin, mu )
551 100 CONTINUE
552 END IF
553
554 ELSE
555
556
557
558
559 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
560 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) ) THEN
561 e( ll ) = zero
562 GO TO 60
563 END IF
564
565 IF( tol.GE.zero ) THEN
566
567
568
569
570 mu = abs( d( m ) )
571 smin = mu
572 DO 110 lll = m - 1, ll, -1
573 IF( abs( e( lll ) ).LE.tol*mu ) THEN
574 e( lll ) = zero
575 GO TO 60
576 END IF
577 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
578 smin = min( smin, mu )
579 110 CONTINUE
580 END IF
581 END IF
582 oldll = ll
583 oldm = m
584
585
586
587
588 IF( tol.GE.zero .AND. n*tol*( smin / smax ).LE.
589 $ max( eps, hndrth*tol ) ) THEN
590
591
592
593 shift = zero
594 ELSE
595
596
597
598 IF( idir.EQ.1 ) THEN
599 sll = abs( d( ll ) )
600 CALL dlas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
601 ELSE
602 sll = abs( d( m ) )
603 CALL dlas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
604 END IF
605
606
607
608 IF( sll.GT.zero ) THEN
609 IF( ( shift / sll )**2.LT.eps )
610 $ shift = zero
611 END IF
612 END IF
613
614
615
616 iter = iter + m - ll
617
618
619
620 IF( shift.EQ.zero ) THEN
621 IF( idir.EQ.1 ) THEN
622
623
624
625
626 cs = one
627 oldcs = one
628 DO 120 i = ll, m - 1
629 CALL dlartg( d( i )*cs, e( i ), cs, sn, r )
630 IF( i.GT.ll )
631 $ e( i-1 ) = oldsn*r
632 CALL dlartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn, d( i ) )
633 work( i-ll+1 ) = cs
634 work( i-ll+1+nm1 ) = sn
635 work( i-ll+1+nm12 ) = oldcs
636 work( i-ll+1+nm13 ) = oldsn
637 120 CONTINUE
638 h = d( m )*cs
639 d( m ) = h*oldcs
640 e( m-1 ) = h*oldsn
641
642
643
644 IF( ncvt.GT.0 )
645 $
CALL dlasr(
'L',
'V',
'F', m-ll+1, ncvt, work( 1 ),
646 $ work( n ), vt( ll, 1 ), ldvt )
647 IF( nru.GT.0 )
648 $
CALL dlasr(
'R',
'V',
'F', nru, m-ll+1, work( nm12+1 ),
649 $ work( nm13+1 ), u( 1, ll ), ldu )
650 IF( ncc.GT.0 )
651 $
CALL dlasr(
'L',
'V',
'F', m-ll+1, ncc, work( nm12+1 ),
652 $ work( nm13+1 ), c( ll, 1 ), ldc )
653
654
655
656 IF( abs( e( m-1 ) ).LE.thresh )
657 $ e( m-1 ) = zero
658
659 ELSE
660
661
662
663
664 cs = one
665 oldcs = one
666 DO 130 i = m, ll + 1, -1
667 CALL dlartg( d( i )*cs, e( i-1 ), cs, sn, r )
668 IF( i.LT.m )
669 $ e( i ) = oldsn*r
670 CALL dlartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn, d( i ) )
671 work( i-ll ) = cs
672 work( i-ll+nm1 ) = -sn
673 work( i-ll+nm12 ) = oldcs
674 work( i-ll+nm13 ) = -oldsn
675 130 CONTINUE
676 h = d( ll )*cs
677 d( ll ) = h*oldcs
678 e( ll ) = h*oldsn
679
680
681
682 IF( ncvt.GT.0 )
683 $
CALL dlasr(
'L',
'V',
'B', m-ll+1, ncvt, work( nm12+1 ),
684 $ work( nm13+1 ), vt( ll, 1 ), ldvt )
685 IF( nru.GT.0 )
686 $
CALL dlasr(
'R',
'V',
'B', nru, m-ll+1, work( 1 ),
687 $ work( n ), u( 1, ll ), ldu )
688 IF( ncc.GT.0 )
689 $
CALL dlasr(
'L',
'V',
'B', m-ll+1, ncc, work( 1 ),
690 $ work( n ), c( ll, 1 ), ldc )
691
692
693
694 IF( abs( e( ll ) ).LE.thresh )
695 $ e( ll ) = zero
696 END IF
697 ELSE
698
699
700
701 IF( idir.EQ.1 ) THEN
702
703
704
705
706 f = ( abs( d( ll ) )-shift )*
707 $ ( sign( one, d( ll ) )+shift / d( ll ) )
708 g = e( ll )
709 DO 140 i = ll, m - 1
710 CALL dlartg( f, g, cosr, sinr, r )
711 IF( i.GT.ll )
712 $ e( i-1 ) = r
713 f = cosr*d( i ) + sinr*e( i )
714 e( i ) = cosr*e( i ) - sinr*d( i )
715 g = sinr*d( i+1 )
716 d( i+1 ) = cosr*d( i+1 )
717 CALL dlartg( f, g, cosl, sinl, r )
718 d( i ) = r
719 f = cosl*e( i ) + sinl*d( i+1 )
720 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
721 IF( i.LT.m-1 ) THEN
722 g = sinl*e( i+1 )
723 e( i+1 ) = cosl*e( i+1 )
724 END IF
725 work( i-ll+1 ) = cosr
726 work( i-ll+1+nm1 ) = sinr
727 work( i-ll+1+nm12 ) = cosl
728 work( i-ll+1+nm13 ) = sinl
729 140 CONTINUE
730 e( m-1 ) = f
731
732
733
734 IF( ncvt.GT.0 )
735 $
CALL dlasr(
'L',
'V',
'F', m-ll+1, ncvt, work( 1 ),
736 $ work( n ), vt( ll, 1 ), ldvt )
737 IF( nru.GT.0 )
738 $
CALL dlasr(
'R',
'V',
'F', nru, m-ll+1, work( nm12+1 ),
739 $ work( nm13+1 ), u( 1, ll ), ldu )
740 IF( ncc.GT.0 )
741 $
CALL dlasr(
'L',
'V',
'F', m-ll+1, ncc, work( nm12+1 ),
742 $ work( nm13+1 ), c( ll, 1 ), ldc )
743
744
745
746 IF( abs( e( m-1 ) ).LE.thresh )
747 $ e( m-1 ) = zero
748
749 ELSE
750
751
752
753
754 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
755 $ d( m ) )
756 g = e( m-1 )
757 DO 150 i = m, ll + 1, -1
758 CALL dlartg( f, g, cosr, sinr, r )
759 IF( i.LT.m )
760 $ e( i ) = r
761 f = cosr*d( i ) + sinr*e( i-1 )
762 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
763 g = sinr*d( i-1 )
764 d( i-1 ) = cosr*d( i-1 )
765 CALL dlartg( f, g, cosl, sinl, r )
766 d( i ) = r
767 f = cosl*e( i-1 ) + sinl*d( i-1 )
768 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
769 IF( i.GT.ll+1 ) THEN
770 g = sinl*e( i-2 )
771 e( i-2 ) = cosl*e( i-2 )
772 END IF
773 work( i-ll ) = cosr
774 work( i-ll+nm1 ) = -sinr
775 work( i-ll+nm12 ) = cosl
776 work( i-ll+nm13 ) = -sinl
777 150 CONTINUE
778 e( ll ) = f
779
780
781
782 IF( abs( e( ll ) ).LE.thresh )
783 $ e( ll ) = zero
784
785
786
787 IF( ncvt.GT.0 )
788 $
CALL dlasr(
'L',
'V',
'B', m-ll+1, ncvt, work( nm12+1 ),
789 $ work( nm13+1 ), vt( ll, 1 ), ldvt )
790 IF( nru.GT.0 )
791 $
CALL dlasr(
'R',
'V',
'B', nru, m-ll+1, work( 1 ),
792 $ work( n ), u( 1, ll ), ldu )
793 IF( ncc.GT.0 )
794 $
CALL dlasr(
'L',
'V',
'B', m-ll+1, ncc, work( 1 ),
795 $ work( n ), c( ll, 1 ), ldc )
796 END IF
797 END IF
798
799
800
801 GO TO 60
802
803
804
805 160 CONTINUE
806 DO 170 i = 1, n
807 IF( d( i ).LT.zero ) THEN
808 d( i ) = -d( i )
809
810
811
812 IF( ncvt.GT.0 )
813 $
CALL dscal( ncvt, negone, vt( i, 1 ), ldvt )
814 END IF
815 170 CONTINUE
816
817
818
819
820 DO 190 i = 1, n - 1
821
822
823
824 isub = 1
825 smin = d( 1 )
826 DO 180 j = 2, n + 1 - i
827 IF( d( j ).LE.smin ) THEN
828 isub = j
829 smin = d( j )
830 END IF
831 180 CONTINUE
832 IF( isub.NE.n+1-i ) THEN
833
834
835
836 d( isub ) = d( n+1-i )
837 d( n+1-i ) = smin
838 IF( ncvt.GT.0 )
839 $
CALL dswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
840 $ ldvt )
841 IF( nru.GT.0 )
842 $
CALL dswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
843 IF( ncc.GT.0 )
844 $
CALL dswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ), ldc )
845 END IF
846 190 CONTINUE
847 GO TO 220
848
849
850
851 200 CONTINUE
852 info = 0
853 DO 210 i = 1, n - 1
854 IF( e( i ).NE.zero )
855 $ info = info + 1
856 210 CONTINUE
857 220 CONTINUE
858 RETURN
859
860
861
subroutine xerbla(srname, info)
double precision function dlamch(cmach)
DLAMCH
subroutine dlartg(f, g, c, s, r)
DLARTG generates a plane rotation with real cosine and real sine.
subroutine dlas2(f, g, h, ssmin, ssmax)
DLAS2 computes singular values of a 2-by-2 triangular matrix.
subroutine dlasq1(n, d, e, work, info)
DLASQ1 computes the singular values of a real square bidiagonal matrix. Used by sbdsqr.
subroutine dlasr(side, pivot, direct, m, n, c, s, a, lda)
DLASR applies a sequence of plane rotations to a general rectangular matrix.
subroutine dlasv2(f, g, h, ssmin, ssmax, snr, csr, snl, csl)
DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
logical function lsame(ca, cb)
LSAME
subroutine drot(n, dx, incx, dy, incy, c, s)
DROT
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine dswap(n, dx, incx, dy, incy)
DSWAP