182 SUBROUTINE cgelsx( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
183 $ WORK, RWORK, INFO )
190 INTEGER INFO, LDA, LDB, M, N, NRHS, RANK
196 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
203 parameter( imax = 1, imin = 2 )
204 REAL ZERO, ONE, DONE, NTDONE
205 parameter( zero = 0.0e+0, one = 1.0e+0, done = zero,
208 parameter( czero = ( 0.0e+0, 0.0e+0 ),
209 $ cone = ( 1.0e+0, 0.0e+0 ) )
212 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, K, MN
213 REAL ANRM, BIGNUM, BNRM, SMAX, SMAXPR, SMIN, SMINPR,
215 COMPLEX C1, C2, S1, S2, T1, T2
223 EXTERNAL clange, slamch
226 INTRINSIC abs, conjg, max, min
239 ELSE IF( n.LT.0 )
THEN
241 ELSE IF( nrhs.LT.0 )
THEN
243 ELSE IF( lda.LT.max( 1, m ) )
THEN
245 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
250 CALL xerbla(
'CGELSX', -info )
256 IF( min( m, n, nrhs ).EQ.0 )
THEN
263 smlnum = slamch(
'S' ) / slamch(
'P' )
264 bignum = one / smlnum
268 anrm = clange(
'M', m, n, a, lda, rwork )
270 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
274 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
276 ELSE IF( anrm.GT.bignum )
THEN
280 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
282 ELSE IF( anrm.EQ.zero )
THEN
286 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
291 bnrm = clange(
'M', m, nrhs, b, ldb, rwork )
293 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
297 CALL clascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
299 ELSE IF( bnrm.GT.bignum )
THEN
303 CALL clascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
310 CALL cgeqpf( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ), rwork,
320 smax = abs( a( 1, 1 ) )
322 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
324 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
331 IF( rank.LT.mn )
THEN
333 CALL claic1( imin, rank, work( ismin ), smin, a( 1, i ),
334 $ a( i, i ), sminpr, s1, c1 )
335 CALL claic1( imax, rank, work( ismax ), smax, a( 1, i ),
336 $ a( i, i ), smaxpr, s2, c2 )
338 IF( smaxpr*rcond.LE.sminpr )
THEN
340 work( ismin+i-1 ) = s1*work( ismin+i-1 )
341 work( ismax+i-1 ) = s2*work( ismax+i-1 )
343 work( ismin+rank ) = c1
344 work( ismax+rank ) = c2
359 $
CALL ctzrqf( rank, n, a, lda, work( mn+1 ), info )
365 CALL cunm2r(
'Left',
'Conjugate transpose', m, nrhs, mn, a, lda,
366 $ work( 1 ), b, ldb, work( 2*mn+1 ), info )
372 CALL ctrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
373 $ nrhs, cone, a, lda, b, ldb )
375 DO 40 i = rank + 1, n
385 CALL clatzm(
'Left', n-rank+1, nrhs, a( i, rank+1 ), lda,
386 $ conjg( work( mn+i ) ), b( i, 1 ),
387 $ b( rank+1, 1 ), ldb, work( 2*mn+1 ) )
397 work( 2*mn+i ) = ntdone
400 IF( work( 2*mn+i ).EQ.ntdone )
THEN
401 IF( jpvt( i ).NE.i )
THEN
404 t2 = b( jpvt( k ), j )
406 b( jpvt( k ), j ) = t1
407 work( 2*mn+k ) = done
410 t2 = b( jpvt( k ), j )
414 work( 2*mn+k ) = done
422 IF( iascl.EQ.1 )
THEN
423 CALL clascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
424 CALL clascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
426 ELSE IF( iascl.EQ.2 )
THEN
427 CALL clascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
428 CALL clascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
431 IF( ibscl.EQ.1 )
THEN
432 CALL clascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
433 ELSE IF( ibscl.EQ.2 )
THEN
434 CALL clascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )
subroutine xerbla(srname, info)
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 cgeqpf(m, n, a, lda, jpvt, tau, work, rwork, info)
CGEQPF
subroutine clatzm(side, m, n, v, incv, tau, c1, c2, ldc, work)
CLATZM
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.
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 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 ctrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRSM
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...