LAPACK  3.9.0
LAPACK: Linear Algebra PACKage
slalsa.f
Go to the documentation of this file.
1 *> \brief \b SLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd.
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SLALSA + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slalsa.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slalsa.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slalsa.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
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,
24 * IWORK, INFO )
25 *
26 * .. Scalar Arguments ..
27 * INTEGER ICOMPQ, INFO, LDB, LDBX, LDGCOL, LDU, N, NRHS,
28 * $ SMLSIZ
29 * ..
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( * ),
37 * $ Z( LDU, * )
38 * ..
39 *
40 *
41 *> \par Purpose:
42 * =============
43 *>
44 *> \verbatim
45 *>
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
49 *> matrices.).
50 *>
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.
56 *> \endverbatim
57 *
58 * Arguments:
59 * ==========
60 *
61 *> \param[in] ICOMPQ
62 *> \verbatim
63 *> ICOMPQ is INTEGER
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
68 *> \endverbatim
69 *>
70 *> \param[in] SMLSIZ
71 *> \verbatim
72 *> SMLSIZ is INTEGER
73 *> The maximum size of the subproblems at the bottom of the
74 *> computation tree.
75 *> \endverbatim
76 *>
77 *> \param[in] N
78 *> \verbatim
79 *> N is INTEGER
80 *> The row and column dimensions of the upper bidiagonal matrix.
81 *> \endverbatim
82 *>
83 *> \param[in] NRHS
84 *> \verbatim
85 *> NRHS is INTEGER
86 *> The number of columns of B and BX. NRHS must be at least 1.
87 *> \endverbatim
88 *>
89 *> \param[in,out] B
90 *> \verbatim
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.
95 *> \endverbatim
96 *>
97 *> \param[in] LDB
98 *> \verbatim
99 *> LDB is INTEGER
100 *> The leading dimension of B in the calling subprogram.
101 *> LDB must be at least max(1,MAX( M, N ) ).
102 *> \endverbatim
103 *>
104 *> \param[out] BX
105 *> \verbatim
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.
109 *> \endverbatim
110 *>
111 *> \param[in] LDBX
112 *> \verbatim
113 *> LDBX is INTEGER
114 *> The leading dimension of BX.
115 *> \endverbatim
116 *>
117 *> \param[in] U
118 *> \verbatim
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.
122 *> \endverbatim
123 *>
124 *> \param[in] LDU
125 *> \verbatim
126 *> LDU is INTEGER, LDU = > N.
127 *> The leading dimension of arrays U, VT, DIFL, DIFR,
128 *> POLES, GIVNUM, and Z.
129 *> \endverbatim
130 *>
131 *> \param[in] VT
132 *> \verbatim
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.
136 *> \endverbatim
137 *>
138 *> \param[in] K
139 *> \verbatim
140 *> K is INTEGER array, dimension ( N ).
141 *> \endverbatim
142 *>
143 *> \param[in] DIFL
144 *> \verbatim
145 *> DIFL is REAL array, dimension ( LDU, NLVL ).
146 *> where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1.
147 *> \endverbatim
148 *>
149 *> \param[in] DIFR
150 *> \verbatim
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.
157 *> \endverbatim
158 *>
159 *> \param[in] Z
160 *> \verbatim
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
164 *> level.
165 *> \endverbatim
166 *>
167 *> \param[in] POLES
168 *> \verbatim
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
172 *> level.
173 *> \endverbatim
174 *>
175 *> \param[in] GIVPTR
176 *> \verbatim
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
180 *> tree.
181 *> \endverbatim
182 *>
183 *> \param[in] GIVCOL
184 *> \verbatim
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.
189 *> \endverbatim
190 *>
191 *> \param[in] LDGCOL
192 *> \verbatim
193 *> LDGCOL is INTEGER, LDGCOL = > N.
194 *> The leading dimension of arrays GIVCOL and PERM.
195 *> \endverbatim
196 *>
197 *> \param[in] PERM
198 *> \verbatim
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.
202 *> \endverbatim
203 *>
204 *> \param[in] GIVNUM
205 *> \verbatim
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
209 *> computation tree.
210 *> \endverbatim
211 *>
212 *> \param[in] C
213 *> \verbatim
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.
218 *> \endverbatim
219 *>
220 *> \param[in] S
221 *> \verbatim
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.
226 *> \endverbatim
227 *>
228 *> \param[out] WORK
229 *> \verbatim
230 *> WORK is REAL array, dimension (N)
231 *> \endverbatim
232 *>
233 *> \param[out] IWORK
234 *> \verbatim
235 *> IWORK is INTEGER array, dimension (3*N)
236 *> \endverbatim
237 *>
238 *> \param[out] INFO
239 *> \verbatim
240 *> INFO is INTEGER
241 *> = 0: successful exit.
242 *> < 0: if INFO = -i, the i-th argument had an illegal value.
243 *> \endverbatim
244 *
245 * Authors:
246 * ========
247 *
248 *> \author Univ. of Tennessee
249 *> \author Univ. of California Berkeley
250 *> \author Univ. of Colorado Denver
251 *> \author NAG Ltd.
252 *
253 *> \date June 2017
254 *
255 *> \ingroup realOTHERcomputational
256 *
257 *> \par Contributors:
258 * ==================
259 *>
260 *> Ming Gu and Ren-Cang Li, Computer Science Division, University of
261 *> California at Berkeley, USA \n
262 *> Osni Marques, LBNL/NERSC, USA \n
263 *
264 * =====================================================================
265  SUBROUTINE slalsa( ICOMPQ, SMLSIZ, N, NRHS, B, LDB, BX, LDBX, U,
266  $ LDU, VT, K, DIFL, DIFR, Z, POLES, GIVPTR,
267  $ GIVCOL, LDGCOL, PERM, GIVNUM, C, S, WORK,
268  $ IWORK, INFO )
269 *
270 * -- LAPACK computational routine (version 3.7.1) --
271 * -- LAPACK is a software package provided by Univ. of Tennessee, --
272 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
273 * June 2017
274 *
275 * .. Scalar Arguments ..
276  INTEGER ICOMPQ, INFO, LDB, LDBX, LDGCOL, LDU, N, NRHS,
277  $ SMLSIZ
278 * ..
279 * .. Array Arguments ..
280  INTEGER GIVCOL( LDGCOL, * ), GIVPTR( * ), IWORK( * ),
281  $ K( * ), PERM( LDGCOL, * )
282  REAL B( LDB, * ), BX( LDBX, * ), C( * ),
283  $ difl( ldu, * ), difr( ldu, * ),
284  $ givnum( ldu, * ), poles( ldu, * ), s( * ),
285  $ u( ldu, * ), vt( ldu, * ), work( * ),
286  $ z( ldu, * )
287 * ..
288 *
289 * =====================================================================
290 *
291 * .. Parameters ..
292  REAL ZERO, ONE
293  PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
294 * ..
295 * .. Local Scalars ..
296  INTEGER I, I1, IC, IM1, INODE, J, LF, LL, LVL, LVL2,
297  $ ND, NDB1, NDIML, NDIMR, NL, NLF, NLP1, NLVL,
298  $ NR, NRF, NRP1, SQRE
299 * ..
300 * .. External Subroutines ..
301  EXTERNAL scopy, sgemm, slals0, slasdt, xerbla
302 * ..
303 * .. Executable Statements ..
304 *
305 * Test the input parameters.
306 *
307  info = 0
308 *
309  IF( ( icompq.LT.0 ) .OR. ( icompq.GT.1 ) ) THEN
310  info = -1
311  ELSE IF( smlsiz.LT.3 ) THEN
312  info = -2
313  ELSE IF( n.LT.smlsiz ) THEN
314  info = -3
315  ELSE IF( nrhs.LT.1 ) THEN
316  info = -4
317  ELSE IF( ldb.LT.n ) THEN
318  info = -6
319  ELSE IF( ldbx.LT.n ) THEN
320  info = -8
321  ELSE IF( ldu.LT.n ) THEN
322  info = -10
323  ELSE IF( ldgcol.LT.n ) THEN
324  info = -19
325  END IF
326  IF( info.NE.0 ) THEN
327  CALL xerbla( 'SLALSA', -info )
328  RETURN
329  END IF
330 *
331 * Book-keeping and setting up the computation tree.
332 *
333  inode = 1
334  ndiml = inode + n
335  ndimr = ndiml + n
336 *
337  CALL slasdt( n, nlvl, nd, iwork( inode ), iwork( ndiml ),
338  $ iwork( ndimr ), smlsiz )
339 *
340 * The following code applies back the left singular vector factors.
341 * For applying back the right singular vector factors, go to 50.
342 *
343  IF( icompq.EQ.1 ) THEN
344  GO TO 50
345  END IF
346 *
347 * The nodes on the bottom level of the tree were solved
348 * by SLASDQ. The corresponding left and right singular vector
349 * matrices are in explicit form. First apply back the left
350 * singular vector matrices.
351 *
352  ndb1 = ( nd+1 ) / 2
353  DO 10 i = ndb1, nd
354 *
355 * IC : center row of each node
356 * NL : number of rows of left subproblem
357 * NR : number of rows of right subproblem
358 * NLF: starting row of the left subproblem
359 * NRF: starting row of the right subproblem
360 *
361  i1 = i - 1
362  ic = iwork( inode+i1 )
363  nl = iwork( ndiml+i1 )
364  nr = iwork( ndimr+i1 )
365  nlf = ic - nl
366  nrf = ic + 1
367  CALL sgemm( 'T', 'N', nl, nrhs, nl, one, u( nlf, 1 ), ldu,
368  $ b( nlf, 1 ), ldb, zero, bx( nlf, 1 ), ldbx )
369  CALL sgemm( 'T', 'N', nr, nrhs, nr, one, u( nrf, 1 ), ldu,
370  $ b( nrf, 1 ), ldb, zero, bx( nrf, 1 ), ldbx )
371  10 CONTINUE
372 *
373 * Next copy the rows of B that correspond to unchanged rows
374 * in the bidiagonal matrix to BX.
375 *
376  DO 20 i = 1, nd
377  ic = iwork( inode+i-1 )
378  CALL scopy( nrhs, b( ic, 1 ), ldb, bx( ic, 1 ), ldbx )
379  20 CONTINUE
380 *
381 * Finally go through the left singular vector matrices of all
382 * the other subproblems bottom-up on the tree.
383 *
384  j = 2**nlvl
385  sqre = 0
386 *
387  DO 40 lvl = nlvl, 1, -1
388  lvl2 = 2*lvl - 1
389 *
390 * find the first node LF and last node LL on
391 * the current level LVL
392 *
393  IF( lvl.EQ.1 ) THEN
394  lf = 1
395  ll = 1
396  ELSE
397  lf = 2**( lvl-1 )
398  ll = 2*lf - 1
399  END IF
400  DO 30 i = lf, ll
401  im1 = i - 1
402  ic = iwork( inode+im1 )
403  nl = iwork( ndiml+im1 )
404  nr = iwork( ndimr+im1 )
405  nlf = ic - nl
406  nrf = ic + 1
407  j = j - 1
408  CALL slals0( icompq, nl, nr, sqre, nrhs, bx( nlf, 1 ), ldbx,
409  $ b( nlf, 1 ), ldb, perm( nlf, lvl ),
410  $ givptr( j ), givcol( nlf, lvl2 ), ldgcol,
411  $ givnum( nlf, lvl2 ), ldu, poles( nlf, lvl2 ),
412  $ difl( nlf, lvl ), difr( nlf, lvl2 ),
413  $ z( nlf, lvl ), k( j ), c( j ), s( j ), work,
414  $ info )
415  30 CONTINUE
416  40 CONTINUE
417  GO TO 90
418 *
419 * ICOMPQ = 1: applying back the right singular vector factors.
420 *
421  50 CONTINUE
422 *
423 * First now go through the right singular vector matrices of all
424 * the tree nodes top-down.
425 *
426  j = 0
427  DO 70 lvl = 1, nlvl
428  lvl2 = 2*lvl - 1
429 *
430 * Find the first node LF and last node LL on
431 * the current level LVL.
432 *
433  IF( lvl.EQ.1 ) THEN
434  lf = 1
435  ll = 1
436  ELSE
437  lf = 2**( lvl-1 )
438  ll = 2*lf - 1
439  END IF
440  DO 60 i = ll, lf, -1
441  im1 = i - 1
442  ic = iwork( inode+im1 )
443  nl = iwork( ndiml+im1 )
444  nr = iwork( ndimr+im1 )
445  nlf = ic - nl
446  nrf = ic + 1
447  IF( i.EQ.ll ) THEN
448  sqre = 0
449  ELSE
450  sqre = 1
451  END IF
452  j = j + 1
453  CALL slals0( icompq, nl, nr, sqre, nrhs, b( nlf, 1 ), ldb,
454  $ bx( nlf, 1 ), ldbx, perm( nlf, lvl ),
455  $ givptr( j ), givcol( nlf, lvl2 ), ldgcol,
456  $ givnum( nlf, lvl2 ), ldu, poles( nlf, lvl2 ),
457  $ difl( nlf, lvl ), difr( nlf, lvl2 ),
458  $ z( nlf, lvl ), k( j ), c( j ), s( j ), work,
459  $ info )
460  60 CONTINUE
461  70 CONTINUE
462 *
463 * The nodes on the bottom level of the tree were solved
464 * by SLASDQ. The corresponding right singular vector
465 * matrices are in explicit form. Apply them back.
466 *
467  ndb1 = ( nd+1 ) / 2
468  DO 80 i = ndb1, nd
469  i1 = i - 1
470  ic = iwork( inode+i1 )
471  nl = iwork( ndiml+i1 )
472  nr = iwork( ndimr+i1 )
473  nlp1 = nl + 1
474  IF( i.EQ.nd ) THEN
475  nrp1 = nr
476  ELSE
477  nrp1 = nr + 1
478  END IF
479  nlf = ic - nl
480  nrf = ic + 1
481  CALL sgemm( 'T', 'N', nlp1, nrhs, nlp1, one, vt( nlf, 1 ), ldu,
482  $ b( nlf, 1 ), ldb, zero, bx( nlf, 1 ), ldbx )
483  CALL sgemm( 'T', 'N', nrp1, nrhs, nrp1, one, vt( nrf, 1 ), ldu,
484  $ b( nrf, 1 ), ldb, zero, bx( nrf, 1 ), ldbx )
485  80 CONTINUE
486 *
487  90 CONTINUE
488 *
489  RETURN
490 *
491 * End of SLALSA
492 *
493  END
sgemm
subroutine sgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
SGEMM
Definition: sgemm.f:189
scopy
subroutine scopy(N, SX, INCX, SY, INCY)
SCOPY
Definition: scopy.f:84
xerbla
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
slals0
subroutine slals0(ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX, PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, POLES, DIFL, DIFR, Z, K, C, S, WORK, INFO)
SLALS0 applies back multiplying factors in solving the least squares problem using divide and conquer...
Definition: slals0.f:270
slalsa
subroutine slalsa(ICOMPQ, SMLSIZ, N, NRHS, B, LDB, BX, LDBX, U, LDU, VT, K, DIFL, DIFR, Z, POLES, GIVPTR, GIVCOL, LDGCOL, PERM, GIVNUM, C, S, WORK, IWORK, INFO)
SLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd.
Definition: slalsa.f:269
slasdt
subroutine slasdt(N, LVL, ND, INODE, NDIML, NDIMR, MSUB)
SLASDT creates a tree of subproblems for bidiagonal divide and conquer. Used by sbdsdc.
Definition: slasdt.f:107