LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ dgelst()

subroutine dgelst ( character  TRANS,
integer  M,
integer  N,
integer  NRHS,
double precision, dimension( lda, * )  A,
integer  LDA,
double precision, dimension( ldb, * )  B,
integer  LDB,
double precision, dimension( * )  WORK,
integer  LWORK,
integer  INFO 
)

DGELST solves overdetermined or underdetermined systems for GE matrices using QR or LQ factorization with compact WY representation of Q.

Download DGELST + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 DGELST solves overdetermined or underdetermined real linear systems
 involving an M-by-N matrix A, or its transpose, using a QR or LQ
 factorization of A with compact WY representation of Q.
 It is assumed that A has full rank.

 The following options are provided:

 1. If TRANS = 'N' and m >= n:  find the least squares solution of
    an overdetermined system, i.e., solve the least squares problem
                 minimize || B - A*X ||.

 2. If TRANS = 'N' and m < n:  find the minimum norm solution of
    an underdetermined system A * X = B.

 3. If TRANS = 'T' and m >= n:  find the minimum norm solution of
    an underdetermined system A**T * X = B.

 4. If TRANS = 'T' and m < n:  find the least squares solution of
    an overdetermined system, i.e., solve the least squares problem
                 minimize || B - A**T * X ||.

 Several right hand side vectors b and solution vectors x can be
 handled in a single call; they are stored as the columns of the
 M-by-NRHS right hand side matrix B and the N-by-NRHS solution
 matrix X.
Parameters
[in]TRANS
          TRANS is CHARACTER*1
          = 'N': the linear system involves A;
          = 'T': the linear system involves A**T.
[in]M
          M is INTEGER
          The number of rows of the matrix A.  M >= 0.
[in]N
          N is INTEGER
          The number of columns of the matrix A.  N >= 0.
[in]NRHS
          NRHS is INTEGER
          The number of right hand sides, i.e., the number of
          columns of the matrices B and X. NRHS >=0.
[in,out]A
          A is DOUBLE PRECISION array, dimension (LDA,N)
          On entry, the M-by-N matrix A.
          On exit,
            if M >= N, A is overwritten by details of its QR
                       factorization as returned by DGEQRT;
            if M <  N, A is overwritten by details of its LQ
                       factorization as returned by DGELQT.
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,M).
[in,out]B
          B is DOUBLE PRECISION array, dimension (LDB,NRHS)
          On entry, the matrix B of right hand side vectors, stored
          columnwise; B is M-by-NRHS if TRANS = 'N', or N-by-NRHS
          if TRANS = 'T'.
          On exit, if INFO = 0, B is overwritten by the solution
          vectors, stored columnwise:
          if TRANS = 'N' and m >= n, rows 1 to n of B contain the least
          squares solution vectors; the residual sum of squares for the
          solution in each column is given by the sum of squares of
          elements N+1 to M in that column;
          if TRANS = 'N' and m < n, rows 1 to N of B contain the
          minimum norm solution vectors;
          if TRANS = 'T' and m >= n, rows 1 to M of B contain the
          minimum norm solution vectors;
          if TRANS = 'T' and m < n, rows 1 to M of B contain the
          least squares solution vectors; the residual sum of squares
          for the solution in each column is given by the sum of
          squares of elements M+1 to N in that column.
[in]LDB
          LDB is INTEGER
          The leading dimension of the array B. LDB >= MAX(1,M,N).
[out]WORK
          WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
[in]LWORK
          LWORK is INTEGER
          The dimension of the array WORK.
          LWORK >= max( 1, MN + max( MN, NRHS ) ).
          For optimal performance,
          LWORK >= max( 1, (MN + max( MN, NRHS ))*NB ).
          where MN = min(M,N) and NB is the optimum block size.

          If LWORK = -1, then a workspace query is assumed; the routine
          only calculates the optimal size of the WORK array, returns
          this value as the first entry of the WORK array, and no error
          message related to LWORK is issued by XERBLA.
[out]INFO
          INFO is INTEGER
          = 0:  successful exit
          < 0:  if INFO = -i, the i-th argument had an illegal value
          > 0:  if INFO =  i, the i-th diagonal element of the
                triangular factor of A is zero, so that A does not have
                full rank; the least squares solution could not be
                computed.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Contributors:
  November 2022,  Igor Kozachenko,
                  Computer Science Division,
                  University of California, Berkeley

Definition at line 192 of file dgelst.f.

