 LAPACK  3.6.1 LAPACK: Linear Algebra PACKage
 subroutine clalsa ( integer ICOMPQ, integer SMLSIZ, integer N, integer NRHS, complex, dimension( ldb, * ) B, integer LDB, complex, dimension( ldbx, * ) BX, integer LDBX, real, dimension( ldu, * ) U, integer LDU, real, dimension( ldu, * ) VT, integer, dimension( * ) K, real, dimension( ldu, * ) DIFL, real, dimension( ldu, * ) DIFR, real, dimension( ldu, * ) Z, real, dimension( ldu, * ) POLES, integer, dimension( * ) GIVPTR, integer, dimension( ldgcol, * ) GIVCOL, integer LDGCOL, integer, dimension( ldgcol, * ) PERM, real, dimension( ldu, * ) GIVNUM, real, dimension( * ) C, real, dimension( * ) S, real, dimension( * ) RWORK, integer, dimension( * ) IWORK, integer INFO )

CLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd.

Purpose:
``` CLALSA is an itermediate step in solving the least squares problem
by computing the SVD of the coefficient matrix in compact form (The
singular vectors are computed as products of simple orthorgonal
matrices.).

If ICOMPQ = 0, CLALSA applies the inverse of the left singular vector
matrix of an upper bidiagonal matrix to the right hand side; and if
ICOMPQ = 1, CLALSA applies the right singular vector matrix to the
right hand side. The singular vector matrices were generated in
compact form by CLALSA.```
Parameters
 [in] ICOMPQ ``` ICOMPQ is INTEGER Specifies whether the left or the right singular vector matrix is involved. = 0: Left singular vector matrix = 1: Right singular vector matrix``` [in] SMLSIZ ``` SMLSIZ is INTEGER The maximum size of the subproblems at the bottom of the computation tree.``` [in] N ``` N is INTEGER The row and column dimensions of the upper bidiagonal matrix.``` [in] NRHS ``` NRHS is INTEGER The number of columns of B and BX. NRHS must be at least 1.``` [in,out] B ``` B is COMPLEX array, dimension ( LDB, NRHS ) On input, B contains the right hand sides of the least squares problem in rows 1 through M. On output, B contains the solution X in rows 1 through N.``` [in] LDB ``` LDB is INTEGER The leading dimension of B in the calling subprogram. LDB must be at least max(1,MAX( M, N ) ).``` [out] BX ``` BX is COMPLEX array, dimension ( LDBX, NRHS ) On exit, the result of applying the left or right singular vector matrix to B.``` [in] LDBX ``` LDBX is INTEGER The leading dimension of BX.``` [in] U ``` U is REAL array, dimension ( LDU, SMLSIZ ). On entry, U contains the left singular vector matrices of all subproblems at the bottom level.``` [in] LDU ``` LDU is INTEGER, LDU = > N. The leading dimension of arrays U, VT, DIFL, DIFR, POLES, GIVNUM, and Z.``` [in] VT ``` VT is REAL array, dimension ( LDU, SMLSIZ+1 ). On entry, VT**H contains the right singular vector matrices of all subproblems at the bottom level.``` [in] K ` K is INTEGER array, dimension ( N ).` [in] DIFL ``` DIFL is REAL array, dimension ( LDU, NLVL ). where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1.``` [in] DIFR ``` DIFR is REAL array, dimension ( LDU, 2 * NLVL ). On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record distances between singular values on the I-th level and singular values on the (I -1)-th level, and DIFR(*, 2 * I) record the normalizing factors of the right singular vectors matrices of subproblems on I-th level.``` [in] Z ``` Z is REAL array, dimension ( LDU, NLVL ). On entry, Z(1, I) contains the components of the deflation- adjusted updating row vector for subproblems on the I-th level.``` [in] POLES ``` POLES is REAL array, dimension ( LDU, 2 * NLVL ). On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old singular values involved in the secular equations on the I-th level.``` [in] GIVPTR ``` GIVPTR is INTEGER array, dimension ( N ). On entry, GIVPTR( I ) records the number of Givens rotations performed on the I-th problem on the computation tree.``` [in] GIVCOL ``` GIVCOL is INTEGER array, dimension ( LDGCOL, 2 * NLVL ). On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the locations of Givens rotations performed on the I-th level on the computation tree.``` [in] LDGCOL ``` LDGCOL is INTEGER, LDGCOL = > N. The leading dimension of arrays GIVCOL and PERM.``` [in] PERM ``` PERM is INTEGER array, dimension ( LDGCOL, NLVL ). On entry, PERM(*, I) records permutations done on the I-th level of the computation tree.``` [in] GIVNUM ``` GIVNUM is REAL array, dimension ( LDU, 2 * NLVL ). On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S- values of Givens rotations performed on the I-th level on the computation tree.``` [in] C ``` C is REAL array, dimension ( N ). On entry, if the I-th subproblem is not square, C( I ) contains the C-value of a Givens rotation related to the right null space of the I-th subproblem.``` [in] S ``` S is REAL array, dimension ( N ). On entry, if the I-th subproblem is not square, S( I ) contains the S-value of a Givens rotation related to the right null space of the I-th subproblem.``` [out] RWORK ``` RWORK is REAL array, dimension at least MAX( (SMLSZ+1)*NRHS*3, N*(1+NRHS) + 2*NRHS ).``` [out] IWORK ``` IWORK is INTEGER array. The dimension must be at least 3 * N``` [out] INFO ``` INFO is INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value.```
