1 *> \brief \b SLASD6 computes the SVD of an updated upper bidiagonal matrix obtained by merging two smaller ones by appending a row. Used by sbdsdc.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLASD6 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasd6.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasd6.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasd6.f">
21 * SUBROUTINE SLASD6( ICOMPQ, NL, NR, SQRE, D, VF, VL, ALPHA, BETA,
22 * IDXQ, PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM,
23 * LDGNUM, POLES, DIFL, DIFR, Z, K, C, S, WORK,
26 * .. Scalar Arguments ..
27 * INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
29 * REAL ALPHA, BETA, C, S
31 * .. Array Arguments ..
32 * INTEGER GIVCOL( LDGCOL, * ), IDXQ( * ), IWORK( * ),
34 * REAL D( * ), DIFL( * ), DIFR( * ),
35 * $ GIVNUM( LDGNUM, * ), POLES( LDGNUM, * ),
36 * $ VF( * ), VL( * ), WORK( * ), Z( * )
45 *> SLASD6 computes the SVD of an updated upper bidiagonal matrix B
46 *> obtained by merging two smaller ones by appending a row. This
47 *> routine is used only for the problem which requires all singular
48 *> values and optionally singular vector matrices in factored form.
49 *> B is an N-by-M matrix with N = NL + NR + 1 and M = N + SQRE.
50 *> A related subroutine, SLASD1, handles the case in which all singular
51 *> values and singular vectors of the bidiagonal matrix are desired.
53 *> SLASD6 computes the SVD as follows:
56 *> B = U(in) * ( Z1**T a Z2**T b ) * VT(in)
59 *> = U(out) * ( D(out) 0) * VT(out)
61 *> where Z**T = (Z1**T a Z2**T b) = u**T VT**T, and u is a vector of dimension M
62 *> with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros
63 *> elsewhere; and the entry b is empty if SQRE = 0.
65 *> The singular values of B can be computed using D1, D2, the first
66 *> components of all the right singular vectors of the lower block, and
67 *> the last components of all the right singular vectors of the upper
68 *> block. These components are stored and updated in VF and VL,
69 *> respectively, in SLASD6. Hence U and VT are not explicitly
72 *> The singular values are stored in D. The algorithm consists of two
75 *> The first stage consists of deflating the size of the problem
76 *> when there are multiple singular values or if there is a zero
77 *> in the Z vector. For each such occurrence the dimension of the
78 *> secular equation problem is reduced by one. This stage is
79 *> performed by the routine SLASD7.
81 *> The second stage consists of calculating the updated
82 *> singular values. This is done by finding the roots of the
83 *> secular equation via the routine SLASD4 (as called by SLASD8).
84 *> This routine also updates VF and VL and computes the distances
85 *> between the updated singular values and the old singular
88 *> SLASD6 is called from SLASDA.
97 *> Specifies whether singular vectors are to be computed in
99 *> = 0: Compute singular values only.
100 *> = 1: Compute singular vectors in factored form as well.
106 *> The row dimension of the upper block. NL >= 1.
112 *> The row dimension of the lower block. NR >= 1.
118 *> = 0: the lower block is an NR-by-NR square matrix.
119 *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
121 *> The bidiagonal matrix has row dimension N = NL + NR + 1,
122 *> and column dimension M = N + SQRE.
127 *> D is REAL array, dimension (NL+NR+1).
128 *> On entry D(1:NL,1:NL) contains the singular values of the
129 *> upper block, and D(NL+2:N) contains the singular values
130 *> of the lower block. On exit D(1:N) contains the singular
131 *> values of the modified matrix.
136 *> VF is REAL array, dimension (M)
137 *> On entry, VF(1:NL+1) contains the first components of all
138 *> right singular vectors of the upper block; and VF(NL+2:M)
139 *> contains the first components of all right singular vectors
140 *> of the lower block. On exit, VF contains the first components
141 *> of all right singular vectors of the bidiagonal matrix.
146 *> VL is REAL array, dimension (M)
147 *> On entry, VL(1:NL+1) contains the last components of all
148 *> right singular vectors of the upper block; and VL(NL+2:M)
149 *> contains the last components of all right singular vectors of
150 *> the lower block. On exit, VL contains the last components of
151 *> all right singular vectors of the bidiagonal matrix.
154 *> \param[in,out] ALPHA
157 *> Contains the diagonal element associated with the added row.
160 *> \param[in,out] BETA
163 *> Contains the off-diagonal element associated with the added
167 *> \param[in,out] IDXQ
169 *> IDXQ is INTEGER array, dimension (N)
170 *> This contains the permutation which will reintegrate the
171 *> subproblem just solved back into sorted order, i.e.
172 *> D( IDXQ( I = 1, N ) ) will be in ascending order.
177 *> PERM is INTEGER array, dimension ( N )
178 *> The permutations (from deflation and sorting) to be applied
179 *> to each block. Not referenced if ICOMPQ = 0.
182 *> \param[out] GIVPTR
185 *> The number of Givens rotations which took place in this
186 *> subproblem. Not referenced if ICOMPQ = 0.
189 *> \param[out] GIVCOL
191 *> GIVCOL is INTEGER array, dimension ( LDGCOL, 2 )
192 *> Each pair of numbers indicates a pair of columns to take place
193 *> in a Givens rotation. Not referenced if ICOMPQ = 0.
199 *> leading dimension of GIVCOL, must be at least N.
202 *> \param[out] GIVNUM
204 *> GIVNUM is REAL array, dimension ( LDGNUM, 2 )
205 *> Each number indicates the C or S value to be used in the
206 *> corresponding Givens rotation. Not referenced if ICOMPQ = 0.
212 *> The leading dimension of GIVNUM and POLES, must be at least N.
217 *> POLES is REAL array, dimension ( LDGNUM, 2 )
218 *> On exit, POLES(1,*) is an array containing the new singular
219 *> values obtained from solving the secular equation, and
220 *> POLES(2,*) is an array containing the poles in the secular
221 *> equation. Not referenced if ICOMPQ = 0.
226 *> DIFL is REAL array, dimension ( N )
227 *> On exit, DIFL(I) is the distance between I-th updated
228 *> (undeflated) singular value and the I-th (undeflated) old
234 *> DIFR is REAL array,
235 *> dimension ( LDDIFR, 2 ) if ICOMPQ = 1 and
236 *> dimension ( K ) if ICOMPQ = 0.
237 *> On exit, DIFR(I,1) = D(I) - DSIGMA(I+1), DIFR(K,1) is not
238 *> defined and will not be referenced.
240 *> If ICOMPQ = 1, DIFR(1:K,2) is an array containing the
241 *> normalizing factors for the right singular vector matrix.
243 *> See SLASD8 for details on DIFL and DIFR.
248 *> Z is REAL array, dimension ( M )
249 *> The first elements of this array contain the components
250 *> of the deflation-adjusted updating row vector.
256 *> Contains the dimension of the non-deflated matrix,
257 *> This is the order of the related secular equation. 1 <= K <=N.
263 *> C contains garbage if SQRE =0 and the C-value of a Givens
264 *> rotation related to the right null space if SQRE = 1.
270 *> S contains garbage if SQRE =0 and the S-value of a Givens
271 *> rotation related to the right null space if SQRE = 1.
276 *> WORK is REAL array, dimension ( 4 * M )
281 *> IWORK is INTEGER array, dimension ( 3 * N )
287 *> = 0: successful exit.
288 *> < 0: if INFO = -i, the i-th argument had an illegal value.
289 *> > 0: if INFO = 1, a singular value did not converge
295 *> \author Univ. of Tennessee
296 *> \author Univ. of California Berkeley
297 *> \author Univ. of Colorado Denver
302 *> \ingroup OTHERauxiliary
304 *> \par Contributors:
307 *> Ming Gu and Huan Ren, Computer Science Division, University of
308 *> California at Berkeley, USA
310 * =====================================================================
311 SUBROUTINE SLASD6( ICOMPQ, NL, NR, SQRE, D, VF, VL, ALPHA, BETA,
312 $ IDXQ, PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM,
313 $ LDGNUM, POLES, DIFL, DIFR, Z, K, C, S, WORK,
316 * -- LAPACK auxiliary routine (version 3.6.1) --
317 * -- LAPACK is a software package provided by Univ. of Tennessee, --
318 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
321 * .. Scalar Arguments ..
322 INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
324 REAL ALPHA, BETA, C, S
326 * .. Array Arguments ..
327 INTEGER GIVCOL( LDGCOL, * ), IDXQ( * ), IWORK( * ),
329 REAL D( * ), DIFL( * ), DIFR( * ),
330 $ GIVNUM( LDGNUM, * ), POLES( LDGNUM, * ),
331 $ VF( * ), VL( * ), WORK( * ), Z( * )
334 * =====================================================================
338 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
340 * .. Local Scalars ..
341 INTEGER I, IDX, IDXC, IDXP, ISIGMA, IVFW, IVLW, IW, M,
345 * .. External Subroutines ..
346 EXTERNAL SCOPY, SLAMRG, SLASCL, SLASD7, SLASD8, XERBLA
348 * .. Intrinsic Functions ..
351 * .. Executable Statements ..
353 * Test the input parameters.
359 IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
361 ELSE IF( NL.LT.1 ) THEN
363 ELSE IF( NR.LT.1 ) THEN
365 ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
367 ELSE IF( LDGCOL.LT.N ) THEN
369 ELSE IF( LDGNUM.LT.N ) THEN
373 CALL XERBLA( 'SLASD6', -INFO )
377 * The following values are for bookkeeping purposes only. They are
378 * integer pointers which indicate the portion of the workspace
379 * used by a particular array in SLASD7 and SLASD8.
392 ORGNRM = MAX( ABS( ALPHA ), ABS( BETA ) )
395 IF( ABS( D( I ) ).GT.ORGNRM ) THEN
396 ORGNRM = ABS( D( I ) )
399 CALL SLASCL( 'G', 0, 0, ORGNRM, ONE, N, 1, D, N, INFO )
400 ALPHA = ALPHA / ORGNRM
403 * Sort and Deflate singular values.
405 CALL SLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, WORK( IW ), VF,
406 $ WORK( IVFW ), VL, WORK( IVLW ), ALPHA, BETA,
407 $ WORK( ISIGMA ), IWORK( IDX ), IWORK( IDXP ), IDXQ,
408 $ PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, C, S,
411 * Solve Secular Equation, compute DIFL, DIFR, and update VF, VL.
413 CALL SLASD8( ICOMPQ, K, D, Z, VF, VL, DIFL, DIFR, LDGNUM,
414 $ WORK( ISIGMA ), WORK( IW ), INFO )
416 * Report the possible convergence failure.
422 * Save the poles if ICOMPQ = 1.
424 IF( ICOMPQ.EQ.1 ) THEN
425 CALL SCOPY( K, D, 1, POLES( 1, 1 ), 1 )
426 CALL SCOPY( K, WORK( ISIGMA ), 1, POLES( 1, 2 ), 1 )
431 CALL SLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
433 * Prepare the IDXQ sorting permutation.
437 CALL SLAMRG( N1, N2, D, 1, -1, IDXQ )