194*
195* -- LAPACK driver routine --
196* -- LAPACK is a software package provided by Univ. of Tennessee, --
197* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
198*
199* .. Scalar Arguments ..
200 CHARACTER TRANS
201 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
202* ..
203* .. Array Arguments ..
204 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( * )
205* ..
206*
207* =====================================================================
208*
209* .. Parameters ..
210 DOUBLE PRECISION ZERO, ONE
211 parameter( zero = 0.0d+0, one = 1.0d+0 )
212* ..
213* .. Local Scalars ..
214 LOGICAL LQUERY, TPSD
215 INTEGER BROW, I, IASCL, IBSCL, J, LWOPT, MN, MNNRHS,
216 $ NB, NBMIN, SCLLEN
217 DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMLNUM
218* ..
219* .. Local Arrays ..
220 DOUBLE PRECISION RWORK( 1 )
221* ..
222* .. External Functions ..
223 LOGICAL LSAME
224 INTEGER ILAENV
225 DOUBLE PRECISION DLAMCH, DLANGE
226 EXTERNAL lsame, ilaenv, dlamch, dlange
227* ..
228* .. External Subroutines ..
229 EXTERNAL dgelqt, dgeqrt, dgemlqt, dgemqrt, dlabad,
231* ..
232* .. Intrinsic Functions ..
233 INTRINSIC dble, max, min
234* ..
235* .. Executable Statements ..
236*
237* Test the input arguments.
238*
239 info = 0
240 mn = min( m, n )
241 lquery = ( lwork.EQ.-1 )
242 IF( .NOT.( lsame( trans, 'N' ) .OR. lsame( trans, 'T' ) ) ) THEN
243 info = -1
244 ELSE IF( m.LT.0 ) THEN
245 info = -2
246 ELSE IF( n.LT.0 ) THEN
247 info = -3
248 ELSE IF( nrhs.LT.0 ) THEN
249 info = -4
250 ELSE IF( lda.LT.max( 1, m ) ) THEN
251 info = -6
252 ELSE IF( ldb.LT.max( 1, m, n ) ) THEN
253 info = -8
254 ELSE IF( lwork.LT.max( 1, mn+max( mn, nrhs ) ) .AND. .NOT.lquery )
255 $ THEN
256 info = -10
257 END IF
258*
259* Figure out optimal block size and optimal workspace size
260*
261 IF( info.EQ.0 .OR. info.EQ.-10 ) THEN
262*
263 tpsd = .true.
264 IF( lsame( trans, 'N' ) )
265 $ tpsd = .false.
266*
267 nb = ilaenv( 1, 'DGELST', ' ', m, n, -1, -1 )
268*
269 mnnrhs = max( mn, nrhs )
270 lwopt = max( 1, (mn+mnnrhs)*nb )
271 work( 1 ) = dble( lwopt )
272*
273 END IF
274*
275 IF( info.NE.0 ) THEN
276 CALL xerbla( 'DGELST ', -info )
277 RETURN
278 ELSE IF( lquery ) THEN
279 RETURN
280 END IF
281*
282* Quick return if possible
283*
284 IF( min( m, n, nrhs ).EQ.0 ) THEN
285 CALL dlaset( 'Full', max( m, n ), nrhs, zero, zero, b, ldb )
286 work( 1 ) = dble( lwopt )
287 RETURN
288 END IF
289*
290* *GEQRT and *GELQT routines cannot accept NB larger than min(M,N)
291*
292 IF( nb.GT.mn ) nb = mn
293*
294* Determine the block size from the supplied LWORK
295* ( at this stage we know that LWORK >= (minimum required workspace,
296* but it may be less than optimal)
297*
298 nb = min( nb, lwork/( mn + mnnrhs ) )
299*
300* The minimum value of NB, when blocked code is used
301*
302 nbmin = max( 2, ilaenv( 2, 'DGELST', ' ', m, n, -1, -1 ) )
303*
304 IF( nb.LT.nbmin ) THEN
305 nb = 1
306 END IF
307*
308* Get machine parameters
309*
310 smlnum = dlamch( 'S' ) / dlamch( 'P' )
311 bignum = one / smlnum
312 CALL dlabad( smlnum, bignum )
313*
314* Scale A, B if max element outside range [SMLNUM,BIGNUM]
315*
316 anrm = dlange( 'M', m, n, a, lda, rwork )
317 iascl = 0
318 IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
319*
320* Scale matrix norm up to SMLNUM
321*
322 CALL dlascl( 'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
323 iascl = 1
324 ELSE IF( anrm.GT.bignum ) THEN
325*
326* Scale matrix norm down to BIGNUM
327*
328 CALL dlascl( 'G', 0, 0, anrm, bignum, m, n, a, lda, info )
329 iascl = 2
330 ELSE IF( anrm.EQ.zero ) THEN
331*
332* Matrix all zero. Return zero solution.
333*
334 CALL dlaset( 'Full', max( m, n ), nrhs, zero, zero, b, ldb )
335 work( 1 ) = dble( lwopt )
336 RETURN
337 END IF
338*
339 brow = m
340 IF( tpsd )
341 $ brow = n
342 bnrm = dlange( 'M', brow, nrhs, b, ldb, rwork )
343 ibscl = 0
344 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum ) THEN
345*
346* Scale matrix norm up to SMLNUM
347*
348 CALL dlascl( 'G', 0, 0, bnrm, smlnum, brow, nrhs, b, ldb,
349 $ info )
350 ibscl = 1
351 ELSE IF( bnrm.GT.bignum ) THEN
352*
353* Scale matrix norm down to BIGNUM
354*
355 CALL dlascl( 'G', 0, 0, bnrm, bignum, brow, nrhs, b, ldb,
356 $ info )
357 ibscl = 2
358 END IF
359*
360 IF( m.GE.n ) THEN
361*
362* M > N:
363* Compute the blocked QR factorization of A,
364* using the compact WY representation of Q,
365* workspace at least N, optimally N*NB.
366*
367 CALL dgeqrt( m, n, nb, a, lda, work( 1 ), nb,
368 $ work( mn*nb+1 ), info )
369*
370 IF( .NOT.tpsd ) THEN
371*
372* M > N, A is not transposed:
373* Overdetermined system of equations,
374* least-squares problem, min || A * X - B ||.
375*
376* Compute B(1:M,1:NRHS) := Q**T * B(1:M,1:NRHS),
377* using the compact WY representation of Q,
378* workspace at least NRHS, optimally NRHS*NB.
379*
380 CALL dgemqrt( 'Left', 'Transpose', m, nrhs, n, nb, a, lda,
381 $ work( 1 ), nb, b, ldb, work( mn*nb+1 ),
382 $ info )
383*
384* Compute B(1:N,1:NRHS) := inv(R) * B(1:N,1:NRHS)
385*
386 CALL dtrtrs( 'Upper', 'No transpose', 'Non-unit', n, nrhs,
387 $ a, lda, b, ldb, info )
388*
389 IF( info.GT.0 ) THEN
390 RETURN
391 END IF
392*
393 scllen = n
394*
395 ELSE
396*
397* M > N, A is transposed:
398* Underdetermined system of equations,
399* minimum norm solution of A**T * X = B.
400*
401* Compute B := inv(R**T) * B in two row blocks of B.
402*
403* Block 1: B(1:N,1:NRHS) := inv(R**T) * B(1:N,1:NRHS)
404*
405 CALL dtrtrs( 'Upper', 'Transpose', 'Non-unit', n, nrhs,
406 $ a, lda, b, ldb, info )
407*
408 IF( info.GT.0 ) THEN
409 RETURN
410 END IF
411*
412* Block 2: Zero out all rows below the N-th row in B:
413* B(N+1:M,1:NRHS) = ZERO
414*
415 DO j = 1, nrhs
416 DO i = n + 1, m
417 b( i, j ) = zero
418 END DO
419 END DO
420*
421* Compute B(1:M,1:NRHS) := Q(1:N,:) * B(1:N,1:NRHS),
422* using the compact WY representation of Q,
423* workspace at least NRHS, optimally NRHS*NB.
424*
425 CALL dgemqrt( 'Left', 'No transpose', m, nrhs, n, nb,
426 $ a, lda, work( 1 ), nb, b, ldb,
427 $ work( mn*nb+1 ), info )
428*
429 scllen = m
430*
431 END IF
432*
433 ELSE
434*
435* M < N:
436* Compute the blocked LQ factorization of A,
437* using the compact WY representation of Q,
438* workspace at least M, optimally M*NB.
439*
440 CALL dgelqt( m, n, nb, a, lda, work( 1 ), nb,
441 $ work( mn*nb+1 ), info )
442*
443 IF( .NOT.tpsd ) THEN
444*
445* M < N, A is not transposed:
446* Underdetermined system of equations,
447* minimum norm solution of A * X = B.
448*
449* Compute B := inv(L) * B in two row blocks of B.
450*
451* Block 1: B(1:M,1:NRHS) := inv(L) * B(1:M,1:NRHS)
452*
453 CALL dtrtrs( 'Lower', 'No transpose', 'Non-unit', m, nrhs,
454 $ a, lda, b, ldb, info )
455*
456 IF( info.GT.0 ) THEN
457 RETURN
458 END IF
459*
460* Block 2: Zero out all rows below the M-th row in B:
461* B(M+1:N,1:NRHS) = ZERO
462*
463 DO j = 1, nrhs
464 DO i = m + 1, n
465 b( i, j ) = zero
466 END DO
467 END DO
468*
469* Compute B(1:N,1:NRHS) := Q(1:N,:)**T * B(1:M,1:NRHS),
470* using the compact WY representation of Q,
471* workspace at least NRHS, optimally NRHS*NB.
472*
473 CALL dgemlqt( 'Left', 'Transpose', n, nrhs, m, nb, a, lda,
474 $ work( 1 ), nb, b, ldb,
475 $ work( mn*nb+1 ), info )
476*
477 scllen = n
478*
479 ELSE
480*
481* M < N, A is transposed:
482* Overdetermined system of equations,
483* least-squares problem, min || A**T * X - B ||.
484*
485* Compute B(1:N,1:NRHS) := Q * B(1:N,1:NRHS),
486* using the compact WY representation of Q,
487* workspace at least NRHS, optimally NRHS*NB.
488*
489 CALL dgemlqt( 'Left', 'No transpose', n, nrhs, m, nb,
490 $ a, lda, work( 1 ), nb, b, ldb,
491 $ work( mn*nb+1), info )
492*
493* Compute B(1:M,1:NRHS) := inv(L**T) * B(1:M,1:NRHS)
494*
495 CALL dtrtrs( 'Lower', 'Transpose', 'Non-unit', m, nrhs,
496 $ a, lda, b, ldb, info )
497*
498 IF( info.GT.0 ) THEN
499 RETURN
500 END IF
501*
502 scllen = m
503*
504 END IF
505*
506 END IF
507*
508* Undo scaling
509*
510 IF( iascl.EQ.1 ) THEN
511 CALL dlascl( 'G', 0, 0, anrm, smlnum, scllen, nrhs, b, ldb,
512 $ info )
513 ELSE IF( iascl.EQ.2 ) THEN
514 CALL dlascl( 'G', 0, 0, anrm, bignum, scllen, nrhs, b, ldb,
515 $ info )
516 END IF
517 IF( ibscl.EQ.1 ) THEN
518 CALL dlascl( 'G', 0, 0, smlnum, bnrm, scllen, nrhs, b, ldb,
519 $ info )
520 ELSE IF( ibscl.EQ.2 ) THEN
521 CALL dlascl( 'G', 0, 0, bignum, bnrm, scllen, nrhs, b, ldb,
522 $ info )
523 END IF
524*
525 work( 1 ) = dble( lwopt )
526*
527 RETURN
528*
529* End of DGELST
530*
double precision function dlamch(CMACH)
DLAMCH
Definition: dlamch.f:69
subroutine dlabad(SMALL, LARGE)
DLABAD
Definition: dlabad.f:74
subroutine dlascl(TYPE, KL, KU, CFROM, CTO, M, N, A, LDA, INFO)
DLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition: dlascl.f:143
subroutine dlaset(UPLO, M, N, ALPHA, BETA, A, LDA)
DLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition: dlaset.f:110
integer function ilaenv(ISPEC, NAME, OPTS, N1, N2, N3, N4)
ILAENV
Definition: ilaenv.f:162
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:60
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:53
double precision function dlange(NORM, M, N, A, LDA, WORK)
DLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition: dlange.f:114
subroutine dgemlqt(SIDE, TRANS, M, N, K, MB, V, LDV, T, LDT, C, LDC, WORK, INFO)
DGEMLQT
Definition: dgemlqt.f:168
subroutine dgeqrt(M, N, NB, A, LDA, T, LDT, WORK, INFO)
DGEQRT
Definition: dgeqrt.f:141
subroutine dgemqrt(SIDE, TRANS, M, N, K, NB, V, LDV, T, LDT, C, LDC, WORK, INFO)
DGEMQRT
Definition: dgemqrt.f:168
subroutine dgelqt(M, N, MB, A, LDA, T, LDT, WORK, INFO)
DGELQT
Definition: dgelqt.f:139
subroutine dtrtrs(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO)
DTRTRS
Definition: dtrtrs.f:140
Here is the call graph for this function:
Here is the caller graph for this function: