LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
slasd7.f
Go to the documentation of this file.
1*> \brief \b SLASD7 merges the two sets of singular values together into a single sorted set. Then it tries to deflate the size of the problem. Used by sbdsdc.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download SLASD7 + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasd7.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasd7.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasd7.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW, VL,
20* VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ,
21* PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
22* C, S, INFO )
23*
24* .. Scalar Arguments ..
25* INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
26* $ NR, SQRE
27* REAL ALPHA, BETA, C, S
28* ..
29* .. Array Arguments ..
30* INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ),
31* $ IDXQ( * ), PERM( * )
32* REAL D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ),
33* $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ),
34* $ ZW( * )
35* ..
36*
37*
38*> \par Purpose:
39* =============
40*>
41*> \verbatim
42*>
43*> SLASD7 merges the two sets of singular values together into a single
44*> sorted set. Then it tries to deflate the size of the problem. There
45*> are two ways in which deflation can occur: when two or more singular
46*> values are close together or if there is a tiny entry in the Z
47*> vector. For each such occurrence the order of the related
48*> secular equation problem is reduced by one.
49*>
50*> SLASD7 is called from SLASD6.
51*> \endverbatim
52*
53* Arguments:
54* ==========
55*
56*> \param[in] ICOMPQ
57*> \verbatim
58*> ICOMPQ is INTEGER
59*> Specifies whether singular vectors are to be computed
60*> in compact form, as follows:
61*> = 0: Compute singular values only.
62*> = 1: Compute singular vectors of upper
63*> bidiagonal matrix in compact form.
64*> \endverbatim
65*>
66*> \param[in] NL
67*> \verbatim
68*> NL is INTEGER
69*> The row dimension of the upper block. NL >= 1.
70*> \endverbatim
71*>
72*> \param[in] NR
73*> \verbatim
74*> NR is INTEGER
75*> The row dimension of the lower block. NR >= 1.
76*> \endverbatim
77*>
78*> \param[in] SQRE
79*> \verbatim
80*> SQRE is INTEGER
81*> = 0: the lower block is an NR-by-NR square matrix.
82*> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
83*>
84*> The bidiagonal matrix has
85*> N = NL + NR + 1 rows and
86*> M = N + SQRE >= N columns.
87*> \endverbatim
88*>
89*> \param[out] K
90*> \verbatim
91*> K is INTEGER
92*> Contains the dimension of the non-deflated matrix, this is
93*> the order of the related secular equation. 1 <= K <=N.
94*> \endverbatim
95*>
96*> \param[in,out] D
97*> \verbatim
98*> D is REAL array, dimension ( N )
99*> On entry D contains the singular values of the two submatrices
100*> to be combined. On exit D contains the trailing (N-K) updated
101*> singular values (those which were deflated) sorted into
102*> increasing order.
103*> \endverbatim
104*>
105*> \param[out] Z
106*> \verbatim
107*> Z is REAL array, dimension ( M )
108*> On exit Z contains the updating row vector in the secular
109*> equation.
110*> \endverbatim
111*>
112*> \param[out] ZW
113*> \verbatim
114*> ZW is REAL array, dimension ( M )
115*> Workspace for Z.
116*> \endverbatim
117*>
118*> \param[in,out] VF
119*> \verbatim
120*> VF is REAL array, dimension ( M )
121*> On entry, VF(1:NL+1) contains the first components of all
122*> right singular vectors of the upper block; and VF(NL+2:M)
123*> contains the first components of all right singular vectors
124*> of the lower block. On exit, VF contains the first components
125*> of all right singular vectors of the bidiagonal matrix.
126*> \endverbatim
127*>
128*> \param[out] VFW
129*> \verbatim
130*> VFW is REAL array, dimension ( M )
131*> Workspace for VF.
132*> \endverbatim
133*>
134*> \param[in,out] VL
135*> \verbatim
136*> VL is REAL array, dimension ( M )
137*> On entry, VL(1:NL+1) contains the last components of all
138*> right singular vectors of the upper block; and VL(NL+2:M)
139*> contains the last components of all right singular vectors
140*> of the lower block. On exit, VL contains the last components
141*> of all right singular vectors of the bidiagonal matrix.
142*> \endverbatim
143*>
144*> \param[out] VLW
145*> \verbatim
146*> VLW is REAL array, dimension ( M )
147*> Workspace for VL.
148*> \endverbatim
149*>
150*> \param[in] ALPHA
151*> \verbatim
152*> ALPHA is REAL
153*> Contains the diagonal element associated with the added row.
154*> \endverbatim
155*>
156*> \param[in] BETA
157*> \verbatim
158*> BETA is REAL
159*> Contains the off-diagonal element associated with the added
160*> row.
161*> \endverbatim
162*>
163*> \param[out] DSIGMA
164*> \verbatim
165*> DSIGMA is REAL array, dimension ( N )
166*> Contains a copy of the diagonal elements (K-1 singular values
167*> and one zero) in the secular equation.
168*> \endverbatim
169*>
170*> \param[out] IDX
171*> \verbatim
172*> IDX is INTEGER array, dimension ( N )
173*> This will contain the permutation used to sort the contents of
174*> D into ascending order.
175*> \endverbatim
176*>
177*> \param[out] IDXP
178*> \verbatim
179*> IDXP is INTEGER array, dimension ( N )
180*> This will contain the permutation used to place deflated
181*> values of D at the end of the array. On output IDXP(2:K)
182*> points to the nondeflated D-values and IDXP(K+1:N)
183*> points to the deflated singular values.
184*> \endverbatim
185*>
186*> \param[in] IDXQ
187*> \verbatim
188*> IDXQ is INTEGER array, dimension ( N )
189*> This contains the permutation which separately sorts the two
190*> sub-problems in D into ascending order. Note that entries in
191*> the first half of this permutation must first be moved one
192*> position backward; and entries in the second half
193*> must first have NL+1 added to their values.
194*> \endverbatim
195*>
196*> \param[out] PERM
197*> \verbatim
198*> PERM is INTEGER array, dimension ( N )
199*> The permutations (from deflation and sorting) to be applied
200*> to each singular block. Not referenced if ICOMPQ = 0.
201*> \endverbatim
202*>
203*> \param[out] GIVPTR
204*> \verbatim
205*> GIVPTR is INTEGER
206*> The number of Givens rotations which took place in this
207*> subproblem. Not referenced if ICOMPQ = 0.
208*> \endverbatim
209*>
210*> \param[out] GIVCOL
211*> \verbatim
212*> GIVCOL is INTEGER array, dimension ( LDGCOL, 2 )
213*> Each pair of numbers indicates a pair of columns to take place
214*> in a Givens rotation. Not referenced if ICOMPQ = 0.
215*> \endverbatim
216*>
217*> \param[in] LDGCOL
218*> \verbatim
219*> LDGCOL is INTEGER
220*> The leading dimension of GIVCOL, must be at least N.
221*> \endverbatim
222*>
223*> \param[out] GIVNUM
224*> \verbatim
225*> GIVNUM is REAL array, dimension ( LDGNUM, 2 )
226*> Each number indicates the C or S value to be used in the
227*> corresponding Givens rotation. Not referenced if ICOMPQ = 0.
228*> \endverbatim
229*>
230*> \param[in] LDGNUM
231*> \verbatim
232*> LDGNUM is INTEGER
233*> The leading dimension of GIVNUM, must be at least N.
234*> \endverbatim
235*>
236*> \param[out] C
237*> \verbatim
238*> C is REAL
239*> C contains garbage if SQRE =0 and the C-value of a Givens
240*> rotation related to the right null space if SQRE = 1.
241*> \endverbatim
242*>
243*> \param[out] S
244*> \verbatim
245*> S is REAL
246*> S contains garbage if SQRE =0 and the S-value of a Givens
247*> rotation related to the right null space if SQRE = 1.
248*> \endverbatim
249*>
250*> \param[out] INFO
251*> \verbatim
252*> INFO is INTEGER
253*> = 0: successful exit.
254*> < 0: if INFO = -i, the i-th argument had an illegal value.
255*> \endverbatim
256*
257* Authors:
258* ========
259*
260*> \author Univ. of Tennessee
261*> \author Univ. of California Berkeley
262*> \author Univ. of Colorado Denver
263*> \author NAG Ltd.
264*
265*> \ingroup lasd7
266*
267*> \par Contributors:
268* ==================
269*>
270*> Ming Gu and Huan Ren, Computer Science Division, University of
271*> California at Berkeley, USA
272*>
273* =====================================================================
274 SUBROUTINE slasd7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW,
275 $ VL,
276 $ VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ,
277 $ PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
278 $ C, S, INFO )
279*
280* -- LAPACK auxiliary routine --
281* -- LAPACK is a software package provided by Univ. of Tennessee, --
282* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
283*
284* .. Scalar Arguments ..
285 INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
286 $ NR, SQRE
287 REAL ALPHA, BETA, C, S
288* ..
289* .. Array Arguments ..
290 INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ),
291 $ idxq( * ), perm( * )
292 REAL D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ),
293 $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ),
294 $ zw( * )
295* ..
296*
297* =====================================================================
298*
299* .. Parameters ..
300 REAL ZERO, ONE, TWO, EIGHT
301 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0, two = 2.0e+0,
302 $ eight = 8.0e+0 )
303* ..
304* .. Local Scalars ..
305*
306 INTEGER I, IDXI, IDXJ, IDXJP, J, JP, JPREV, K2, M, N,
307 $ NLP1, NLP2
308 REAL EPS, HLFTOL, TAU, TOL, Z1
309* ..
310* .. External Subroutines ..
311 EXTERNAL scopy, slamrg, srot, xerbla
312* ..
313* .. External Functions ..
314 REAL SLAMCH, SLAPY2
315 EXTERNAL slamch, slapy2
316* ..
317* .. Intrinsic Functions ..
318 INTRINSIC abs, max
319* ..
320* .. Executable Statements ..
321*
322* Test the input parameters.
323*
324 info = 0
325 n = nl + nr + 1
326 m = n + sqre
327*
328 IF( ( icompq.LT.0 ) .OR. ( icompq.GT.1 ) ) THEN
329 info = -1
330 ELSE IF( nl.LT.1 ) THEN
331 info = -2
332 ELSE IF( nr.LT.1 ) THEN
333 info = -3
334 ELSE IF( ( sqre.LT.0 ) .OR. ( sqre.GT.1 ) ) THEN
335 info = -4
336 ELSE IF( ldgcol.LT.n ) THEN
337 info = -22
338 ELSE IF( ldgnum.LT.n ) THEN
339 info = -24
340 END IF
341 IF( info.NE.0 ) THEN
342 CALL xerbla( 'SLASD7', -info )
343 RETURN
344 END IF
345*
346 nlp1 = nl + 1
347 nlp2 = nl + 2
348 IF( icompq.EQ.1 ) THEN
349 givptr = 0
350 END IF
351*
352* Generate the first part of the vector Z and move the singular
353* values in the first part of D one position backward.
354*
355 z1 = alpha*vl( nlp1 )
356 vl( nlp1 ) = zero
357 tau = vf( nlp1 )
358 DO 10 i = nl, 1, -1
359 z( i+1 ) = alpha*vl( i )
360 vl( i ) = zero
361 vf( i+1 ) = vf( i )
362 d( i+1 ) = d( i )
363 idxq( i+1 ) = idxq( i ) + 1
364 10 CONTINUE
365 vf( 1 ) = tau
366*
367* Generate the second part of the vector Z.
368*
369 DO 20 i = nlp2, m
370 z( i ) = beta*vf( i )
371 vf( i ) = zero
372 20 CONTINUE
373*
374* Sort the singular values into increasing order
375*
376 DO 30 i = nlp2, n
377 idxq( i ) = idxq( i ) + nlp1
378 30 CONTINUE
379*
380* DSIGMA, IDXC, IDXC, and ZW are used as storage space.
381*
382 DO 40 i = 2, n
383 dsigma( i ) = d( idxq( i ) )
384 zw( i ) = z( idxq( i ) )
385 vfw( i ) = vf( idxq( i ) )
386 vlw( i ) = vl( idxq( i ) )
387 40 CONTINUE
388*
389 CALL slamrg( nl, nr, dsigma( 2 ), 1, 1, idx( 2 ) )
390*
391 DO 50 i = 2, n
392 idxi = 1 + idx( i )
393 d( i ) = dsigma( idxi )
394 z( i ) = zw( idxi )
395 vf( i ) = vfw( idxi )
396 vl( i ) = vlw( idxi )
397 50 CONTINUE
398*
399* Calculate the allowable deflation tolerance
400*
401 eps = slamch( 'Epsilon' )
402 tol = max( abs( alpha ), abs( beta ) )
403 tol = eight*eight*eps*max( abs( d( n ) ), tol )
404*
405* There are 2 kinds of deflation -- first a value in the z-vector
406* is small, second two (or more) singular values are very close
407* together (their difference is small).
408*
409* If the value in the z-vector is small, we simply permute the
410* array so that the corresponding singular value is moved to the
411* end.
412*
413* If two values in the D-vector are close, we perform a two-sided
414* rotation designed to make one of the corresponding z-vector
415* entries zero, and then permute the array so that the deflated
416* singular value is moved to the end.
417*
418* If there are multiple singular values then the problem deflates.
419* Here the number of equal singular values are found. As each equal
420* singular value is found, an elementary reflector is computed to
421* rotate the corresponding singular subspace so that the
422* corresponding components of Z are zero in this new basis.
423*
424 k = 1
425 k2 = n + 1
426 DO 60 j = 2, n
427 IF( abs( z( j ) ).LE.tol ) THEN
428*
429* Deflate due to small z component.
430*
431 k2 = k2 - 1
432 idxp( k2 ) = j
433 IF( j.EQ.n )
434 $ GO TO 100
435 ELSE
436 jprev = j
437 GO TO 70
438 END IF
439 60 CONTINUE
440 70 CONTINUE
441 j = jprev
442 80 CONTINUE
443 j = j + 1
444 IF( j.GT.n )
445 $ GO TO 90
446 IF( abs( z( j ) ).LE.tol ) THEN
447*
448* Deflate due to small z component.
449*
450 k2 = k2 - 1
451 idxp( k2 ) = j
452 ELSE
453*
454* Check if singular values are close enough to allow deflation.
455*
456 IF( abs( d( j )-d( jprev ) ).LE.tol ) THEN
457*
458* Deflation is possible.
459*
460 s = z( jprev )
461 c = z( j )
462*
463* Find sqrt(a**2+b**2) without overflow or
464* destructive underflow.
465*
466 tau = slapy2( c, s )
467 z( j ) = tau
468 z( jprev ) = zero
469 c = c / tau
470 s = -s / tau
471*
472* Record the appropriate Givens rotation
473*
474 IF( icompq.EQ.1 ) THEN
475 givptr = givptr + 1
476 idxjp = idxq( idx( jprev )+1 )
477 idxj = idxq( idx( j )+1 )
478 IF( idxjp.LE.nlp1 ) THEN
479 idxjp = idxjp - 1
480 END IF
481 IF( idxj.LE.nlp1 ) THEN
482 idxj = idxj - 1
483 END IF
484 givcol( givptr, 2 ) = idxjp
485 givcol( givptr, 1 ) = idxj
486 givnum( givptr, 2 ) = c
487 givnum( givptr, 1 ) = s
488 END IF
489 CALL srot( 1, vf( jprev ), 1, vf( j ), 1, c, s )
490 CALL srot( 1, vl( jprev ), 1, vl( j ), 1, c, s )
491 k2 = k2 - 1
492 idxp( k2 ) = jprev
493 jprev = j
494 ELSE
495 k = k + 1
496 zw( k ) = z( jprev )
497 dsigma( k ) = d( jprev )
498 idxp( k ) = jprev
499 jprev = j
500 END IF
501 END IF
502 GO TO 80
503 90 CONTINUE
504*
505* Record the last singular value.
506*
507 k = k + 1
508 zw( k ) = z( jprev )
509 dsigma( k ) = d( jprev )
510 idxp( k ) = jprev
511*
512 100 CONTINUE
513*
514* Sort the singular values into DSIGMA. The singular values which
515* were not deflated go into the first K slots of DSIGMA, except
516* that DSIGMA(1) is treated separately.
517*
518 DO 110 j = 2, n
519 jp = idxp( j )
520 dsigma( j ) = d( jp )
521 vfw( j ) = vf( jp )
522 vlw( j ) = vl( jp )
523 110 CONTINUE
524 IF( icompq.EQ.1 ) THEN
525 DO 120 j = 2, n
526 jp = idxp( j )
527 perm( j ) = idxq( idx( jp )+1 )
528 IF( perm( j ).LE.nlp1 ) THEN
529 perm( j ) = perm( j ) - 1
530 END IF
531 120 CONTINUE
532 END IF
533*
534* The deflated singular values go back into the last N - K slots of
535* D.
536*
537 CALL scopy( n-k, dsigma( k+1 ), 1, d( k+1 ), 1 )
538*
539* Determine DSIGMA(1), DSIGMA(2), Z(1), VF(1), VL(1), VF(M), and
540* VL(M).
541*
542 dsigma( 1 ) = zero
543 hlftol = tol / two
544 IF( abs( dsigma( 2 ) ).LE.hlftol )
545 $ dsigma( 2 ) = hlftol
546 IF( m.GT.n ) THEN
547 z( 1 ) = slapy2( z1, z( m ) )
548 IF( z( 1 ).LE.tol ) THEN
549 c = one
550 s = zero
551 z( 1 ) = tol
552 ELSE
553 c = z1 / z( 1 )
554 s = -z( m ) / z( 1 )
555 END IF
556 CALL srot( 1, vf( m ), 1, vf( 1 ), 1, c, s )
557 CALL srot( 1, vl( m ), 1, vl( 1 ), 1, c, s )
558 ELSE
559 IF( abs( z1 ).LE.tol ) THEN
560 z( 1 ) = tol
561 ELSE
562 z( 1 ) = z1
563 END IF
564 END IF
565*
566* Restore Z, VF, and VL.
567*
568 CALL scopy( k-1, zw( 2 ), 1, z( 2 ), 1 )
569 CALL scopy( n-1, vfw( 2 ), 1, vf( 2 ), 1 )
570 CALL scopy( n-1, vlw( 2 ), 1, vl( 2 ), 1 )
571*
572 RETURN
573*
574* End of SLASD7
575*
576 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine scopy(n, sx, incx, sy, incy)
SCOPY
Definition scopy.f:82
subroutine slamrg(n1, n2, a, strd1, strd2, index)
SLAMRG creates a permutation list to merge the entries of two independently sorted sets into a single...
Definition slamrg.f:97
subroutine slasd7(icompq, nl, nr, sqre, k, d, z, zw, vf, vfw, vl, vlw, alpha, beta, dsigma, idx, idxp, idxq, perm, givptr, givcol, ldgcol, givnum, ldgnum, c, s, info)
SLASD7 merges the two sets of singular values together into a single sorted set. Then it tries to def...
Definition slasd7.f:279
subroutine srot(n, sx, incx, sy, incy, c, s)
SROT
Definition srot.f:92