184 SUBROUTINE cgelsx( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
185 $ work, rwork, info )
193 INTEGER INFO, LDA, LDB, M, N, NRHS, RANK
199 COMPLEX A( lda, * ), B( ldb, * ), WORK( * )
206 parameter ( imax = 1, imin = 2 )
207 REAL ZERO, ONE, DONE, NTDONE
208 parameter ( zero = 0.0e+0, one = 1.0e+0, done = zero,
211 parameter ( czero = ( 0.0e+0, 0.0e+0 ),
212 $ cone = ( 1.0e+0, 0.0e+0 ) )
215 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, K, MN
216 REAL ANRM, BIGNUM, BNRM, SMAX, SMAXPR, SMIN, SMINPR,
218 COMPLEX C1, C2, S1, S2, T1, T2
226 EXTERNAL clange, slamch
229 INTRINSIC abs, conjg, max, min
242 ELSE IF( n.LT.0 )
THEN
244 ELSE IF( nrhs.LT.0 )
THEN
246 ELSE IF( lda.LT.max( 1, m ) )
THEN
248 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
253 CALL xerbla(
'CGELSX', -info )
259 IF( min( m, n, nrhs ).EQ.0 )
THEN
266 smlnum = slamch(
'S' ) / slamch(
'P' )
267 bignum = one / smlnum
268 CALL slabad( smlnum, bignum )
272 anrm = clange(
'M', m, n, a, lda, rwork )
274 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
278 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
280 ELSE IF( anrm.GT.bignum )
THEN
284 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
286 ELSE IF( anrm.EQ.zero )
THEN
290 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
295 bnrm = clange(
'M', m, nrhs, b, ldb, rwork )
297 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
301 CALL clascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
303 ELSE IF( bnrm.GT.bignum )
THEN
307 CALL clascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
314 CALL cgeqpf( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ), rwork,
324 smax = abs( a( 1, 1 ) )
326 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
328 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
335 IF( rank.LT.mn )
THEN
337 CALL claic1( imin, rank, work( ismin ), smin, a( 1, i ),
338 $ a( i, i ), sminpr, s1, c1 )
339 CALL claic1( imax, rank, work( ismax ), smax, a( 1, i ),
340 $ a( i, i ), smaxpr, s2, c2 )
342 IF( smaxpr*rcond.LE.sminpr )
THEN
344 work( ismin+i-1 ) = s1*work( ismin+i-1 )
345 work( ismax+i-1 ) = s2*work( ismax+i-1 )
347 work( ismin+rank ) = c1
348 work( ismax+rank ) = c2
363 $
CALL ctzrqf( rank, n, a, lda, work( mn+1 ), info )
369 CALL cunm2r(
'Left',
'Conjugate transpose', m, nrhs, mn, a, lda,
370 $ work( 1 ), b, ldb, work( 2*mn+1 ), info )
376 CALL ctrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
377 $ nrhs, cone, a, lda, b, ldb )
379 DO 40 i = rank + 1, n
389 CALL clatzm(
'Left', n-rank+1, nrhs, a( i, rank+1 ), lda,
390 $ conjg( work( mn+i ) ), b( i, 1 ),
391 $ b( rank+1, 1 ), ldb, work( 2*mn+1 ) )
401 work( 2*mn+i ) = ntdone
404 IF( work( 2*mn+i ).EQ.ntdone )
THEN
405 IF( jpvt( i ).NE.i )
THEN
408 t2 = b( jpvt( k ), j )
410 b( jpvt( k ), j ) = t1
411 work( 2*mn+k ) = done
414 t2 = b( jpvt( k ), j )
418 work( 2*mn+k ) = done
426 IF( iascl.EQ.1 )
THEN
427 CALL clascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
428 CALL clascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
430 ELSE IF( iascl.EQ.2 )
THEN
431 CALL clascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
432 CALL clascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
435 IF( ibscl.EQ.1 )
THEN
436 CALL clascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
437 ELSE IF( ibscl.EQ.2 )
THEN
438 CALL clascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )
subroutine clatzm(SIDE, M, N, V, INCV, TAU, C1, C2, LDC, WORK)
CLATZM
subroutine cunm2r(SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, INFO)
CUNM2R multiplies a general matrix by the unitary matrix from a QR factorization determined by cgeqrf...
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 slabad(SMALL, LARGE)
SLABAD
subroutine xerbla(SRNAME, INFO)
XERBLA
subroutine ctrsm(SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA, B, LDB)
CTRSM
subroutine cgeqpf(M, N, A, LDA, JPVT, TAU, WORK, RWORK, INFO)
CGEQPF
subroutine cgelsx(M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK, WORK, RWORK, INFO)
CGELSX solves overdetermined or underdetermined systems for GE matrices
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 ctzrqf(M, N, A, LDA, TAU, INFO)
CTZRQF
subroutine claic1(JOB, J, X, SEST, W, GAMMA, SESTPR, S, C)
CLAIC1 applies one step of incremental condition estimation.