LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dbdsqr.f
Go to the documentation of this file.
1*> \brief \b DBDSQR
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DBDSQR + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsqr.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsqr.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsqr.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
20* LDU, C, LDC, WORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER UPLO
24* INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
25* ..
26* .. Array Arguments ..
27* DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
28* $ VT( LDVT, * ), WORK( * )
29* ..
30*
31*
32*> \par Purpose:
33* =============
34*>
35*> \verbatim
36*>
37*> DBDSQR computes the singular values and, optionally, the right and/or
38*> left singular vectors from the singular value decomposition (SVD) of
39*> a real N-by-N (upper or lower) bidiagonal matrix B using the implicit
40*> zero-shift QR algorithm. The SVD of B has the form
41*>
42*> B = Q * S * P**T
43*>
44*> where S is the diagonal matrix of singular values, Q is an orthogonal
45*> matrix of left singular vectors, and P is an orthogonal matrix of
46*> right singular vectors. If left singular vectors are requested, this
47*> subroutine actually returns U*Q instead of Q, and, if right singular
48*> vectors are requested, this subroutine returns P**T*VT instead of
49*> P**T, for given real input matrices U and VT. When U and VT are the
50*> orthogonal matrices that reduce a general matrix A to bidiagonal
51*> form: A = U*B*VT, as computed by DGEBRD, then
52*>
53*> A = (U*Q) * S * (P**T*VT)
54*>
55*> is the SVD of A. Optionally, the subroutine may also compute Q**T*C
56*> for a given real input matrix C.
57*>
58*> See "Computing Small Singular Values of Bidiagonal Matrices With
59*> Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan,
60*> LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11,
61*> no. 5, pp. 873-912, Sept 1990) and
62*> "Accurate singular values and differential qd algorithms," by
63*> B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics
64*> Department, University of California at Berkeley, July 1992
65*> for a detailed description of the algorithm.
66*> \endverbatim
67*
68* Arguments:
69* ==========
70*
71*> \param[in] UPLO
72*> \verbatim
73*> UPLO is CHARACTER*1
74*> = 'U': B is upper bidiagonal;
75*> = 'L': B is lower bidiagonal.
76*> \endverbatim
77*>
78*> \param[in] N
79*> \verbatim
80*> N is INTEGER
81*> The order of the matrix B. N >= 0.
82*> \endverbatim
83*>
84*> \param[in] NCVT
85*> \verbatim
86*> NCVT is INTEGER
87*> The number of columns of the matrix VT. NCVT >= 0.
88*> \endverbatim
89*>
90*> \param[in] NRU
91*> \verbatim
92*> NRU is INTEGER
93*> The number of rows of the matrix U. NRU >= 0.
94*> \endverbatim
95*>
96*> \param[in] NCC
97*> \verbatim
98*> NCC is INTEGER
99*> The number of columns of the matrix C. NCC >= 0.
100*> \endverbatim
101*>
102*> \param[in,out] D
103*> \verbatim
104*> D is DOUBLE PRECISION array, dimension (N)
105*> On entry, the n diagonal elements of the bidiagonal matrix B.
106*> On exit, if INFO=0, the singular values of B in decreasing
107*> order.
108*> \endverbatim
109*>
110*> \param[in,out] E
111*> \verbatim
112*> E is DOUBLE PRECISION array, dimension (N-1)
113*> On entry, the N-1 offdiagonal elements of the bidiagonal
114*> matrix B.
115*> On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E
116*> will contain the diagonal and superdiagonal elements of a
117*> bidiagonal matrix orthogonally equivalent to the one given
118*> as input.
119*> \endverbatim
120*>
121*> \param[in,out] VT
122*> \verbatim
123*> VT is DOUBLE PRECISION array, dimension (LDVT, NCVT)
124*> On entry, an N-by-NCVT matrix VT.
125*> On exit, VT is overwritten by P**T * VT.
126*> Not referenced if NCVT = 0.
127*> \endverbatim
128*>
129*> \param[in] LDVT
130*> \verbatim
131*> LDVT is INTEGER
132*> The leading dimension of the array VT.
133*> LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0.
134*> \endverbatim
135*>
136*> \param[in,out] U
137*> \verbatim
138*> U is DOUBLE PRECISION array, dimension (LDU, N)
139*> On entry, an NRU-by-N matrix U.
140*> On exit, U is overwritten by U * Q.
141*> Not referenced if NRU = 0.
142*> \endverbatim
143*>
144*> \param[in] LDU
145*> \verbatim
146*> LDU is INTEGER
147*> The leading dimension of the array U. LDU >= max(1,NRU).
148*> \endverbatim
149*>
150*> \param[in,out] C
151*> \verbatim
152*> C is DOUBLE PRECISION array, dimension (LDC, NCC)
153*> On entry, an N-by-NCC matrix C.
154*> On exit, C is overwritten by Q**T * C.
155*> Not referenced if NCC = 0.
156*> \endverbatim
157*>
158*> \param[in] LDC
159*> \verbatim
160*> LDC is INTEGER
161*> The leading dimension of the array C.
162*> LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0.
163*> \endverbatim
164*>
165*> \param[out] WORK
166*> \verbatim
167*> WORK is DOUBLE PRECISION array, dimension (LWORK)
168*> LWORK = 4*N, if NCVT = NRU = NCC = 0, and
169*> LWORK = 4*(N-1), otherwise
170*> \endverbatim
171*>
172*> \param[out] INFO
173*> \verbatim
174*> INFO is INTEGER
175*> = 0: successful exit
176*> < 0: If INFO = -i, the i-th argument had an illegal value
177*> > 0:
178*> if NCVT = NRU = NCC = 0,
179*> = 1, a split was marked by a positive value in E
180*> = 2, current block of Z not diagonalized after 30*N
181*> iterations (in inner while loop)
182*> = 3, termination criterion of outer while loop not met
183*> (program created more than N unreduced blocks)
184*> else NCVT = NRU = NCC = 0,
185*> the algorithm did not converge; D and E contain the
186*> elements of a bidiagonal matrix which is orthogonally
187*> similar to the input matrix B; if INFO = i, i
188*> elements of E have not converged to zero.
189*> \endverbatim
190*
191*> \par Internal Parameters:
192* =========================
193*>
194*> \verbatim
195*> TOLMUL DOUBLE PRECISION, default = max(10,min(100,EPS**(-1/8)))
196*> TOLMUL controls the convergence criterion of the QR loop.
197*> If it is positive, TOLMUL*EPS is the desired relative
198*> precision in the computed singular values.
199*> If it is negative, abs(TOLMUL*EPS*sigma_max) is the
200*> desired absolute accuracy in the computed singular
201*> values (corresponds to relative accuracy
202*> abs(TOLMUL*EPS) in the largest singular value.
203*> abs(TOLMUL) should be between 1 and 1/EPS, and preferably
204*> between 10 (for fast convergence) and .1/EPS
205*> (for there to be some accuracy in the results).
206*> Default is to lose at either one eighth or 2 of the
207*> available decimal digits in each computed singular value
208*> (whichever is smaller).
209*>
210*> MAXITR INTEGER, default = 6
211*> MAXITR controls the maximum number of passes of the
212*> algorithm through its inner loop. The algorithms stops
213*> (and so fails to converge) if the number of passes
214*> through the inner loop exceeds MAXITR*N**2.
215*>
216*> \endverbatim
217*
218*> \par Note:
219* ===========
220*>
221*> \verbatim
222*> Bug report from Cezary Dendek.
223*> On March 23rd 2017, the INTEGER variable MAXIT = MAXITR*N**2 is
224*> removed since it can overflow pretty easily (for N larger or equal
225*> than 18,919). We instead use MAXITDIVN = MAXITR*N.
226*> \endverbatim
227*
228* Authors:
229* ========
230*
231*> \author Univ. of Tennessee
232*> \author Univ. of California Berkeley
233*> \author Univ. of Colorado Denver
234*> \author NAG Ltd.
235*
236*> \ingroup bdsqr
237*
238* =====================================================================
239 SUBROUTINE dbdsqr( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
240 $ LDU, C, LDC, WORK, INFO )
241*
242* -- LAPACK computational routine --
243* -- LAPACK is a software package provided by Univ. of Tennessee, --
244* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
245*
246* .. Scalar Arguments ..
247 CHARACTER UPLO
248 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
249* ..
250* .. Array Arguments ..
251 DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
252 $ vt( ldvt, * ), work( * )
253* ..
254*
255* =====================================================================
256*
257* .. Parameters ..
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* .. Local Scalars ..
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* .. External Functions ..
285 LOGICAL LSAME
286 DOUBLE PRECISION DLAMCH
287 EXTERNAL lsame, dlamch
288* ..
289* .. External Subroutines ..
290 EXTERNAL dlartg, dlas2, dlasq1, dlasr, dlasv2,
291 $ drot,
292 $ dscal, dswap, xerbla
293* ..
294* .. Intrinsic Functions ..
295 INTRINSIC abs, dble, max, min, sign, sqrt
296* ..
297* .. Executable Statements ..
298*
299* Test the input parameters.
300*
301 info = 0
302 lower = lsame( uplo, 'L' )
303 IF( .NOT.lsame( uplo, 'U' ) .AND. .NOT.lower ) THEN
304 info = -1
305 ELSE IF( n.LT.0 ) THEN
306 info = -2
307 ELSE IF( ncvt.LT.0 ) THEN
308 info = -3
309 ELSE IF( nru.LT.0 ) THEN
310 info = -4
311 ELSE IF( ncc.LT.0 ) THEN
312 info = -5
313 ELSE IF( ( ncvt.EQ.0 .AND. ldvt.LT.1 ) .OR.
314 $ ( ncvt.GT.0 .AND. ldvt.LT.max( 1, n ) ) ) THEN
315 info = -9
316 ELSE IF( ldu.LT.max( 1, nru ) ) THEN
317 info = -11
318 ELSE IF( ( ncc.EQ.0 .AND. ldc.LT.1 ) .OR.
319 $ ( ncc.GT.0 .AND. ldc.LT.max( 1, n ) ) ) THEN
320 info = -13
321 END IF
322 IF( info.NE.0 ) THEN
323 CALL xerbla( 'DBDSQR', -info )
324 RETURN
325 END IF
326 IF( n.EQ.0 )
327 $ RETURN
328 IF( n.EQ.1 )
329 $ GO TO 160
330*
331* ROTATE is true if any singular vectors desired, false otherwise
332*
333 rotate = ( ncvt.GT.0 ) .OR. ( nru.GT.0 ) .OR. ( ncc.GT.0 )
334*
335* If no singular vectors desired, use qd algorithm
336*
337 IF( .NOT.rotate ) THEN
338 CALL dlasq1( n, d, e, work, info )
339*
340* If INFO equals 2, dqds didn't finish, try to finish
341*
342 IF( info .NE. 2 ) RETURN
343 info = 0
344 END IF
345*
346 nm1 = n - 1
347 nm12 = nm1 + nm1
348 nm13 = nm12 + nm1
349 idir = 0
350*
351* Get machine constants
352*
353 eps = dlamch( 'Epsilon' )
354 unfl = dlamch( 'Safe minimum' )
355*
356* If matrix lower bidiagonal, rotate to be upper bidiagonal
357* by applying Givens rotations on the left
358*
359 IF( lower ) THEN
360 DO 10 i = 1, n - 1
361 CALL dlartg( d( i ), e( i ), cs, sn, r )
362 d( i ) = r
363 e( i ) = sn*d( i+1 )
364 d( i+1 ) = cs*d( i+1 )
365 work( i ) = cs
366 work( nm1+i ) = sn
367 10 CONTINUE
368*
369* Update singular vectors if desired
370*
371 IF( nru.GT.0 )
372 $ CALL dlasr( 'R', 'V', 'F', nru, n, work( 1 ), work( n ),
373 $ u,
374 $ ldu )
375 IF( ncc.GT.0 )
376 $ CALL dlasr( 'L', 'V', 'F', n, ncc, work( 1 ), work( n ),
377 $ c,
378 $ ldc )
379 END IF
380*
381* Compute singular values to relative accuracy TOL
382* (By setting TOL to be negative, algorithm will compute
383* singular values to absolute accuracy ABS(TOL)*norm(input matrix))
384*
385 tolmul = max( ten, min( hndrd, eps**meigth ) )
386 tol = tolmul*eps
387*
388* Compute approximate maximum, minimum singular values
389*
390 smax = zero
391 DO 20 i = 1, n
392 smax = max( smax, abs( d( i ) ) )
393 20 CONTINUE
394 DO 30 i = 1, n - 1
395 smax = max( smax, abs( e( i ) ) )
396 30 CONTINUE
397 smin = zero
398 IF( tol.GE.zero ) THEN
399*
400* Relative accuracy desired
401*
402 sminoa = abs( d( 1 ) )
403 IF( sminoa.EQ.zero )
404 $ GO TO 50
405 mu = sminoa
406 DO 40 i = 2, n
407 mu = abs( d( i ) )*( mu / ( mu+abs( e( i-1 ) ) ) )
408 sminoa = min( sminoa, mu )
409 IF( sminoa.EQ.zero )
410 $ GO TO 50
411 40 CONTINUE
412 50 CONTINUE
413 sminoa = sminoa / sqrt( dble( n ) )
414 thresh = max( tol*sminoa, maxitr*(n*(n*unfl)) )
415 ELSE
416*
417* Absolute accuracy desired
418*
419 thresh = max( abs( tol )*smax, maxitr*(n*(n*unfl)) )
420 END IF
421*
422* Prepare for main iteration loop for the singular values
423* (MAXIT is the maximum number of passes through the inner
424* loop permitted before nonconvergence signalled.)
425*
426 maxitdivn = maxitr*n
427 iterdivn = 0
428 iter = -1
429 oldll = -1
430 oldm = -1
431*
432* M points to last element of unconverged part of matrix
433*
434 m = n
435*
436* Begin main iteration loop
437*
438 60 CONTINUE
439*
440* Check for convergence or exceeding iteration count
441*
442 IF( m.LE.1 )
443 $ GO TO 160
444*
445 IF( iter.GE.n ) THEN
446 iter = iter - n
447 iterdivn = iterdivn + 1
448 IF( iterdivn.GE.maxitdivn )
449 $ GO TO 200
450 END IF
451*
452* Find diagonal block of matrix to work on
453*
454 IF( tol.LT.zero .AND. abs( d( m ) ).LE.thresh )
455 $ d( m ) = zero
456 smax = abs( d( m ) )
457 DO 70 lll = 1, m - 1
458 ll = m - lll
459 abss = abs( d( ll ) )
460 abse = abs( e( ll ) )
461 IF( tol.LT.zero .AND. abss.LE.thresh )
462 $ d( ll ) = zero
463 IF( abse.LE.thresh )
464 $ GO TO 80
465 smax = max( smax, abss, abse )
466 70 CONTINUE
467 ll = 0
468 GO TO 90
469 80 CONTINUE
470 e( ll ) = zero
471*
472* Matrix splits since E(LL) = 0
473*
474 IF( ll.EQ.m-1 ) THEN
475*
476* Convergence of bottom singular value, return to top of loop
477*
478 m = m - 1
479 GO TO 60
480 END IF
481 90 CONTINUE
482 ll = ll + 1
483*
484* E(LL) through E(M-1) are nonzero, E(LL-1) is zero
485*
486 IF( ll.EQ.m-1 ) THEN
487*
488* 2 by 2 block, handle separately
489*
490 CALL dlasv2( d( m-1 ), e( m-1 ), d( m ), sigmn, sigmx, sinr,
491 $ cosr, sinl, cosl )
492 d( m-1 ) = sigmx
493 e( m-1 ) = zero
494 d( m ) = sigmn
495*
496* Compute singular vectors, if desired
497*
498 IF( ncvt.GT.0 )
499 $ CALL drot( ncvt, vt( m-1, 1 ), ldvt, vt( m, 1 ), ldvt,
500 $ cosr,
501 $ sinr )
502 IF( nru.GT.0 )
503 $ CALL drot( nru, u( 1, m-1 ), 1, u( 1, m ), 1, cosl,
504 $ sinl )
505 IF( ncc.GT.0 )
506 $ CALL drot( ncc, c( m-1, 1 ), ldc, c( m, 1 ), ldc, cosl,
507 $ sinl )
508 m = m - 2
509 GO TO 60
510 END IF
511*
512* If working on new submatrix, choose shift direction
513* (from larger end diagonal element towards smaller)
514*
515 IF( ll.GT.oldm .OR. m.LT.oldll ) THEN
516 IF( abs( d( ll ) ).GE.abs( d( m ) ) ) THEN
517*
518* Chase bulge from top (big end) to bottom (small end)
519*
520 idir = 1
521 ELSE
522*
523* Chase bulge from bottom (big end) to top (small end)
524*
525 idir = 2
526 END IF
527 END IF
528*
529* Apply convergence tests
530*
531 IF( idir.EQ.1 ) THEN
532*
533* Run convergence test in forward direction
534* First apply standard test to bottom of matrix
535*
536 IF( abs( e( m-1 ) ).LE.abs( tol )*abs( d( m ) ) .OR.
537 $ ( tol.LT.zero .AND. abs( e( m-1 ) ).LE.thresh ) ) THEN
538 e( m-1 ) = zero
539 GO TO 60
540 END IF
541*
542 IF( tol.GE.zero ) THEN
543*
544* If relative accuracy desired,
545* apply convergence criterion forward
546*
547 mu = abs( d( ll ) )
548 smin = mu
549 DO 100 lll = ll, m - 1
550 IF( abs( e( lll ) ).LE.tol*mu ) THEN
551 e( lll ) = zero
552 GO TO 60
553 END IF
554 mu = abs( d( lll+1 ) )*( mu / ( mu+abs( e( lll ) ) ) )
555 smin = min( smin, mu )
556 100 CONTINUE
557 END IF
558*
559 ELSE
560*
561* Run convergence test in backward direction
562* First apply standard test to top of matrix
563*
564 IF( abs( e( ll ) ).LE.abs( tol )*abs( d( ll ) ) .OR.
565 $ ( tol.LT.zero .AND. abs( e( ll ) ).LE.thresh ) ) THEN
566 e( ll ) = zero
567 GO TO 60
568 END IF
569*
570 IF( tol.GE.zero ) THEN
571*
572* If relative accuracy desired,
573* apply convergence criterion backward
574*
575 mu = abs( d( m ) )
576 smin = mu
577 DO 110 lll = m - 1, ll, -1
578 IF( abs( e( lll ) ).LE.tol*mu ) THEN
579 e( lll ) = zero
580 GO TO 60
581 END IF
582 mu = abs( d( lll ) )*( mu / ( mu+abs( e( lll ) ) ) )
583 smin = min( smin, mu )
584 110 CONTINUE
585 END IF
586 END IF
587 oldll = ll
588 oldm = m
589*
590* Compute shift. First, test if shifting would ruin relative
591* accuracy, and if so set the shift to zero.
592*
593 IF( tol.GE.zero .AND. n*tol*( smin / smax ).LE.
594 $ max( eps, hndrth*tol ) ) THEN
595*
596* Use a zero shift to avoid loss of relative accuracy
597*
598 shift = zero
599 ELSE
600*
601* Compute the shift from 2-by-2 block at end of matrix
602*
603 IF( idir.EQ.1 ) THEN
604 sll = abs( d( ll ) )
605 CALL dlas2( d( m-1 ), e( m-1 ), d( m ), shift, r )
606 ELSE
607 sll = abs( d( m ) )
608 CALL dlas2( d( ll ), e( ll ), d( ll+1 ), shift, r )
609 END IF
610*
611* Test if shift negligible, and if so set to zero
612*
613 IF( sll.GT.zero ) THEN
614 IF( ( shift / sll )**2.LT.eps )
615 $ shift = zero
616 END IF
617 END IF
618*
619* Increment iteration count
620*
621 iter = iter + m - ll
622*
623* If SHIFT = 0, do simplified QR iteration
624*
625 IF( shift.EQ.zero ) THEN
626 IF( idir.EQ.1 ) THEN
627*
628* Chase bulge from top to bottom
629* Save cosines and sines for later singular vector updates
630*
631 cs = one
632 oldcs = one
633 DO 120 i = ll, m - 1
634 CALL dlartg( d( i )*cs, e( i ), cs, sn, r )
635 IF( i.GT.ll )
636 $ e( i-1 ) = oldsn*r
637 CALL dlartg( oldcs*r, d( i+1 )*sn, oldcs, oldsn,
638 $ d( i ) )
639 work( i-ll+1 ) = cs
640 work( i-ll+1+nm1 ) = sn
641 work( i-ll+1+nm12 ) = oldcs
642 work( i-ll+1+nm13 ) = oldsn
643 120 CONTINUE
644 h = d( m )*cs
645 d( m ) = h*oldcs
646 e( m-1 ) = h*oldsn
647*
648* Update singular vectors
649*
650 IF( ncvt.GT.0 )
651 $ CALL dlasr( 'L', 'V', 'F', m-ll+1, ncvt, work( 1 ),
652 $ work( n ), vt( ll, 1 ), ldvt )
653 IF( nru.GT.0 )
654 $ CALL dlasr( 'R', 'V', 'F', nru, m-ll+1,
655 $ work( nm12+1 ),
656 $ work( nm13+1 ), u( 1, ll ), ldu )
657 IF( ncc.GT.0 )
658 $ CALL dlasr( 'L', 'V', 'F', m-ll+1, ncc,
659 $ work( nm12+1 ),
660 $ work( nm13+1 ), c( ll, 1 ), ldc )
661*
662* Test convergence
663*
664 IF( abs( e( m-1 ) ).LE.thresh )
665 $ e( m-1 ) = zero
666*
667 ELSE
668*
669* Chase bulge from bottom to top
670* Save cosines and sines for later singular vector updates
671*
672 cs = one
673 oldcs = one
674 DO 130 i = m, ll + 1, -1
675 CALL dlartg( d( i )*cs, e( i-1 ), cs, sn, r )
676 IF( i.LT.m )
677 $ e( i ) = oldsn*r
678 CALL dlartg( oldcs*r, d( i-1 )*sn, oldcs, oldsn,
679 $ d( i ) )
680 work( i-ll ) = cs
681 work( i-ll+nm1 ) = -sn
682 work( i-ll+nm12 ) = oldcs
683 work( i-ll+nm13 ) = -oldsn
684 130 CONTINUE
685 h = d( ll )*cs
686 d( ll ) = h*oldcs
687 e( ll ) = h*oldsn
688*
689* Update singular vectors
690*
691 IF( ncvt.GT.0 )
692 $ CALL dlasr( 'L', 'V', 'B', m-ll+1, ncvt,
693 $ work( nm12+1 ),
694 $ work( nm13+1 ), vt( ll, 1 ), ldvt )
695 IF( nru.GT.0 )
696 $ CALL dlasr( 'R', 'V', 'B', nru, m-ll+1, work( 1 ),
697 $ work( n ), u( 1, ll ), ldu )
698 IF( ncc.GT.0 )
699 $ CALL dlasr( 'L', 'V', 'B', m-ll+1, ncc, work( 1 ),
700 $ work( n ), c( ll, 1 ), ldc )
701*
702* Test convergence
703*
704 IF( abs( e( ll ) ).LE.thresh )
705 $ e( ll ) = zero
706 END IF
707 ELSE
708*
709* Use nonzero shift
710*
711 IF( idir.EQ.1 ) THEN
712*
713* Chase bulge from top to bottom
714* Save cosines and sines for later singular vector updates
715*
716 f = ( abs( d( ll ) )-shift )*
717 $ ( sign( one, d( ll ) )+shift / d( ll ) )
718 g = e( ll )
719 DO 140 i = ll, m - 1
720 CALL dlartg( f, g, cosr, sinr, r )
721 IF( i.GT.ll )
722 $ e( i-1 ) = r
723 f = cosr*d( i ) + sinr*e( i )
724 e( i ) = cosr*e( i ) - sinr*d( i )
725 g = sinr*d( i+1 )
726 d( i+1 ) = cosr*d( i+1 )
727 CALL dlartg( f, g, cosl, sinl, r )
728 d( i ) = r
729 f = cosl*e( i ) + sinl*d( i+1 )
730 d( i+1 ) = cosl*d( i+1 ) - sinl*e( i )
731 IF( i.LT.m-1 ) THEN
732 g = sinl*e( i+1 )
733 e( i+1 ) = cosl*e( i+1 )
734 END IF
735 work( i-ll+1 ) = cosr
736 work( i-ll+1+nm1 ) = sinr
737 work( i-ll+1+nm12 ) = cosl
738 work( i-ll+1+nm13 ) = sinl
739 140 CONTINUE
740 e( m-1 ) = f
741*
742* Update singular vectors
743*
744 IF( ncvt.GT.0 )
745 $ CALL dlasr( 'L', 'V', 'F', m-ll+1, ncvt, work( 1 ),
746 $ work( n ), vt( ll, 1 ), ldvt )
747 IF( nru.GT.0 )
748 $ CALL dlasr( 'R', 'V', 'F', nru, m-ll+1,
749 $ work( nm12+1 ),
750 $ work( nm13+1 ), u( 1, ll ), ldu )
751 IF( ncc.GT.0 )
752 $ CALL dlasr( 'L', 'V', 'F', m-ll+1, ncc,
753 $ work( nm12+1 ),
754 $ work( nm13+1 ), c( ll, 1 ), ldc )
755*
756* Test convergence
757*
758 IF( abs( e( m-1 ) ).LE.thresh )
759 $ e( m-1 ) = zero
760*
761 ELSE
762*
763* Chase bulge from bottom to top
764* Save cosines and sines for later singular vector updates
765*
766 f = ( abs( d( m ) )-shift )*( sign( one, d( m ) )+shift /
767 $ d( m ) )
768 g = e( m-1 )
769 DO 150 i = m, ll + 1, -1
770 CALL dlartg( f, g, cosr, sinr, r )
771 IF( i.LT.m )
772 $ e( i ) = r
773 f = cosr*d( i ) + sinr*e( i-1 )
774 e( i-1 ) = cosr*e( i-1 ) - sinr*d( i )
775 g = sinr*d( i-1 )
776 d( i-1 ) = cosr*d( i-1 )
777 CALL dlartg( f, g, cosl, sinl, r )
778 d( i ) = r
779 f = cosl*e( i-1 ) + sinl*d( i-1 )
780 d( i-1 ) = cosl*d( i-1 ) - sinl*e( i-1 )
781 IF( i.GT.ll+1 ) THEN
782 g = sinl*e( i-2 )
783 e( i-2 ) = cosl*e( i-2 )
784 END IF
785 work( i-ll ) = cosr
786 work( i-ll+nm1 ) = -sinr
787 work( i-ll+nm12 ) = cosl
788 work( i-ll+nm13 ) = -sinl
789 150 CONTINUE
790 e( ll ) = f
791*
792* Test convergence
793*
794 IF( abs( e( ll ) ).LE.thresh )
795 $ e( ll ) = zero
796*
797* Update singular vectors if desired
798*
799 IF( ncvt.GT.0 )
800 $ CALL dlasr( 'L', 'V', 'B', m-ll+1, ncvt,
801 $ work( nm12+1 ),
802 $ work( nm13+1 ), vt( ll, 1 ), ldvt )
803 IF( nru.GT.0 )
804 $ CALL dlasr( 'R', 'V', 'B', nru, m-ll+1, work( 1 ),
805 $ work( n ), u( 1, ll ), ldu )
806 IF( ncc.GT.0 )
807 $ CALL dlasr( 'L', 'V', 'B', m-ll+1, ncc, work( 1 ),
808 $ work( n ), c( ll, 1 ), ldc )
809 END IF
810 END IF
811*
812* QR iteration finished, go back and check convergence
813*
814 GO TO 60
815*
816* All singular values converged, so make them positive
817*
818 160 CONTINUE
819 DO 170 i = 1, n
820 IF( d( i ).EQ.zero ) THEN
821*
822* Avoid -ZERO
823*
824 d( i ) = zero
825 END IF
826 IF( d( i ).LT.zero ) THEN
827 d( i ) = -d( i )
828*
829* Change sign of singular vectors, if desired
830*
831 IF( ncvt.GT.0 )
832 $ CALL dscal( ncvt, negone, vt( i, 1 ), ldvt )
833 END IF
834 170 CONTINUE
835*
836* Sort the singular values into decreasing order (insertion sort on
837* singular values, but only one transposition per singular vector)
838*
839 DO 190 i = 1, n - 1
840*
841* Scan for smallest D(I)
842*
843 isub = 1
844 smin = d( 1 )
845 DO 180 j = 2, n + 1 - i
846 IF( d( j ).LE.smin ) THEN
847 isub = j
848 smin = d( j )
849 END IF
850 180 CONTINUE
851 IF( isub.NE.n+1-i ) THEN
852*
853* Swap singular values and vectors
854*
855 d( isub ) = d( n+1-i )
856 d( n+1-i ) = smin
857 IF( ncvt.GT.0 )
858 $ CALL dswap( ncvt, vt( isub, 1 ), ldvt, vt( n+1-i, 1 ),
859 $ ldvt )
860 IF( nru.GT.0 )
861 $ CALL dswap( nru, u( 1, isub ), 1, u( 1, n+1-i ), 1 )
862 IF( ncc.GT.0 )
863 $ CALL dswap( ncc, c( isub, 1 ), ldc, c( n+1-i, 1 ),
864 $ ldc )
865 END IF
866 190 CONTINUE
867 GO TO 220
868*
869* Maximum number of iterations exceeded, failure to converge
870*
871 200 CONTINUE
872 info = 0
873 DO 210 i = 1, n - 1
874 IF( e( i ).NE.zero )
875 $ info = info + 1
876 210 CONTINUE
877 220 CONTINUE
878 RETURN
879*
880* End of DBDSQR
881*
882 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine dbdsqr(uplo, n, ncvt, nru, ncc, d, e, vt, ldvt, u, ldu, c, ldc, work, info)
DBDSQR
Definition dbdsqr.f:241
subroutine dlartg(f, g, c, s, r)
DLARTG generates a plane rotation with real cosine and real sine.
Definition dlartg.f90:111
subroutine dlas2(f, g, h, ssmin, ssmax)
DLAS2 computes singular values of a 2-by-2 triangular matrix.
Definition dlas2.f:103
subroutine dlasq1(n, d, e, work, info)
DLASQ1 computes the singular values of a real square bidiagonal matrix. Used by sbdsqr.
Definition dlasq1.f:106
subroutine dlasr(side, pivot, direct, m, n, c, s, a, lda)
DLASR applies a sequence of plane rotations to a general rectangular matrix.
Definition dlasr.f:197
subroutine dlasv2(f, g, h, ssmin, ssmax, snr, csr, snl, csl)
DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
Definition dlasv2.f:134
subroutine drot(n, dx, incx, dy, incy, c, s)
DROT
Definition drot.f:92
subroutine dscal(n, da, dx, incx)
DSCAL
Definition dscal.f:79
subroutine dswap(n, dx, incx, dy, incy)
DSWAP
Definition dswap.f:82