1 *> \brief \b SLALS0 applies back multiplying factors in solving the least squares problem using divide and conquer SVD approach. Used by sgelsd.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLALS0 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slals0.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slals0.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slals0.f">
21 * SUBROUTINE SLALS0( ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX,
22 * PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
23 * POLES, DIFL, DIFR, Z, K, C, S, WORK, INFO )
25 * .. Scalar Arguments ..
26 * INTEGER GIVPTR, ICOMPQ, INFO, K, LDB, LDBX, LDGCOL,
27 * $ LDGNUM, NL, NR, NRHS, SQRE
30 * .. Array Arguments ..
31 * INTEGER GIVCOL( LDGCOL, * ), PERM( * )
32 * REAL B( LDB, * ), BX( LDBX, * ), DIFL( * ),
33 * $ DIFR( LDGNUM, * ), GIVNUM( LDGNUM, * ),
34 * $ POLES( LDGNUM, * ), WORK( * ), Z( * )
43 *> SLALS0 applies back the multiplying factors of either the left or the
44 *> right singular vector matrix of a diagonal matrix appended by a row
45 *> to the right hand side matrix B in solving the least squares problem
46 *> using the divide-and-conquer SVD approach.
48 *> For the left singular vector matrix, three types of orthogonal
49 *> matrices are involved:
51 *> (1L) Givens rotations: the number of such rotations is GIVPTR; the
52 *> pairs of columns/rows they were applied to are stored in GIVCOL;
53 *> and the C- and S-values of these rotations are stored in GIVNUM.
55 *> (2L) Permutation. The (NL+1)-st row of B is to be moved to the first
56 *> row, and for J=2:N, PERM(J)-th row of B is to be moved to the
59 *> (3L) The left singular vector matrix of the remaining matrix.
61 *> For the right singular vector matrix, four types of orthogonal
62 *> matrices are involved:
64 *> (1R) The right singular vector matrix of the remaining matrix.
66 *> (2R) If SQRE = 1, one extra Givens rotation to generate the right
69 *> (3R) The inverse transformation of (2L).
71 *> (4R) The inverse transformation of (1L).
80 *> Specifies whether singular vectors are to be computed in
82 *> = 0: Left singular vector matrix.
83 *> = 1: Right singular vector matrix.
89 *> The row dimension of the upper block. NL >= 1.
95 *> The row dimension of the lower block. NR >= 1.
101 *> = 0: the lower block is an NR-by-NR square matrix.
102 *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
104 *> The bidiagonal matrix has row dimension N = NL + NR + 1,
105 *> and column dimension M = N + SQRE.
111 *> The number of columns of B and BX. NRHS must be at least 1.
116 *> B is REAL array, dimension ( LDB, NRHS )
117 *> On input, B contains the right hand sides of the least
118 *> squares problem in rows 1 through M. On output, B contains
119 *> the solution X in rows 1 through N.
125 *> The leading dimension of B. LDB must be at least
126 *> max(1,MAX( M, N ) ).
131 *> BX is REAL array, dimension ( LDBX, NRHS )
137 *> The leading dimension of BX.
142 *> PERM is INTEGER array, dimension ( N )
143 *> The permutations (from deflation and sorting) applied
144 *> to the two blocks.
150 *> The number of Givens rotations which took place in this
156 *> GIVCOL is INTEGER array, dimension ( LDGCOL, 2 )
157 *> Each pair of numbers indicates a pair of rows/columns
158 *> involved in a Givens rotation.
164 *> The leading dimension of GIVCOL, must be at least N.
169 *> GIVNUM is REAL array, dimension ( LDGNUM, 2 )
170 *> Each number indicates the C or S value used in the
171 *> corresponding Givens rotation.
177 *> The leading dimension of arrays DIFR, POLES and
178 *> GIVNUM, must be at least K.
183 *> POLES is REAL array, dimension ( LDGNUM, 2 )
184 *> On entry, POLES(1:K, 1) contains the new singular
185 *> values obtained from solving the secular equation, and
186 *> POLES(1:K, 2) is an array containing the poles in the secular
192 *> DIFL is REAL array, dimension ( K ).
193 *> On entry, DIFL(I) is the distance between I-th updated
194 *> (undeflated) singular value and the I-th (undeflated) old
200 *> DIFR is REAL array, dimension ( LDGNUM, 2 ).
201 *> On entry, DIFR(I, 1) contains the distances between I-th
202 *> updated (undeflated) singular value and the I+1-th
203 *> (undeflated) old singular value. And DIFR(I, 2) is the
204 *> normalizing factor for the I-th right singular vector.
209 *> Z is REAL array, dimension ( K )
210 *> Contain the components of the deflation-adjusted updating row
217 *> Contains the dimension of the non-deflated matrix,
218 *> This is the order of the related secular equation. 1 <= K <=N.
224 *> C contains garbage if SQRE =0 and the C-value of a Givens
225 *> rotation related to the right null space if SQRE = 1.
231 *> S contains garbage if SQRE =0 and the S-value of a Givens
232 *> rotation related to the right null space if SQRE = 1.
237 *> WORK is REAL array, dimension ( K )
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 November 2015
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 SLALS0( ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX,
268 $ PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
269 $ POLES, DIFL, DIFR, Z, K, C, S, WORK, INFO )
271 * -- LAPACK computational routine (version 3.6.0) --
272 * -- LAPACK is a software package provided by Univ. of Tennessee, --
273 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
276 * .. Scalar Arguments ..
277 INTEGER GIVPTR, ICOMPQ, INFO, K, LDB, LDBX, LDGCOL,
278 $ LDGNUM, NL, NR, NRHS, SQRE
281 * .. Array Arguments ..
282 INTEGER GIVCOL( LDGCOL, * ), PERM( * )
283 REAL B( LDB, * ), BX( LDBX, * ), DIFL( * ),
284 $ DIFR( LDGNUM, * ), GIVNUM( LDGNUM, * ),
285 $ POLES( LDGNUM, * ), WORK( * ), Z( * )
288 * =====================================================================
291 REAL ONE, ZERO, NEGONE
292 PARAMETER ( ONE = 1.0E0, ZERO = 0.0E0, NEGONE = -1.0E0 )
294 * .. Local Scalars ..
295 INTEGER I, J, M, N, NLP1
296 REAL DIFLJ, DIFRJ, DJ, DSIGJ, DSIGJP, TEMP
298 * .. External Subroutines ..
299 EXTERNAL SCOPY, SGEMV, SLACPY, SLASCL, SROT, SSCAL,
302 * .. External Functions ..
304 EXTERNAL SLAMC3, SNRM2
306 * .. Intrinsic Functions ..
309 * .. Executable Statements ..
311 * Test the input parameters.
316 IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
318 ELSE IF( NL.LT.1 ) THEN
320 ELSE IF( NR.LT.1 ) THEN
322 ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
324 ELSE IF( NRHS.LT.1 ) THEN
326 ELSE IF( LDB.LT.N ) THEN
328 ELSE IF( LDBX.LT.N ) THEN
330 ELSE IF( GIVPTR.LT.0 ) THEN
332 ELSE IF( LDGCOL.LT.N ) THEN
334 ELSE IF( LDGNUM.LT.N ) THEN
336 ELSE IF( K.LT.1 ) THEN
340 CALL XERBLA( 'SLALS0', -INFO )
347 IF( ICOMPQ.EQ.0 ) THEN
349 * Apply back orthogonal transformations from the left.
351 * Step (1L): apply back the Givens rotations performed.
354 CALL SROT( NRHS, B( GIVCOL( I, 2 ), 1 ), LDB,
355 $ B( GIVCOL( I, 1 ), 1 ), LDB, GIVNUM( I, 2 ),
359 * Step (2L): permute rows of B.
361 CALL SCOPY( NRHS, B( NLP1, 1 ), LDB, BX( 1, 1 ), LDBX )
363 CALL SCOPY( NRHS, B( PERM( I ), 1 ), LDB, BX( I, 1 ), LDBX )
366 * Step (3L): apply the inverse of the left singular vector
370 CALL SCOPY( NRHS, BX, LDBX, B, LDB )
371 IF( Z( 1 ).LT.ZERO ) THEN
372 CALL SSCAL( NRHS, NEGONE, B, LDB )
378 DSIGJ = -POLES( J, 2 )
380 DIFRJ = -DIFR( J, 1 )
381 DSIGJP = -POLES( J+1, 2 )
383 IF( ( Z( J ).EQ.ZERO ) .OR. ( POLES( J, 2 ).EQ.ZERO ) )
387 WORK( J ) = -POLES( J, 2 )*Z( J ) / DIFLJ /
388 $ ( POLES( J, 2 )+DJ )
391 IF( ( Z( I ).EQ.ZERO ) .OR.
392 $ ( POLES( I, 2 ).EQ.ZERO ) ) THEN
395 WORK( I ) = POLES( I, 2 )*Z( I ) /
396 $ ( SLAMC3( POLES( I, 2 ), DSIGJ )-
397 $ DIFLJ ) / ( POLES( I, 2 )+DJ )
401 IF( ( Z( I ).EQ.ZERO ) .OR.
402 $ ( POLES( I, 2 ).EQ.ZERO ) ) THEN
405 WORK( I ) = POLES( I, 2 )*Z( I ) /
406 $ ( SLAMC3( POLES( I, 2 ), DSIGJP )+
407 $ DIFRJ ) / ( POLES( I, 2 )+DJ )
411 TEMP = SNRM2( K, WORK, 1 )
412 CALL SGEMV( 'T', K, NRHS, ONE, BX, LDBX, WORK, 1, ZERO,
414 CALL SLASCL( 'G', 0, 0, TEMP, ONE, 1, NRHS, B( J, 1 ),
419 * Move the deflated rows of BX to B also.
421 IF( K.LT.MAX( M, N ) )
422 $ CALL SLACPY( 'A', N-K, NRHS, BX( K+1, 1 ), LDBX,
426 * Apply back the right orthogonal transformations.
428 * Step (1R): apply back the new right singular vector matrix
432 CALL SCOPY( NRHS, B, LDB, BX, LDBX )
435 DSIGJ = POLES( J, 2 )
436 IF( Z( J ).EQ.ZERO ) THEN
439 WORK( J ) = -Z( J ) / DIFL( J ) /
440 $ ( DSIGJ+POLES( J, 1 ) ) / DIFR( J, 2 )
443 IF( Z( J ).EQ.ZERO ) THEN
446 WORK( I ) = Z( J ) / ( SLAMC3( DSIGJ, -POLES( I+1,
447 $ 2 ) )-DIFR( I, 1 ) ) /
448 $ ( DSIGJ+POLES( I, 1 ) ) / DIFR( I, 2 )
452 IF( Z( J ).EQ.ZERO ) THEN
455 WORK( I ) = Z( J ) / ( SLAMC3( DSIGJ, -POLES( I,
456 $ 2 ) )-DIFL( I ) ) /
457 $ ( DSIGJ+POLES( I, 1 ) ) / DIFR( I, 2 )
460 CALL SGEMV( 'T', K, NRHS, ONE, B, LDB, WORK, 1, ZERO,
465 * Step (2R): if SQRE = 1, apply back the rotation that is
466 * related to the right null space of the subproblem.
469 CALL SCOPY( NRHS, B( M, 1 ), LDB, BX( M, 1 ), LDBX )
470 CALL SROT( NRHS, BX( 1, 1 ), LDBX, BX( M, 1 ), LDBX, C, S )
472 IF( K.LT.MAX( M, N ) )
473 $ CALL SLACPY( 'A', N-K, NRHS, B( K+1, 1 ), LDB, BX( K+1, 1 ),
476 * Step (3R): permute rows of B.
478 CALL SCOPY( NRHS, BX( 1, 1 ), LDBX, B( NLP1, 1 ), LDB )
480 CALL SCOPY( NRHS, BX( M, 1 ), LDBX, B( M, 1 ), LDB )
483 CALL SCOPY( NRHS, BX( I, 1 ), LDBX, B( PERM( I ), 1 ), LDB )
486 * Step (4R): apply back the Givens rotations performed.
488 DO 100 I = GIVPTR, 1, -1
489 CALL SROT( NRHS, B( GIVCOL( I, 2 ), 1 ), LDB,
490 $ B( GIVCOL( I, 1 ), 1 ), LDB, GIVNUM( I, 2 ),