Date
September 2012
Contributors:
Ming Gu and Ren-Cang Li, Computer Science Division, University of California at Berkeley, USA
Osni Marques, LBNL/NERSC, USA

Definition at line 270 of file clalsa.f.

270 *
271 * -- LAPACK computational routine (version 3.4.2) --
272 * -- LAPACK is a software package provided by Univ. of Tennessee, --
273 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
274 * September 2012
275 *
276 * .. Scalar Arguments ..
277  INTEGER icompq, info, ldb, ldbx, ldgcol, ldu, n, nrhs,
278  \$ smlsiz
279 * ..
280 * .. Array Arguments ..
281  INTEGER givcol( ldgcol, * ), givptr( * ), iwork( * ),
282  \$ k( * ), perm( ldgcol, * )
283  REAL c( * ), difl( ldu, * ), difr( ldu, * ),
284  \$ givnum( ldu, * ), poles( ldu, * ), rwork( * ),
285  \$ s( * ), u( ldu, * ), vt( ldu, * ), z( ldu, * )
286  COMPLEX b( ldb, * ), bx( ldbx, * )
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, jcol, jimag, jreal,
297  \$ jrow, lf, ll, lvl, lvl2, nd, ndb1, ndiml,
298  \$ ndimr, nl, nlf, nlp1, nlvl, nr, nrf, nrp1, sqre
299 * ..
300 * .. External Subroutines ..
301  EXTERNAL ccopy, clals0, sgemm, slasdt, xerbla
302 * ..
303 * .. Intrinsic Functions ..
304  INTRINSIC aimag, cmplx, real
305 * ..
306 * .. Executable Statements ..
307 *
308 * Test the input parameters.
309 *
310  info = 0
311 *
312  IF( ( icompq.LT.0 ) .OR. ( icompq.GT.1 ) ) THEN
313  info = -1
314  ELSE IF( smlsiz.LT.3 ) THEN
315  info = -2
316  ELSE IF( n.LT.smlsiz ) THEN
317  info = -3
318  ELSE IF( nrhs.LT.1 ) THEN
319  info = -4
320  ELSE IF( ldb.LT.n ) THEN
321  info = -6
322  ELSE IF( ldbx.LT.n ) THEN
323  info = -8
324  ELSE IF( ldu.LT.n ) THEN
325  info = -10
326  ELSE IF( ldgcol.LT.n ) THEN
327  info = -19
328  END IF
329  IF( info.NE.0 ) THEN
330  CALL xerbla( 'CLALSA', -info )
331  RETURN
332  END IF
333 *
334 * Book-keeping and setting up the computation tree.
335 *
336  inode = 1
337  ndiml = inode + n
338  ndimr = ndiml + n
339 *
340  CALL slasdt( n, nlvl, nd, iwork( inode ), iwork( ndiml ),
341  \$ iwork( ndimr ), smlsiz )
342 *
343 * The following code applies back the left singular vector factors.
344 * For applying back the right singular vector factors, go to 170.
345 *
346  IF( icompq.EQ.1 ) THEN
347  GO TO 170
348  END IF
349 *
350 * The nodes on the bottom level of the tree were solved
351 * by SLASDQ. The corresponding left and right singular vector
352 * matrices are in explicit form. First apply back the left
353 * singular vector matrices.
354 *
355  ndb1 = ( nd+1 ) / 2
356  DO 130 i = ndb1, nd
357 *
358 * IC : center row of each node
359 * NL : number of rows of left subproblem
360 * NR : number of rows of right subproblem
361 * NLF: starting row of the left subproblem
362 * NRF: starting row of the right subproblem
363 *
364  i1 = i - 1
365  ic = iwork( inode+i1 )
366  nl = iwork( ndiml+i1 )
367  nr = iwork( ndimr+i1 )
368  nlf = ic - nl
369  nrf = ic + 1
370 *
371 * Since B and BX are complex, the following call to SGEMM
372 * is performed in two steps (real and imaginary parts).
373 *
374 * CALL SGEMM( 'T', 'N', NL, NRHS, NL, ONE, U( NLF, 1 ), LDU,
375 * \$ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
376 *
377  j = nl*nrhs*2
378  DO 20 jcol = 1, nrhs
379  DO 10 jrow = nlf, nlf + nl - 1
380  j = j + 1
381  rwork( j ) = REAL( B( JROW, JCOL ) )
382  10 CONTINUE
383  20 CONTINUE
384  CALL sgemm( 'T', 'N', nl, nrhs, nl, one, u( nlf, 1 ), ldu,
385  \$ rwork( 1+nl*nrhs*2 ), nl, zero, rwork( 1 ), nl )
386  j = nl*nrhs*2
387  DO 40 jcol = 1, nrhs
388  DO 30 jrow = nlf, nlf + nl - 1
389  j = j + 1
390  rwork( j ) = aimag( b( jrow, jcol ) )
391  30 CONTINUE
392  40 CONTINUE
393  CALL sgemm( 'T', 'N', nl, nrhs, nl, one, u( nlf, 1 ), ldu,
394  \$ rwork( 1+nl*nrhs*2 ), nl, zero, rwork( 1+nl*nrhs ),
395  \$ nl )
396  jreal = 0
397  jimag = nl*nrhs
398  DO 60 jcol = 1, nrhs
399  DO 50 jrow = nlf, nlf + nl - 1
400  jreal = jreal + 1
401  jimag = jimag + 1
402  bx( jrow, jcol ) = cmplx( rwork( jreal ),
403  \$ rwork( jimag ) )
404  50 CONTINUE
405  60 CONTINUE
406 *
407 * Since B and BX are complex, the following call to SGEMM
408 * is performed in two steps (real and imaginary parts).
409 *
410 * CALL SGEMM( 'T', 'N', NR, NRHS, NR, ONE, U( NRF, 1 ), LDU,
411 * \$ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )
412 *
413  j = nr*nrhs*2
414  DO 80 jcol = 1, nrhs
415  DO 70 jrow = nrf, nrf + nr - 1
416  j = j + 1
417  rwork( j ) = REAL( B( JROW, JCOL ) )
418  70 CONTINUE
419  80 CONTINUE
420  CALL sgemm( 'T', 'N', nr, nrhs, nr, one, u( nrf, 1 ), ldu,
421  \$ rwork( 1+nr*nrhs*2 ), nr, zero, rwork( 1 ), nr )
422  j = nr*nrhs*2
423  DO 100 jcol = 1, nrhs
424  DO 90 jrow = nrf, nrf + nr - 1
425  j = j + 1
426  rwork( j ) = aimag( b( jrow, jcol ) )
427  90 CONTINUE
428  100 CONTINUE
429  CALL sgemm( 'T', 'N', nr, nrhs, nr, one, u( nrf, 1 ), ldu,
430  \$ rwork( 1+nr*nrhs*2 ), nr, zero, rwork( 1+nr*nrhs ),
431  \$ nr )
432  jreal = 0
433  jimag = nr*nrhs
434  DO 120 jcol = 1, nrhs
435  DO 110 jrow = nrf, nrf + nr - 1
436  jreal = jreal + 1
437  jimag = jimag + 1
438  bx( jrow, jcol ) = cmplx( rwork( jreal ),
439  \$ rwork( jimag ) )
440  110 CONTINUE
441  120 CONTINUE
442 *
443  130 CONTINUE
444 *
445 * Next copy the rows of B that correspond to unchanged rows
446 * in the bidiagonal matrix to BX.
447 *
448  DO 140 i = 1, nd
449  ic = iwork( inode+i-1 )
450  CALL ccopy( nrhs, b( ic, 1 ), ldb, bx( ic, 1 ), ldbx )
451  140 CONTINUE
452 *
453 * Finally go through the left singular vector matrices of all
454 * the other subproblems bottom-up on the tree.
455 *
456  j = 2**nlvl
457  sqre = 0
458 *
459  DO 160 lvl = nlvl, 1, -1
460  lvl2 = 2*lvl - 1
461 *
462 * find the first node LF and last node LL on
463 * the current level LVL
464 *
465  IF( lvl.EQ.1 ) THEN
466  lf = 1
467  ll = 1
468  ELSE
469  lf = 2**( lvl-1 )
470  ll = 2*lf - 1
471  END IF
472  DO 150 i = lf, ll
473  im1 = i - 1
474  ic = iwork( inode+im1 )
475  nl = iwork( ndiml+im1 )
476  nr = iwork( ndimr+im1 )
477  nlf = ic - nl
478  nrf = ic + 1
479  j = j - 1
480  CALL clals0( icompq, nl, nr, sqre, nrhs, bx( nlf, 1 ), ldbx,
481  \$ b( nlf, 1 ), ldb, perm( nlf, lvl ),
482  \$ givptr( j ), givcol( nlf, lvl2 ), ldgcol,
483  \$ givnum( nlf, lvl2 ), ldu, poles( nlf, lvl2 ),
484  \$ difl( nlf, lvl ), difr( nlf, lvl2 ),
485  \$ z( nlf, lvl ), k( j ), c( j ), s( j ), rwork,
486  \$ info )
487  150 CONTINUE
488  160 CONTINUE
489  GO TO 330
490 *
491 * ICOMPQ = 1: applying back the right singular vector factors.
492 *
493  170 CONTINUE
494 *
495 * First now go through the right singular vector matrices of all
496 * the tree nodes top-down.
497 *
498  j = 0
499  DO 190 lvl = 1, nlvl
500  lvl2 = 2*lvl - 1
501 *
502 * Find the first node LF and last node LL on
503 * the current level LVL.
504 *
505  IF( lvl.EQ.1 ) THEN
506  lf = 1
507  ll = 1
508  ELSE
509  lf = 2**( lvl-1 )
510  ll = 2*lf - 1
511  END IF
512  DO 180 i = ll, lf, -1
513  im1 = i - 1
514  ic = iwork( inode+im1 )
515  nl = iwork( ndiml+im1 )
516  nr = iwork( ndimr+im1 )
517  nlf = ic - nl
518  nrf = ic + 1
519  IF( i.EQ.ll ) THEN
520  sqre = 0
521  ELSE
522  sqre = 1
523  END IF
524  j = j + 1
525  CALL clals0( icompq, nl, nr, sqre, nrhs, b( nlf, 1 ), ldb,
526  \$ bx( nlf, 1 ), ldbx, perm( nlf, lvl ),
527  \$ givptr( j ), givcol( nlf, lvl2 ), ldgcol,
528  \$ givnum( nlf, lvl2 ), ldu, poles( nlf, lvl2 ),
529  \$ difl( nlf, lvl ), difr( nlf, lvl2 ),
530  \$ z( nlf, lvl ), k( j ), c( j ), s( j ), rwork,
531  \$ info )
532  180 CONTINUE
533  190 CONTINUE
534 *
535 * The nodes on the bottom level of the tree were solved
536 * by SLASDQ. The corresponding right singular vector
537 * matrices are in explicit form. Apply them back.
538 *
539  ndb1 = ( nd+1 ) / 2
540  DO 320 i = ndb1, nd
541  i1 = i - 1
542  ic = iwork( inode+i1 )
543  nl = iwork( ndiml+i1 )
544  nr = iwork( ndimr+i1 )
545  nlp1 = nl + 1
546  IF( i.EQ.nd ) THEN
547  nrp1 = nr
548  ELSE
549  nrp1 = nr + 1
550  END IF
551  nlf = ic - nl
552  nrf = ic + 1
553 *
554 * Since B and BX are complex, the following call to SGEMM is
555 * performed in two steps (real and imaginary parts).
556 *
557 * CALL SGEMM( 'T', 'N', NLP1, NRHS, NLP1, ONE, VT( NLF, 1 ), LDU,
558 * \$ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
559 *
560  j = nlp1*nrhs*2
561  DO 210 jcol = 1, nrhs
562  DO 200 jrow = nlf, nlf + nlp1 - 1
563  j = j + 1
564  rwork( j ) = REAL( B( JROW, JCOL ) )
565  200 CONTINUE
566  210 CONTINUE
567  CALL sgemm( 'T', 'N', nlp1, nrhs, nlp1, one, vt( nlf, 1 ), ldu,
568  \$ rwork( 1+nlp1*nrhs*2 ), nlp1, zero, rwork( 1 ),
569  \$ nlp1 )
570  j = nlp1*nrhs*2
571  DO 230 jcol = 1, nrhs
572  DO 220 jrow = nlf, nlf + nlp1 - 1
573  j = j + 1
574  rwork( j ) = aimag( b( jrow, jcol ) )
575  220 CONTINUE
576  230 CONTINUE
577  CALL sgemm( 'T', 'N', nlp1, nrhs, nlp1, one, vt( nlf, 1 ), ldu,
578  \$ rwork( 1+nlp1*nrhs*2 ), nlp1, zero,
579  \$ rwork( 1+nlp1*nrhs ), nlp1 )
580  jreal = 0
581  jimag = nlp1*nrhs
582  DO 250 jcol = 1, nrhs
583  DO 240 jrow = nlf, nlf + nlp1 - 1
584  jreal = jreal + 1
585  jimag = jimag + 1
586  bx( jrow, jcol ) = cmplx( rwork( jreal ),
587  \$ rwork( jimag ) )
588  240 CONTINUE
589  250 CONTINUE
590 *
591 * Since B and BX are complex, the following call to SGEMM is
592 * performed in two steps (real and imaginary parts).
593 *
594 * CALL SGEMM( 'T', 'N', NRP1, NRHS, NRP1, ONE, VT( NRF, 1 ), LDU,
595 * \$ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )
596 *
597  j = nrp1*nrhs*2
598  DO 270 jcol = 1, nrhs
599  DO 260 jrow = nrf, nrf + nrp1 - 1
600  j = j + 1
601  rwork( j ) = REAL( B( JROW, JCOL ) )
602  260 CONTINUE
603  270 CONTINUE
604  CALL sgemm( 'T', 'N', nrp1, nrhs, nrp1, one, vt( nrf, 1 ), ldu,
605  \$ rwork( 1+nrp1*nrhs*2 ), nrp1, zero, rwork( 1 ),
606  \$ nrp1 )
607  j = nrp1*nrhs*2
608  DO 290 jcol = 1, nrhs
609  DO 280 jrow = nrf, nrf + nrp1 - 1
610  j = j + 1
611  rwork( j ) = aimag( b( jrow, jcol ) )
612  280 CONTINUE
613  290 CONTINUE
614  CALL sgemm( 'T', 'N', nrp1, nrhs, nrp1, one, vt( nrf, 1 ), ldu,
615  \$ rwork( 1+nrp1*nrhs*2 ), nrp1, zero,
616  \$ rwork( 1+nrp1*nrhs ), nrp1 )
617  jreal = 0
618  jimag = nrp1*nrhs
619  DO 310 jcol = 1, nrhs
620  DO 300 jrow = nrf, nrf + nrp1 - 1
621  jreal = jreal + 1
622  jimag = jimag + 1
623  bx( jrow, jcol ) = cmplx( rwork( jreal ),
624  \$ rwork( jimag ) )
625  300 CONTINUE
626  310 CONTINUE
627 *
628  320 CONTINUE
629 *
630  330 CONTINUE
631 *
632  RETURN
633 *
634 * End of CLALSA
635 *
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
subroutine sgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
SGEMM
Definition: sgemm.f:189
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine clals0(ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX, PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, POLES, DIFL, DIFR, Z, K, C, S, RWORK, INFO)
CLALS0 applies back multiplying factors in solving the least squares problem using divide and conquer...
Definition: clals0.f:272
subroutine ccopy(N, CX, INCX, CY, INCY)
CCOPY
Definition: ccopy.f:52

Here is the call graph for this function:

Here is the caller graph for this function: