210 SUBROUTINE cgelsy( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
211 $ WORK, LWORK, RWORK, INFO )
218 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
224 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
231 parameter( imax = 1, imin = 2 )
233 parameter( zero = 0.0e+0, one = 1.0e+0 )
235 parameter( czero = ( 0.0e+0, 0.0e+0 ),
236 $ cone = ( 1.0e+0, 0.0e+0 ) )
240 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, LWKOPT, MN,
241 $ nb, nb1, nb2, nb3, nb4
242 REAL ANRM, BIGNUM, BNRM, SMAX, SMAXPR, SMIN, SMINPR,
244 COMPLEX C1, C2, S1, S2
253 EXTERNAL clange, ilaenv, slamch
256 INTRINSIC abs, max, min, real, cmplx
267 nb1 = ilaenv( 1,
'CGEQRF',
' ', m, n, -1, -1 )
268 nb2 = ilaenv( 1,
'CGERQF',
' ', m, n, -1, -1 )
269 nb3 = ilaenv( 1,
'CUNMQR',
' ', m, n, nrhs, -1 )
270 nb4 = ilaenv( 1,
'CUNMRQ',
' ', m, n, nrhs, -1 )
271 nb = max( nb1, nb2, nb3, nb4 )
272 lwkopt = max( 1, mn+2*n+nb*(n+1), 2*mn+nb*nrhs )
273 work( 1 ) = cmplx( lwkopt )
274 lquery = ( lwork.EQ.-1 )
277 ELSE IF( n.LT.0 )
THEN
279 ELSE IF( nrhs.LT.0 )
THEN
281 ELSE IF( lda.LT.max( 1, m ) )
THEN
283 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
285 ELSE IF( lwork.LT.( mn+max( 2*mn, n+1, mn+nrhs ) ) .AND.
291 CALL xerbla(
'CGELSY', -info )
293 ELSE IF( lquery )
THEN
299 IF( min( m, n, nrhs ).EQ.0 )
THEN
306 smlnum = slamch(
'S' ) / slamch(
'P' )
307 bignum = one / smlnum
311 anrm = clange(
'M', m, n, a, lda, rwork )
313 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
317 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
319 ELSE IF( anrm.GT.bignum )
THEN
323 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
325 ELSE IF( anrm.EQ.zero )
THEN
329 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
334 bnrm = clange(
'M', m, nrhs, b, ldb, rwork )
336 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
340 CALL clascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
342 ELSE IF( bnrm.GT.bignum )
THEN
346 CALL clascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
353 CALL cgeqp3( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ),
354 $ lwork-mn, rwork, info )
355 wsize = mn + real( work( mn+1 ) )
364 smax = abs( a( 1, 1 ) )
366 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
368 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
375 IF( rank.LT.mn )
THEN
377 CALL claic1( imin, rank, work( ismin ), smin, a( 1, i ),
378 $ a( i, i ), sminpr, s1, c1 )
379 CALL claic1( imax, rank, work( ismax ), smax, a( 1, i ),
380 $ a( i, i ), smaxpr, s2, c2 )
382 IF( smaxpr*rcond.LE.sminpr )
THEN
384 work( ismin+i-1 ) = s1*work( ismin+i-1 )
385 work( ismax+i-1 ) = s2*work( ismax+i-1 )
387 work( ismin+rank ) = c1
388 work( ismax+rank ) = c2
405 $
CALL ctzrzf( rank, n, a, lda, work( mn+1 ), work( 2*mn+1 ),
413 CALL cunmqr(
'Left',
'Conjugate transpose', m, nrhs, mn, a, lda,
414 $ work( 1 ), b, ldb, work( 2*mn+1 ), lwork-2*mn, info )
415 wsize = max( wsize, 2*mn+real( work( 2*mn+1 ) ) )
421 CALL ctrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
422 $ nrhs, cone, a, lda, b, ldb )
425 DO 30 i = rank + 1, n
433 CALL cunmrz(
'Left',
'Conjugate transpose', n, nrhs, rank,
434 $ n-rank, a, lda, work( mn+1 ), b, ldb,
435 $ work( 2*mn+1 ), lwork-2*mn, info )
444 work( jpvt( i ) ) = b( i, j )
446 CALL ccopy( n, work( 1 ), 1, b( 1, j ), 1 )
453 IF( iascl.EQ.1 )
THEN
454 CALL clascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
455 CALL clascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
457 ELSE IF( iascl.EQ.2 )
THEN
458 CALL clascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
459 CALL clascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
462 IF( ibscl.EQ.1 )
THEN
463 CALL clascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
464 ELSE IF( ibscl.EQ.2 )
THEN
465 CALL clascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )
469 work( 1 ) = cmplx( lwkopt )
subroutine xerbla(srname, info)
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
subroutine cgelsy(m, n, nrhs, a, lda, b, ldb, jpvt, rcond, rank, work, lwork, rwork, info)
CGELSY solves overdetermined or underdetermined systems for GE matrices
subroutine cgeqp3(m, n, a, lda, jpvt, tau, work, lwork, rwork, info)
CGEQP3
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 ctzrzf(m, n, a, lda, tau, work, lwork, info)
CTZRZF
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
subroutine cunmrz(side, trans, m, n, k, l, a, lda, tau, c, ldc, work, lwork, info)
CUNMRZ