178 SUBROUTINE clalsd( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND,
179 $ RANK, WORK, RWORK, IWORK, INFO )
187 INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ
192 REAL D( * ), E( * ), RWORK( * )
193 COMPLEX B( LDB, * ), WORK( * )
200 parameter( zero = 0.0e0, one = 1.0e0, two = 2.0e0 )
202 parameter( czero = ( 0.0e0, 0.0e0 ) )
205 INTEGER BX, BXST, C, DIFL, DIFR, GIVCOL, GIVNUM,
206 $ givptr, i, icmpq1, icmpq2, irwb, irwib, irwrb,
207 $ irwu, irwvt, irwwrk, iwk, j, jcol, jimag,
208 $ jreal, jrow, k, nlvl, nm1, nrwork, nsize, nsub,
209 $ perm, poles, s, sizei, smlszp, sqre, st, st1,
211 REAL CS, EPS, ORGNRM, R, RCND, SN, TOL
216 EXTERNAL isamax, slamch, slanst
224 INTRINSIC abs, aimag, cmplx, int, log, real, sign
234 ELSE IF( nrhs.LT.1 )
THEN
236 ELSE IF( ( ldb.LT.1 ) .OR. ( ldb.LT.n ) )
THEN
240 CALL xerbla(
'CLALSD', -info )
244 eps = slamch(
'Epsilon' )
248 IF( ( rcond.LE.zero ) .OR. ( rcond.GE.one ) )
THEN
260 ELSE IF( n.EQ.1 )
THEN
261 IF( d( 1 ).EQ.zero )
THEN
262 CALL claset(
'A', 1, nrhs, czero, czero, b, ldb )
265 CALL clascl(
'G', 0, 0, d( 1 ), one, 1, nrhs, b, ldb, info )
266 d( 1 ) = abs( d( 1 ) )
273 IF( uplo.EQ.
'L' )
THEN
275 CALL slartg( d( i ), e( i ), cs, sn, r )
278 d( i+1 ) = cs*d( i+1 )
280 CALL csrot( 1, b( i, 1 ), 1, b( i+1, 1 ), 1, cs, sn )
291 CALL csrot( 1, b( j, i ), 1, b( j+1, i ), 1, cs, sn )
300 orgnrm = slanst(
'M', n, d, e )
301 IF( orgnrm.EQ.zero )
THEN
302 CALL claset(
'A', n, nrhs, czero, czero, b, ldb )
306 CALL slascl(
'G', 0, 0, orgnrm, one, n, 1, d, n, info )
307 CALL slascl(
'G', 0, 0, orgnrm, one, nm1, 1, e, nm1, info )
312 IF( n.LE.smlsiz )
THEN
317 irwib = irwrb + n*nrhs
318 irwb = irwib + n*nrhs
319 CALL slaset(
'A', n, n, zero, one, rwork( irwu ), n )
320 CALL slaset(
'A', n, n, zero, one, rwork( irwvt ), n )
321 CALL slasdq(
'U', 0, n, n, n, 0, d, e, rwork( irwvt ), n,
322 $ rwork( irwu ), n, rwork( irwwrk ), 1,
323 $ rwork( irwwrk ), info )
336 rwork( j ) = real( b( jrow, jcol ) )
339 CALL sgemm(
'T',
'N', n, nrhs, n, one, rwork( irwu ), n,
340 $ rwork( irwb ), n, zero, rwork( irwrb ), n )
345 rwork( j ) = aimag( b( jrow, jcol ) )
348 CALL sgemm(
'T',
'N', n, nrhs, n, one, rwork( irwu ), n,
349 $ rwork( irwb ), n, zero, rwork( irwib ), n )
356 b( jrow, jcol ) = cmplx( rwork( jreal ), rwork( jimag ) )
360 tol = rcnd*abs( d( isamax( n, d, 1 ) ) )
362 IF( d( i ).LE.tol )
THEN
363 CALL claset(
'A', 1, nrhs, czero, czero, b( i, 1 ), ldb )
365 CALL clascl(
'G', 0, 0, d( i ), one, 1, nrhs, b( i, 1 ),
379 DO 120 jcol = 1, nrhs
382 rwork( j ) = real( b( jrow, jcol ) )
385 CALL sgemm(
'T',
'N', n, nrhs, n, one, rwork( irwvt ), n,
386 $ rwork( irwb ), n, zero, rwork( irwrb ), n )
388 DO 140 jcol = 1, nrhs
391 rwork( j ) = aimag( b( jrow, jcol ) )
394 CALL sgemm(
'T',
'N', n, nrhs, n, one, rwork( irwvt ), n,
395 $ rwork( irwb ), n, zero, rwork( irwib ), n )
398 DO 160 jcol = 1, nrhs
402 b( jrow, jcol ) = cmplx( rwork( jreal ), rwork( jimag ) )
408 CALL slascl(
'G', 0, 0, one, orgnrm, n, 1, d, n, info )
409 CALL slasrt(
'D', n, d, info )
410 CALL clascl(
'G', 0, 0, orgnrm, one, n, nrhs, b, ldb, info )
417 nlvl = int( log( real( n ) / real( smlsiz+1 ) ) / log( two ) ) + 1
429 givnum = poles + 2*nlvl*n
430 nrwork = givnum + 2*nlvl*n
434 irwib = irwrb + smlsiz*nrhs
435 irwb = irwib + smlsiz*nrhs
441 givcol = perm + nlvl*n
442 iwk = givcol + nlvl*n*2
451 IF( abs( d( i ) ).LT.eps )
THEN
452 d( i ) = sign( eps, d( i ) )
457 IF( ( abs( e( i ) ).LT.eps ) .OR. ( i.EQ.nm1 ) )
THEN
469 iwork( sizei+nsub-1 ) = nsize
470 ELSE IF( abs( e( i ) ).GE.eps )
THEN
475 iwork( sizei+nsub-1 ) = nsize
483 iwork( sizei+nsub-1 ) = nsize
486 iwork( sizei+nsub-1 ) = 1
487 CALL ccopy( nrhs, b( n, 1 ), ldb, work( bx+nm1 ), n )
490 IF( nsize.EQ.1 )
THEN
495 CALL ccopy( nrhs, b( st, 1 ), ldb, work( bx+st1 ), n )
496 ELSE IF( nsize.LE.smlsiz )
THEN
500 CALL slaset(
'A', nsize, nsize, zero, one,
501 $ rwork( vt+st1 ), n )
502 CALL slaset(
'A', nsize, nsize, zero, one,
503 $ rwork( u+st1 ), n )
504 CALL slasdq(
'U', 0, nsize, nsize, nsize, 0, d( st ),
505 $ e( st ), rwork( vt+st1 ), n, rwork( u+st1 ),
506 $ n, rwork( nrwork ), 1, rwork( nrwork ),
517 DO 190 jcol = 1, nrhs
518 DO 180 jrow = st, st + nsize - 1
520 rwork( j ) = real( b( jrow, jcol ) )
523 CALL sgemm(
'T',
'N', nsize, nrhs, nsize, one,
524 $ rwork( u+st1 ), n, rwork( irwb ), nsize,
525 $ zero, rwork( irwrb ), nsize )
527 DO 210 jcol = 1, nrhs
528 DO 200 jrow = st, st + nsize - 1
530 rwork( j ) = aimag( b( jrow, jcol ) )
533 CALL sgemm(
'T',
'N', nsize, nrhs, nsize, one,
534 $ rwork( u+st1 ), n, rwork( irwb ), nsize,
535 $ zero, rwork( irwib ), nsize )
538 DO 230 jcol = 1, nrhs
539 DO 220 jrow = st, st + nsize - 1
542 b( jrow, jcol ) = cmplx( rwork( jreal ),
547 CALL clacpy(
'A', nsize, nrhs, b( st, 1 ), ldb,
548 $ work( bx+st1 ), n )
553 CALL slasda( icmpq1, smlsiz, nsize, sqre, d( st ),
554 $ e( st ), rwork( u+st1 ), n, rwork( vt+st1 ),
555 $ iwork( k+st1 ), rwork( difl+st1 ),
556 $ rwork( difr+st1 ), rwork( z+st1 ),
557 $ rwork( poles+st1 ), iwork( givptr+st1 ),
558 $ iwork( givcol+st1 ), n, iwork( perm+st1 ),
559 $ rwork( givnum+st1 ), rwork( c+st1 ),
560 $ rwork( s+st1 ), rwork( nrwork ),
561 $ iwork( iwk ), info )
566 CALL clalsa( icmpq2, smlsiz, nsize, nrhs, b( st, 1 ),
567 $ ldb, work( bxst ), n, rwork( u+st1 ), n,
568 $ rwork( vt+st1 ), iwork( k+st1 ),
569 $ rwork( difl+st1 ), rwork( difr+st1 ),
570 $ rwork( z+st1 ), rwork( poles+st1 ),
571 $ iwork( givptr+st1 ), iwork( givcol+st1 ), n,
572 $ iwork( perm+st1 ), rwork( givnum+st1 ),
573 $ rwork( c+st1 ), rwork( s+st1 ),
574 $ rwork( nrwork ), iwork( iwk ), info )
585 tol = rcnd*abs( d( isamax( n, d, 1 ) ) )
592 IF( abs( d( i ) ).LE.tol )
THEN
593 CALL claset(
'A', 1, nrhs, czero, czero, work( bx+i-1 ), n )
596 CALL clascl(
'G', 0, 0, d( i ), one, 1, nrhs,
597 $ work( bx+i-1 ), n, info )
599 d( i ) = abs( d( i ) )
608 nsize = iwork( sizei+i-1 )
610 IF( nsize.EQ.1 )
THEN
611 CALL ccopy( nrhs, work( bxst ), n, b( st, 1 ), ldb )
612 ELSE IF( nsize.LE.smlsiz )
THEN
623 DO 270 jcol = 1, nrhs
625 DO 260 jrow = 1, nsize
627 rwork( jreal ) = real( work( j+jrow ) )
630 CALL sgemm(
'T',
'N', nsize, nrhs, nsize, one,
631 $ rwork( vt+st1 ), n, rwork( irwb ), nsize, zero,
632 $ rwork( irwrb ), nsize )
635 DO 290 jcol = 1, nrhs
637 DO 280 jrow = 1, nsize
639 rwork( jimag ) = aimag( work( j+jrow ) )
642 CALL sgemm(
'T',
'N', nsize, nrhs, nsize, one,
643 $ rwork( vt+st1 ), n, rwork( irwb ), nsize, zero,
644 $ rwork( irwib ), nsize )
647 DO 310 jcol = 1, nrhs
648 DO 300 jrow = st, st + nsize - 1
651 b( jrow, jcol ) = cmplx( rwork( jreal ),
656 CALL clalsa( icmpq2, smlsiz, nsize, nrhs, work( bxst ), n,
657 $ b( st, 1 ), ldb, rwork( u+st1 ), n,
658 $ rwork( vt+st1 ), iwork( k+st1 ),
659 $ rwork( difl+st1 ), rwork( difr+st1 ),
660 $ rwork( z+st1 ), rwork( poles+st1 ),
661 $ iwork( givptr+st1 ), iwork( givcol+st1 ), n,
662 $ iwork( perm+st1 ), rwork( givnum+st1 ),
663 $ rwork( c+st1 ), rwork( s+st1 ),
664 $ rwork( nrwork ), iwork( iwk ), info )
673 CALL slascl(
'G', 0, 0, one, orgnrm, n, 1, d, n, info )
674 CALL slasrt(
'D', n, d, info )
675 CALL clascl(
'G', 0, 0, orgnrm, one, n, nrhs, b, ldb, info )
subroutine xerbla(srname, info)
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
subroutine sgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
SGEMM
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
subroutine clalsa(icompq, smlsiz, n, nrhs, b, ldb, bx, ldbx, u, ldu, vt, k, difl, difr, z, poles, givptr, givcol, ldgcol, perm, givnum, c, s, rwork, iwork, info)
CLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd.
subroutine clalsd(uplo, smlsiz, n, nrhs, d, e, b, ldb, rcond, rank, work, rwork, iwork, info)
CLALSD uses the singular value decomposition of A to solve the least squares problem.
subroutine slartg(f, g, c, s, r)
SLARTG generates a plane rotation with real cosine and real sine.
subroutine clascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine slascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
SLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine slasda(icompq, smlsiz, n, sqre, d, e, u, ldu, vt, k, difl, difr, z, poles, givptr, givcol, ldgcol, perm, givnum, c, s, work, iwork, info)
SLASDA computes the singular value decomposition (SVD) of a real upper bidiagonal matrix with diagona...
subroutine slasdq(uplo, sqre, n, ncvt, nru, ncc, d, e, vt, ldvt, u, ldu, c, ldc, work, info)
SLASDQ computes the SVD of a real bidiagonal matrix with diagonal d and off-diagonal e....
subroutine slaset(uplo, m, n, alpha, beta, a, lda)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine slasrt(id, n, d, info)
SLASRT sorts numbers in increasing or decreasing order.
subroutine csrot(n, cx, incx, cy, incy, c, s)
CSROT