210 SUBROUTINE zgelsy( 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
219 DOUBLE PRECISION RCOND
223 DOUBLE PRECISION RWORK( * )
224 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
231 parameter( imax = 1, imin = 2 )
232 DOUBLE PRECISION ZERO, ONE
233 parameter( zero = 0.0d+0, one = 1.0d+0 )
234 COMPLEX*16 CZERO, CONE
235 parameter( czero = ( 0.0d+0, 0.0d+0 ),
236 $ cone = ( 1.0d+0, 0.0d+0 ) )
240 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, LWKOPT, MN,
241 $ nb, nb1, nb2, nb3, nb4
242 DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMAX, SMAXPR, SMIN, SMINPR,
244 COMPLEX*16 C1, C2, S1, S2
252 DOUBLE PRECISION DLAMCH, ZLANGE
253 EXTERNAL ilaenv, dlamch, zlange
256 INTRINSIC abs, dble, dcmplx, max, min
267 nb1 = ilaenv( 1,
'ZGEQRF',
' ', m, n, -1, -1 )
268 nb2 = ilaenv( 1,
'ZGERQF',
' ', m, n, -1, -1 )
269 nb3 = ilaenv( 1,
'ZUNMQR',
' ', m, n, nrhs, -1 )
270 nb4 = ilaenv( 1,
'ZUNMRQ',
' ', 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 ) = dcmplx( 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. .NOT.
291 CALL xerbla(
'ZGELSY', -info )
293 ELSE IF( lquery )
THEN
299 IF( min( m, n, nrhs ).EQ.0 )
THEN
306 smlnum = dlamch(
'S' ) / dlamch(
'P' )
307 bignum = one / smlnum
311 anrm = zlange(
'M', m, n, a, lda, rwork )
313 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
317 CALL zlascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
319 ELSE IF( anrm.GT.bignum )
THEN
323 CALL zlascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
325 ELSE IF( anrm.EQ.zero )
THEN
329 CALL zlaset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
334 bnrm = zlange(
'M', m, nrhs, b, ldb, rwork )
336 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
340 CALL zlascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
342 ELSE IF( bnrm.GT.bignum )
THEN
346 CALL zlascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
353 CALL zgeqp3( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ),
354 $ lwork-mn, rwork, info )
355 wsize = mn + dble( work( mn+1 ) )
364 smax = abs( a( 1, 1 ) )
366 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
368 CALL zlaset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
375 IF( rank.LT.mn )
THEN
377 CALL zlaic1( imin, rank, work( ismin ), smin, a( 1, i ),
378 $ a( i, i ), sminpr, s1, c1 )
379 CALL zlaic1( 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 ztzrzf( rank, n, a, lda, work( mn+1 ), work( 2*mn+1 ),
413 CALL zunmqr(
'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+dble( work( 2*mn+1 ) ) )
421 CALL ztrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
422 $ nrhs, cone, a, lda, b, ldb )
425 DO 30 i = rank + 1, n
433 CALL zunmrz(
'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 zcopy( n, work( 1 ), 1, b( 1, j ), 1 )
453 IF( iascl.EQ.1 )
THEN
454 CALL zlascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
455 CALL zlascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
457 ELSE IF( iascl.EQ.2 )
THEN
458 CALL zlascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
459 CALL zlascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
462 IF( ibscl.EQ.1 )
THEN
463 CALL zlascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
464 ELSE IF( ibscl.EQ.2 )
THEN
465 CALL zlascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )
469 work( 1 ) = dcmplx( lwkopt )
subroutine xerbla(srname, info)
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
subroutine zgelsy(m, n, nrhs, a, lda, b, ldb, jpvt, rcond, rank, work, lwork, rwork, info)
ZGELSY solves overdetermined or underdetermined systems for GE matrices
subroutine zgeqp3(m, n, a, lda, jpvt, tau, work, lwork, rwork, info)
ZGEQP3
subroutine zlaic1(job, j, x, sest, w, gamma, sestpr, s, c)
ZLAIC1 applies one step of incremental condition estimation.
subroutine zlascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
ZLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine zlaset(uplo, m, n, alpha, beta, a, lda)
ZLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine ztrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
ZTRSM
subroutine ztzrzf(m, n, a, lda, tau, work, lwork, info)
ZTZRZF
subroutine zunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
ZUNMQR
subroutine zunmrz(side, trans, m, n, k, l, a, lda, tau, c, ldc, work, lwork, info)
ZUNMRZ