1 *> \brief \b SLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLALSA + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slalsa.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slalsa.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slalsa.f">
21 * SUBROUTINE SLALSA( ICOMPQ, SMLSIZ, N, NRHS, B, LDB, BX, LDBX, U,
22 * LDU, VT, K, DIFL, DIFR, Z, POLES, GIVPTR,
23 * GIVCOL, LDGCOL, PERM, GIVNUM, C, S, WORK,
26 * .. Scalar Arguments ..
27 * INTEGER ICOMPQ, INFO, LDB, LDBX, LDGCOL, LDU, N, NRHS,
30 * .. Array Arguments ..
31 * INTEGER GIVCOL( LDGCOL, * ), GIVPTR( * ), IWORK( * ),
32 * $ K( * ), PERM( LDGCOL, * )
33 * REAL B( LDB, * ), BX( LDBX, * ), C( * ),
34 * $ DIFL( LDU, * ), DIFR( LDU, * ),
35 * $ GIVNUM( LDU, * ), POLES( LDU, * ), S( * ),
36 * $ U( LDU, * ), VT( LDU, * ), WORK( * ),
46 *> SLALSA is an itermediate step in solving the least squares problem
47 *> by computing the SVD of the coefficient matrix in compact form (The
48 *> singular vectors are computed as products of simple orthorgonal
51 *> If ICOMPQ = 0, SLALSA applies the inverse of the left singular vector
52 *> matrix of an upper bidiagonal matrix to the right hand side; and if
53 *> ICOMPQ = 1, SLALSA applies the right singular vector matrix to the
54 *> right hand side. The singular vector matrices were generated in
55 *> compact form by SLALSA.
64 *> Specifies whether the left or the right singular vector
65 *> matrix is involved.
66 *> = 0: Left singular vector matrix
67 *> = 1: Right singular vector matrix
73 *> The maximum size of the subproblems at the bottom of the
80 *> The row and column dimensions of the upper bidiagonal matrix.
86 *> The number of columns of B and BX. NRHS must be at least 1.
91 *> B is REAL array, dimension ( LDB, NRHS )
92 *> On input, B contains the right hand sides of the least
93 *> squares problem in rows 1 through M.
94 *> On output, B contains the solution X in rows 1 through N.
100 *> The leading dimension of B in the calling subprogram.
101 *> LDB must be at least max(1,MAX( M, N ) ).
106 *> BX is REAL array, dimension ( LDBX, NRHS )
107 *> On exit, the result of applying the left or right singular
108 *> vector matrix to B.
114 *> The leading dimension of BX.
119 *> U is REAL array, dimension ( LDU, SMLSIZ ).
120 *> On entry, U contains the left singular vector matrices of all
121 *> subproblems at the bottom level.
126 *> LDU is INTEGER, LDU = > N.
127 *> The leading dimension of arrays U, VT, DIFL, DIFR,
128 *> POLES, GIVNUM, and Z.
133 *> VT is REAL array, dimension ( LDU, SMLSIZ+1 ).
134 *> On entry, VT**T contains the right singular vector matrices of
135 *> all subproblems at the bottom level.
140 *> K is INTEGER array, dimension ( N ).
145 *> DIFL is REAL array, dimension ( LDU, NLVL ).
146 *> where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1.
151 *> DIFR is REAL array, dimension ( LDU, 2 * NLVL ).
152 *> On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record
153 *> distances between singular values on the I-th level and
154 *> singular values on the (I -1)-th level, and DIFR(*, 2 * I)
155 *> record the normalizing factors of the right singular vectors
156 *> matrices of subproblems on I-th level.
161 *> Z is REAL array, dimension ( LDU, NLVL ).
162 *> On entry, Z(1, I) contains the components of the deflation-
163 *> adjusted updating row vector for subproblems on the I-th
169 *> POLES is REAL array, dimension ( LDU, 2 * NLVL ).
170 *> On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old
171 *> singular values involved in the secular equations on the I-th
177 *> GIVPTR is INTEGER array, dimension ( N ).
178 *> On entry, GIVPTR( I ) records the number of Givens
179 *> rotations performed on the I-th problem on the computation
185 *> GIVCOL is INTEGER array, dimension ( LDGCOL, 2 * NLVL ).
186 *> On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the
187 *> locations of Givens rotations performed on the I-th level on
188 *> the computation tree.
193 *> LDGCOL is INTEGER, LDGCOL = > N.
194 *> The leading dimension of arrays GIVCOL and PERM.
199 *> PERM is INTEGER array, dimension ( LDGCOL, NLVL ).
200 *> On entry, PERM(*, I) records permutations done on the I-th
201 *> level of the computation tree.
206 *> GIVNUM is REAL array, dimension ( LDU, 2 * NLVL ).
207 *> On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S-
208 *> values of Givens rotations performed on the I-th level on the
214 *> C is REAL array, dimension ( N ).
215 *> On entry, if the I-th subproblem is not square,
216 *> C( I ) contains the C-value of a Givens rotation related to
217 *> the right null space of the I-th subproblem.
222 *> S is REAL array, dimension ( N ).
223 *> On entry, if the I-th subproblem is not square,
224 *> S( I ) contains the S-value of a Givens rotation related to
225 *> the right null space of the I-th subproblem.
230 *> WORK is REAL array.
231 *> The dimension must be at least N.
236 *> IWORK is INTEGER array.
237 *> The dimension must be at least 3 * N
243 *> = 0: successful exit.
244 *> < 0: if INFO = -i, the i-th argument had an illegal value.
250 *> \author Univ. of Tennessee
251 *> \author Univ. of California Berkeley
252 *> \author Univ. of Colorado Denver
255 *> \date September 2012
257 *> \ingroup realOTHERcomputational
259 *> \par Contributors:
262 *> Ming Gu and Ren-Cang Li, Computer Science Division, University of
263 *> California at Berkeley, USA \n
264 *> Osni Marques, LBNL/NERSC, USA \n
266 * =====================================================================
267 SUBROUTINE SLALSA( ICOMPQ, SMLSIZ, N, NRHS, B, LDB, BX, LDBX, U,
268 $ LDU, VT, K, DIFL, DIFR, Z, POLES, GIVPTR,
269 $ GIVCOL, LDGCOL, PERM, GIVNUM, C, S, WORK,
272 * -- LAPACK computational routine (version 3.4.2) --
273 * -- LAPACK is a software package provided by Univ. of Tennessee, --
274 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
277 * .. Scalar Arguments ..
278 INTEGER ICOMPQ, INFO, LDB, LDBX, LDGCOL, LDU, N, NRHS,
281 * .. Array Arguments ..
282 INTEGER GIVCOL( LDGCOL, * ), GIVPTR( * ), IWORK( * ),
283 $ K( * ), PERM( LDGCOL, * )
284 REAL B( LDB, * ), BX( LDBX, * ), C( * ),
285 $ DIFL( LDU, * ), DIFR( LDU, * ),
286 $ GIVNUM( LDU, * ), POLES( LDU, * ), S( * ),
287 $ U( LDU, * ), VT( LDU, * ), WORK( * ),
291 * =====================================================================
295 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
297 * .. Local Scalars ..
298 INTEGER I, I1, IC, IM1, INODE, J, LF, LL, LVL, LVL2,
299 $ ND, NDB1, NDIML, NDIMR, NL, NLF, NLP1, NLVL,
300 $ NR, NRF, NRP1, SQRE
302 * .. External Subroutines ..
303 EXTERNAL SCOPY, SGEMM, SLALS0, SLASDT, XERBLA
305 * .. Executable Statements ..
307 * Test the input parameters.
311 IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
313 ELSE IF( SMLSIZ.LT.3 ) THEN
315 ELSE IF( N.LT.SMLSIZ ) THEN
317 ELSE IF( NRHS.LT.1 ) THEN
319 ELSE IF( LDB.LT.N ) THEN
321 ELSE IF( LDBX.LT.N ) THEN
323 ELSE IF( LDU.LT.N ) THEN
325 ELSE IF( LDGCOL.LT.N ) THEN
329 CALL XERBLA( 'SLALSA', -INFO )
333 * Book-keeping and setting up the computation tree.
339 CALL SLASDT( N, NLVL, ND, IWORK( INODE ), IWORK( NDIML ),
340 $ IWORK( NDIMR ), SMLSIZ )
342 * The following code applies back the left singular vector factors.
343 * For applying back the right singular vector factors, go to 50.
345 IF( ICOMPQ.EQ.1 ) THEN
349 * The nodes on the bottom level of the tree were solved
350 * by SLASDQ. The corresponding left and right singular vector
351 * matrices are in explicit form. First apply back the left
352 * singular vector matrices.
357 * IC : center row of each node
358 * NL : number of rows of left subproblem
359 * NR : number of rows of right subproblem
360 * NLF: starting row of the left subproblem
361 * NRF: starting row of the right subproblem
364 IC = IWORK( INODE+I1 )
365 NL = IWORK( NDIML+I1 )
366 NR = IWORK( NDIMR+I1 )
369 CALL SGEMM( 'T', 'N', NL, NRHS, NL, ONE, U( NLF, 1 ), LDU,
370 $ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
371 CALL SGEMM( 'T', 'N', NR, NRHS, NR, ONE, U( NRF, 1 ), LDU,
372 $ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )
375 * Next copy the rows of B that correspond to unchanged rows
376 * in the bidiagonal matrix to BX.
379 IC = IWORK( INODE+I-1 )
380 CALL SCOPY( NRHS, B( IC, 1 ), LDB, BX( IC, 1 ), LDBX )
383 * Finally go through the left singular vector matrices of all
384 * the other subproblems bottom-up on the tree.
389 DO 40 LVL = NLVL, 1, -1
392 * find the first node LF and last node LL on
393 * the current level LVL
404 IC = IWORK( INODE+IM1 )
405 NL = IWORK( NDIML+IM1 )
406 NR = IWORK( NDIMR+IM1 )
410 CALL SLALS0( ICOMPQ, NL, NR, SQRE, NRHS, BX( NLF, 1 ), LDBX,
411 $ B( NLF, 1 ), LDB, PERM( NLF, LVL ),
412 $ GIVPTR( J ), GIVCOL( NLF, LVL2 ), LDGCOL,
413 $ GIVNUM( NLF, LVL2 ), LDU, POLES( NLF, LVL2 ),
414 $ DIFL( NLF, LVL ), DIFR( NLF, LVL2 ),
415 $ Z( NLF, LVL ), K( J ), C( J ), S( J ), WORK,
421 * ICOMPQ = 1: applying back the right singular vector factors.
425 * First now go through the right singular vector matrices of all
426 * the tree nodes top-down.
432 * Find the first node LF and last node LL on
433 * the current level LVL.
444 IC = IWORK( INODE+IM1 )
445 NL = IWORK( NDIML+IM1 )
446 NR = IWORK( NDIMR+IM1 )
455 CALL SLALS0( ICOMPQ, NL, NR, SQRE, NRHS, B( NLF, 1 ), LDB,
456 $ BX( NLF, 1 ), LDBX, PERM( NLF, LVL ),
457 $ GIVPTR( J ), GIVCOL( NLF, LVL2 ), LDGCOL,
458 $ GIVNUM( NLF, LVL2 ), LDU, POLES( NLF, LVL2 ),
459 $ DIFL( NLF, LVL ), DIFR( NLF, LVL2 ),
460 $ Z( NLF, LVL ), K( J ), C( J ), S( J ), WORK,
465 * The nodes on the bottom level of the tree were solved
466 * by SLASDQ. The corresponding right singular vector
467 * matrices are in explicit form. Apply them back.
472 IC = IWORK( INODE+I1 )
473 NL = IWORK( NDIML+I1 )
474 NR = IWORK( NDIMR+I1 )
483 CALL SGEMM( 'T', 'N', NLP1, NRHS, NLP1, ONE, VT( NLF, 1 ), LDU,
484 $ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
485 CALL SGEMM( 'T', 'N', NRP1, NRHS, NRP1, ONE, VT( NRF, 1 ), LDU,
486 $ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )