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