LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgelsd.f
Go to the documentation of this file.
1*> \brief <b> CGELSD computes the minimum-norm solution to a linear least squares problem for GE matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> \htmlonly
9*> Download CGELSD + dependencies
10*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgelsd.f">
11*> [TGZ]</a>
12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgelsd.f">
13*> [ZIP]</a>
14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgelsd.f">
15*> [TXT]</a>
16*> \endhtmlonly
17*
18* Definition:
19* ===========
20*
21* SUBROUTINE CGELSD( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
22* WORK, LWORK, RWORK, IWORK, INFO )
23*
24* .. Scalar Arguments ..
25* INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
26* REAL RCOND
27* ..
28* .. Array Arguments ..
29* INTEGER IWORK( * )
30* REAL RWORK( * ), S( * )
31* COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
32* ..
33*
34*
35*> \par Purpose:
36* =============
37*>
38*> \verbatim
39*>
40*> CGELSD computes the minimum-norm solution to a real linear least
41*> squares problem:
42*> minimize 2-norm(| b - A*x |)
43*> using the singular value decomposition (SVD) of A. A is an M-by-N
44*> matrix which may be rank-deficient.
45*>
46*> Several right hand side vectors b and solution vectors x can be
47*> handled in a single call; they are stored as the columns of the
48*> M-by-NRHS right hand side matrix B and the N-by-NRHS solution
49*> matrix X.
50*>
51*> The problem is solved in three steps:
52*> (1) Reduce the coefficient matrix A to bidiagonal form with
53*> Householder transformations, reducing the original problem
54*> into a "bidiagonal least squares problem" (BLS)
55*> (2) Solve the BLS using a divide and conquer approach.
56*> (3) Apply back all the Householder transformations to solve
57*> the original least squares problem.
58*>
59*> The effective rank of A is determined by treating as zero those
60*> singular values which are less than RCOND times the largest singular
61*> value.
62*>
63*> \endverbatim
64*
65* Arguments:
66* ==========
67*
68*> \param[in] M
69*> \verbatim
70*> M is INTEGER
71*> The number of rows of the matrix A. M >= 0.
72*> \endverbatim
73*>
74*> \param[in] N
75*> \verbatim
76*> N is INTEGER
77*> The number of columns of the matrix A. N >= 0.
78*> \endverbatim
79*>
80*> \param[in] NRHS
81*> \verbatim
82*> NRHS is INTEGER
83*> The number of right hand sides, i.e., the number of columns
84*> of the matrices B and X. NRHS >= 0.
85*> \endverbatim
86*>
87*> \param[in,out] A
88*> \verbatim
89*> A is COMPLEX array, dimension (LDA,N)
90*> On entry, the M-by-N matrix A.
91*> On exit, A has been destroyed.
92*> \endverbatim
93*>
94*> \param[in] LDA
95*> \verbatim
96*> LDA is INTEGER
97*> The leading dimension of the array A. LDA >= max(1,M).
98*> \endverbatim
99*>
100*> \param[in,out] B
101*> \verbatim
102*> B is COMPLEX array, dimension (LDB,NRHS)
103*> On entry, the M-by-NRHS right hand side matrix B.
104*> On exit, B is overwritten by the N-by-NRHS solution matrix X.
105*> If m >= n and RANK = n, the residual sum-of-squares for
106*> the solution in the i-th column is given by the sum of
107*> squares of the modulus of elements n+1:m in that column.
108*> \endverbatim
109*>
110*> \param[in] LDB
111*> \verbatim
112*> LDB is INTEGER
113*> The leading dimension of the array B. LDB >= max(1,M,N).
114*> \endverbatim
115*>
116*> \param[out] S
117*> \verbatim
118*> S is REAL array, dimension (min(M,N))
119*> The singular values of A in decreasing order.
120*> The condition number of A in the 2-norm = S(1)/S(min(m,n)).
121*> \endverbatim
122*>
123*> \param[in] RCOND
124*> \verbatim
125*> RCOND is REAL
126*> RCOND is used to determine the effective rank of A.
127*> Singular values S(i) <= RCOND*S(1) are treated as zero.
128*> If RCOND < 0, machine precision is used instead.
129*> \endverbatim
130*>
131*> \param[out] RANK
132*> \verbatim
133*> RANK is INTEGER
134*> The effective rank of A, i.e., the number of singular values
135*> which are greater than RCOND*S(1).
136*> \endverbatim
137*>
138*> \param[out] WORK
139*> \verbatim
140*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
141*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
142*> \endverbatim
143*>
144*> \param[in] LWORK
145*> \verbatim
146*> LWORK is INTEGER
147*> The dimension of the array WORK. LWORK must be at least 1.
148*> The exact minimum amount of workspace needed depends on M,
149*> N and NRHS. As long as LWORK is at least
150*> 2 * N + N * NRHS
151*> if M is greater than or equal to N or
152*> 2 * M + M * NRHS
153*> if M is less than N, the code will execute correctly.
154*> For good performance, LWORK should generally be larger.
155*>
156*> If LWORK = -1, then a workspace query is assumed; the routine
157*> only calculates the optimal size of the array WORK and the
158*> minimum sizes of the arrays RWORK and IWORK, and returns
159*> these values as the first entries of the WORK, RWORK and
160*> IWORK arrays, and no error message related to LWORK is issued
161*> by XERBLA.
162*> \endverbatim
163*>
164*> \param[out] RWORK
165*> \verbatim
166*> RWORK is REAL array, dimension (MAX(1,LRWORK))
167*> LRWORK >=
168*> 10*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS +
169*> MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
170*> if M is greater than or equal to N or
171*> 10*M + 2*M*SMLSIZ + 8*M*NLVL + 3*SMLSIZ*NRHS +
172*> MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
173*> if M is less than N, the code will execute correctly.
174*> SMLSIZ is returned by ILAENV and is equal to the maximum
175*> size of the subproblems at the bottom of the computation
176*> tree (usually about 25), and
177*> NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 )
178*> On exit, if INFO = 0, RWORK(1) returns the minimum LRWORK.
179*> \endverbatim
180*>
181*> \param[out] IWORK
182*> \verbatim
183*> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
184*> LIWORK >= max(1, 3*MINMN*NLVL + 11*MINMN),
185*> where MINMN = MIN( M,N ).
186*> On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK.
187*> \endverbatim
188*>
189*> \param[out] INFO
190*> \verbatim
191*> INFO is INTEGER
192*> = 0: successful exit
193*> < 0: if INFO = -i, the i-th argument had an illegal value.
194*> > 0: the algorithm for computing the SVD failed to converge;
195*> if INFO = i, i off-diagonal elements of an intermediate
196*> bidiagonal form did not converge to zero.
197*> \endverbatim
198*
199* Authors:
200* ========
201*
202*> \author Univ. of Tennessee
203*> \author Univ. of California Berkeley
204*> \author Univ. of Colorado Denver
205*> \author NAG Ltd.
206*
207*> \ingroup gelsd
208*
209*> \par Contributors:
210* ==================
211*>
212*> Ming Gu and Ren-Cang Li, Computer Science Division, University of
213*> California at Berkeley, USA \n
214*> Osni Marques, LBNL/NERSC, USA \n
215*
216* =====================================================================
217 SUBROUTINE cgelsd( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
218 $ WORK, LWORK, RWORK, IWORK, INFO )
219*
220* -- LAPACK driver routine --
221* -- LAPACK is a software package provided by Univ. of Tennessee, --
222* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
223*
224* .. Scalar Arguments ..
225 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
226 REAL RCOND
227* ..
228* .. Array Arguments ..
229 INTEGER IWORK( * )
230 REAL RWORK( * ), S( * )
231 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
232* ..
233*
234* =====================================================================
235*
236* .. Parameters ..
237 REAL ZERO, ONE, TWO
238 parameter( zero = 0.0e+0, one = 1.0e+0, two = 2.0e+0 )
239 COMPLEX CZERO
240 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
241* ..
242* .. Local Scalars ..
243 LOGICAL LQUERY
244 INTEGER IASCL, IBSCL, IE, IL, ITAU, ITAUP, ITAUQ,
245 $ ldwork, liwork, lrwork, maxmn, maxwrk, minmn,
246 $ minwrk, mm, mnthr, nlvl, nrwork, nwork, smlsiz
247 REAL ANRM, BIGNUM, BNRM, EPS, SFMIN, SMLNUM
248* ..
249* .. External Subroutines ..
250 EXTERNAL cgebrd, cgelqf, cgeqrf, clacpy,
252 $ cunmlq, cunmqr, slascl,
253 $ slaset, xerbla
254* ..
255* .. External Functions ..
256 INTEGER ILAENV
257 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
258 EXTERNAL clange, slamch, ilaenv, sroundup_lwork
259* ..
260* .. Intrinsic Functions ..
261 INTRINSIC int, log, max, min, real
262* ..
263* .. Executable Statements ..
264*
265* Test the input arguments.
266*
267 info = 0
268 minmn = min( m, n )
269 maxmn = max( m, n )
270 lquery = ( lwork.EQ.-1 )
271 IF( m.LT.0 ) THEN
272 info = -1
273 ELSE IF( n.LT.0 ) THEN
274 info = -2
275 ELSE IF( nrhs.LT.0 ) THEN
276 info = -3
277 ELSE IF( lda.LT.max( 1, m ) ) THEN
278 info = -5
279 ELSE IF( ldb.LT.max( 1, maxmn ) ) THEN
280 info = -7
281 END IF
282*
283* Compute workspace.
284* (Note: Comments in the code beginning "Workspace:" describe the
285* minimal amount of workspace needed at that point in the code,
286* as well as the preferred amount for good performance.
287* NB refers to the optimal block size for the immediately
288* following subroutine, as returned by ILAENV.)
289*
290 IF( info.EQ.0 ) THEN
291 minwrk = 1
292 maxwrk = 1
293 liwork = 1
294 lrwork = 1
295 IF( minmn.GT.0 ) THEN
296 smlsiz = ilaenv( 9, 'CGELSD', ' ', 0, 0, 0, 0 )
297 mnthr = ilaenv( 6, 'CGELSD', ' ', m, n, nrhs, -1 )
298 nlvl = max( int( log( real( minmn ) / real( smlsiz + 1 ) ) /
299 $ log( two ) ) + 1, 0 )
300 liwork = 3*minmn*nlvl + 11*minmn
301 mm = m
302 IF( m.GE.n .AND. m.GE.mnthr ) THEN
303*
304* Path 1a - overdetermined, with many more rows than
305* columns.
306*
307 mm = n
308 maxwrk = max( maxwrk, n*ilaenv( 1, 'CGEQRF', ' ', m, n,
309 $ -1, -1 ) )
310 maxwrk = max( maxwrk, nrhs*ilaenv( 1, 'CUNMQR', 'LC', m,
311 $ nrhs, n, -1 ) )
312 END IF
313 IF( m.GE.n ) THEN
314*
315* Path 1 - overdetermined or exactly determined.
316*
317 lrwork = 10*n + 2*n*smlsiz + 8*n*nlvl + 3*smlsiz*nrhs +
318 $ max( (smlsiz+1)**2, n*(1+nrhs) + 2*nrhs )
319 maxwrk = max( maxwrk, 2*n + ( mm + n )*ilaenv( 1,
320 $ 'CGEBRD', ' ', mm, n, -1, -1 ) )
321 maxwrk = max( maxwrk, 2*n + nrhs*ilaenv( 1, 'CUNMBR',
322 $ 'QLC', mm, nrhs, n, -1 ) )
323 maxwrk = max( maxwrk, 2*n + ( n - 1 )*ilaenv( 1,
324 $ 'CUNMBR', 'PLN', n, nrhs, n, -1 ) )
325 maxwrk = max( maxwrk, 2*n + n*nrhs )
326 minwrk = max( 2*n + mm, 2*n + n*nrhs )
327 END IF
328 IF( n.GT.m ) THEN
329 lrwork = 10*m + 2*m*smlsiz + 8*m*nlvl + 3*smlsiz*nrhs +
330 $ max( (smlsiz+1)**2, n*(1+nrhs) + 2*nrhs )
331 IF( n.GE.mnthr ) THEN
332*
333* Path 2a - underdetermined, with many more columns
334* than rows.
335*
336 maxwrk = m + m*ilaenv( 1, 'CGELQF', ' ', m, n, -1,
337 $ -1 )
338 maxwrk = max( maxwrk, m*m + 4*m + 2*m*ilaenv( 1,
339 $ 'CGEBRD', ' ', m, m, -1, -1 ) )
340 maxwrk = max( maxwrk, m*m + 4*m + nrhs*ilaenv( 1,
341 $ 'CUNMBR', 'QLC', m, nrhs, m, -1 ) )
342 maxwrk = max( maxwrk, m*m + 4*m + ( m - 1 )*ilaenv( 1,
343 $ 'CUNMLQ', 'LC', n, nrhs, m, -1 ) )
344 IF( nrhs.GT.1 ) THEN
345 maxwrk = max( maxwrk, m*m + m + m*nrhs )
346 ELSE
347 maxwrk = max( maxwrk, m*m + 2*m )
348 END IF
349 maxwrk = max( maxwrk, m*m + 4*m + m*nrhs )
350! XXX: Ensure the Path 2a case below is triggered. The workspace
351! calculation should use queries for all routines eventually.
352 maxwrk = max( maxwrk,
353 $ 4*m+m*m+max( m, 2*m-4, nrhs, n-3*m ) )
354 ELSE
355*
356* Path 2 - underdetermined.
357*
358 maxwrk = 2*m + ( n + m )*ilaenv( 1, 'CGEBRD', ' ', m,
359 $ n, -1, -1 )
360 maxwrk = max( maxwrk, 2*m + nrhs*ilaenv( 1, 'CUNMBR',
361 $ 'QLC', m, nrhs, m, -1 ) )
362 maxwrk = max( maxwrk, 2*m + m*ilaenv( 1, 'CUNMBR',
363 $ 'PLN', n, nrhs, m, -1 ) )
364 maxwrk = max( maxwrk, 2*m + m*nrhs )
365 END IF
366 minwrk = max( 2*m + n, 2*m + m*nrhs )
367 END IF
368 END IF
369 minwrk = min( minwrk, maxwrk )
370 work( 1 ) = sroundup_lwork(maxwrk)
371 iwork( 1 ) = liwork
372 rwork( 1 ) = lrwork
373*
374 IF( lwork.LT.minwrk .AND. .NOT.lquery ) THEN
375 info = -12
376 END IF
377 END IF
378*
379 IF( info.NE.0 ) THEN
380 CALL xerbla( 'CGELSD', -info )
381 RETURN
382 ELSE IF( lquery ) THEN
383 RETURN
384 END IF
385*
386* Quick return if possible.
387*
388 IF( m.EQ.0 .OR. n.EQ.0 ) THEN
389 rank = 0
390 RETURN
391 END IF
392*
393* Get machine parameters.
394*
395 eps = slamch( 'P' )
396 sfmin = slamch( 'S' )
397 smlnum = sfmin / eps
398 bignum = one / smlnum
399*
400* Scale A if max entry outside range [SMLNUM,BIGNUM].
401*
402 anrm = clange( 'M', m, n, a, lda, rwork )
403 iascl = 0
404 IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
405*
406* Scale matrix norm up to SMLNUM
407*
408 CALL clascl( 'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
409 iascl = 1
410 ELSE IF( anrm.GT.bignum ) THEN
411*
412* Scale matrix norm down to BIGNUM.
413*
414 CALL clascl( 'G', 0, 0, anrm, bignum, m, n, a, lda, info )
415 iascl = 2
416 ELSE IF( anrm.EQ.zero ) THEN
417*
418* Matrix all zero. Return zero solution.
419*
420 CALL claset( 'F', max( m, n ), nrhs, czero, czero, b, ldb )
421 CALL slaset( 'F', minmn, 1, zero, zero, s, 1 )
422 rank = 0
423 GO TO 10
424 END IF
425*
426* Scale B if max entry outside range [SMLNUM,BIGNUM].
427*
428 bnrm = clange( 'M', m, nrhs, b, ldb, rwork )
429 ibscl = 0
430 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum ) THEN
431*
432* Scale matrix norm up to SMLNUM.
433*
434 CALL clascl( 'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
435 ibscl = 1
436 ELSE IF( bnrm.GT.bignum ) THEN
437*
438* Scale matrix norm down to BIGNUM.
439*
440 CALL clascl( 'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
441 ibscl = 2
442 END IF
443*
444* If M < N make sure B(M+1:N,:) = 0
445*
446 IF( m.LT.n )
447 $ CALL claset( 'F', n-m, nrhs, czero, czero, b( m+1, 1 ), ldb )
448*
449* Overdetermined case.
450*
451 IF( m.GE.n ) THEN
452*
453* Path 1 - overdetermined or exactly determined.
454*
455 mm = m
456 IF( m.GE.mnthr ) THEN
457*
458* Path 1a - overdetermined, with many more rows than columns
459*
460 mm = n
461 itau = 1
462 nwork = itau + n
463*
464* Compute A=Q*R.
465* (RWorkspace: need N)
466* (CWorkspace: need N, prefer N*NB)
467*
468 CALL cgeqrf( m, n, a, lda, work( itau ), work( nwork ),
469 $ lwork-nwork+1, info )
470*
471* Multiply B by transpose(Q).
472* (RWorkspace: need N)
473* (CWorkspace: need NRHS, prefer NRHS*NB)
474*
475 CALL cunmqr( 'L', 'C', m, nrhs, n, a, lda, work( itau ), b,
476 $ ldb, work( nwork ), lwork-nwork+1, info )
477*
478* Zero out below R.
479*
480 IF( n.GT.1 ) THEN
481 CALL claset( 'L', n-1, n-1, czero, czero, a( 2, 1 ),
482 $ lda )
483 END IF
484 END IF
485*
486 itauq = 1
487 itaup = itauq + n
488 nwork = itaup + n
489 ie = 1
490 nrwork = ie + n
491*
492* Bidiagonalize R in A.
493* (RWorkspace: need N)
494* (CWorkspace: need 2*N+MM, prefer 2*N+(MM+N)*NB)
495*
496 CALL cgebrd( mm, n, a, lda, s, rwork( ie ), work( itauq ),
497 $ work( itaup ), work( nwork ), lwork-nwork+1,
498 $ info )
499*
500* Multiply B by transpose of left bidiagonalizing vectors of R.
501* (CWorkspace: need 2*N+NRHS, prefer 2*N+NRHS*NB)
502*
503 CALL cunmbr( 'Q', 'L', 'C', mm, nrhs, n, a, lda, work( itauq ),
504 $ b, ldb, work( nwork ), lwork-nwork+1, info )
505*
506* Solve the bidiagonal least squares problem.
507*
508 CALL clalsd( 'U', smlsiz, n, nrhs, s, rwork( ie ), b, ldb,
509 $ rcond, rank, work( nwork ), rwork( nrwork ),
510 $ iwork, info )
511 IF( info.NE.0 ) THEN
512 GO TO 10
513 END IF
514*
515* Multiply B by right bidiagonalizing vectors of R.
516*
517 CALL cunmbr( 'P', 'L', 'N', n, nrhs, n, a, lda, work( itaup ),
518 $ b, ldb, work( nwork ), lwork-nwork+1, info )
519*
520 ELSE IF( n.GE.mnthr .AND. lwork.GE.4*m+m*m+
521 $ max( m, 2*m-4, nrhs, n-3*m ) ) THEN
522*
523* Path 2a - underdetermined, with many more columns than rows
524* and sufficient workspace for an efficient algorithm.
525*
526 ldwork = m
527 IF( lwork.GE.max( 4*m+m*lda+max( m, 2*m-4, nrhs, n-3*m ),
528 $ m*lda+m+m*nrhs ) )ldwork = lda
529 itau = 1
530 nwork = m + 1
531*
532* Compute A=L*Q.
533* (CWorkspace: need 2*M, prefer M+M*NB)
534*
535 CALL cgelqf( m, n, a, lda, work( itau ), work( nwork ),
536 $ lwork-nwork+1, info )
537 il = nwork
538*
539* Copy L to WORK(IL), zeroing out above its diagonal.
540*
541 CALL clacpy( 'L', m, m, a, lda, work( il ), ldwork )
542 CALL claset( 'U', m-1, m-1, czero, czero, work( il+ldwork ),
543 $ ldwork )
544 itauq = il + ldwork*m
545 itaup = itauq + m
546 nwork = itaup + m
547 ie = 1
548 nrwork = ie + m
549*
550* Bidiagonalize L in WORK(IL).
551* (RWorkspace: need M)
552* (CWorkspace: need M*M+4*M, prefer M*M+4*M+2*M*NB)
553*
554 CALL cgebrd( m, m, work( il ), ldwork, s, rwork( ie ),
555 $ work( itauq ), work( itaup ), work( nwork ),
556 $ lwork-nwork+1, info )
557*
558* Multiply B by transpose of left bidiagonalizing vectors of L.
559* (CWorkspace: need M*M+4*M+NRHS, prefer M*M+4*M+NRHS*NB)
560*
561 CALL cunmbr( 'Q', 'L', 'C', m, nrhs, m, work( il ), ldwork,
562 $ work( itauq ), b, ldb, work( nwork ),
563 $ lwork-nwork+1, info )
564*
565* Solve the bidiagonal least squares problem.
566*
567 CALL clalsd( 'U', smlsiz, m, nrhs, s, rwork( ie ), b, ldb,
568 $ rcond, rank, work( nwork ), rwork( nrwork ),
569 $ iwork, info )
570 IF( info.NE.0 ) THEN
571 GO TO 10
572 END IF
573*
574* Multiply B by right bidiagonalizing vectors of L.
575*
576 CALL cunmbr( 'P', 'L', 'N', m, nrhs, m, work( il ), ldwork,
577 $ work( itaup ), b, ldb, work( nwork ),
578 $ lwork-nwork+1, info )
579*
580* Zero out below first M rows of B.
581*
582 CALL claset( 'F', n-m, nrhs, czero, czero, b( m+1, 1 ), ldb )
583 nwork = itau + m
584*
585* Multiply transpose(Q) by B.
586* (CWorkspace: need NRHS, prefer NRHS*NB)
587*
588 CALL cunmlq( 'L', 'C', n, nrhs, m, a, lda, work( itau ), b,
589 $ ldb, work( nwork ), lwork-nwork+1, info )
590*
591 ELSE
592*
593* Path 2 - remaining underdetermined cases.
594*
595 itauq = 1
596 itaup = itauq + m
597 nwork = itaup + m
598 ie = 1
599 nrwork = ie + m
600*
601* Bidiagonalize A.
602* (RWorkspace: need M)
603* (CWorkspace: need 2*M+N, prefer 2*M+(M+N)*NB)
604*
605 CALL cgebrd( m, n, a, lda, s, rwork( ie ), work( itauq ),
606 $ work( itaup ), work( nwork ), lwork-nwork+1,
607 $ info )
608*
609* Multiply B by transpose of left bidiagonalizing vectors.
610* (CWorkspace: need 2*M+NRHS, prefer 2*M+NRHS*NB)
611*
612 CALL cunmbr( 'Q', 'L', 'C', m, nrhs, n, a, lda, work( itauq ),
613 $ b, ldb, work( nwork ), lwork-nwork+1, info )
614*
615* Solve the bidiagonal least squares problem.
616*
617 CALL clalsd( 'L', smlsiz, m, nrhs, s, rwork( ie ), b, ldb,
618 $ rcond, rank, work( nwork ), rwork( nrwork ),
619 $ iwork, info )
620 IF( info.NE.0 ) THEN
621 GO TO 10
622 END IF
623*
624* Multiply B by right bidiagonalizing vectors of A.
625*
626 CALL cunmbr( 'P', 'L', 'N', n, nrhs, m, a, lda, work( itaup ),
627 $ b, ldb, work( nwork ), lwork-nwork+1, info )
628*
629 END IF
630*
631* Undo scaling.
632*
633 IF( iascl.EQ.1 ) THEN
634 CALL clascl( 'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
635 CALL slascl( 'G', 0, 0, smlnum, anrm, minmn, 1, s, minmn,
636 $ info )
637 ELSE IF( iascl.EQ.2 ) THEN
638 CALL clascl( 'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
639 CALL slascl( 'G', 0, 0, bignum, anrm, minmn, 1, s, minmn,
640 $ info )
641 END IF
642 IF( ibscl.EQ.1 ) THEN
643 CALL clascl( 'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
644 ELSE IF( ibscl.EQ.2 ) THEN
645 CALL clascl( 'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )
646 END IF
647*
648 10 CONTINUE
649 work( 1 ) = sroundup_lwork(maxwrk)
650 iwork( 1 ) = liwork
651 rwork( 1 ) = lrwork
652 RETURN
653*
654* End of CGELSD
655*
656 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgebrd(m, n, a, lda, d, e, tauq, taup, work, lwork, info)
CGEBRD
Definition cgebrd.f:206
subroutine cgelqf(m, n, a, lda, tau, work, lwork, info)
CGELQF
Definition cgelqf.f:143
subroutine cgelsd(m, n, nrhs, a, lda, b, ldb, s, rcond, rank, work, lwork, rwork, iwork, info)
CGELSD computes the minimum-norm solution to a linear least squares problem for GE matrices
Definition cgelsd.f:219
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
Definition cgeqrf.f:146
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
Definition clacpy.f:103
subroutine clalsd(uplo, smlsiz, n, nrhs, d, e, b, ldb, rcond, rank, work, rwork, iwork, info)
CLALSD uses the singular value decomposition of A to solve the least squares problem.
Definition clalsd.f:180
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.
Definition clascl.f:143
subroutine slascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
SLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition slascl.f:143
subroutine slaset(uplo, m, n, alpha, beta, a, lda)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition slaset.f:110
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.
Definition claset.f:106
subroutine cunmbr(vect, side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMBR
Definition cunmbr.f:197
subroutine cunmlq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMLQ
Definition cunmlq.f:168
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
Definition cunmqr.f:168