14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static complex c_b1 = {0.f,0.f};
516 static integer c__1 = 1;
517 static integer c__0 = 0;
518 static real c_b10 = 1.f;
519 static real c_b35 = 0.f;
521 /* > \brief \b CLALSD uses the singular value decomposition of A to solve the least squares problem. */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download CLALSD + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clalsd.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clalsd.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clalsd.
544 /* SUBROUTINE CLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND, */
545 /* RANK, WORK, RWORK, IWORK, INFO ) */
548 /* INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ */
550 /* INTEGER IWORK( * ) */
551 /* REAL D( * ), E( * ), RWORK( * ) */
552 /* COMPLEX B( LDB, * ), WORK( * ) */
555 /* > \par Purpose: */
560 /* > CLALSD uses the singular value decomposition of A to solve the least */
561 /* > squares problem of finding X to minimize the Euclidean norm of each */
562 /* > column of A*X-B, where A is N-by-N upper bidiagonal, and X and B */
563 /* > are N-by-NRHS. The solution X overwrites B. */
565 /* > The singular values of A smaller than RCOND times the largest */
566 /* > singular value are treated as zero in solving the least squares */
567 /* > problem; in this case a minimum norm solution is returned. */
568 /* > The actual singular values are returned in D in ascending order. */
570 /* > This code makes very mild assumptions about floating point */
571 /* > arithmetic. It will work on machines with a guard digit in */
572 /* > add/subtract, or on those binary machines without guard digits */
573 /* > which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
574 /* > It could conceivably fail on hexadecimal or decimal machines */
575 /* > without guard digits, but we know of none. */
581 /* > \param[in] UPLO */
583 /* > UPLO is CHARACTER*1 */
584 /* > = 'U': D and E define an upper bidiagonal matrix. */
585 /* > = 'L': D and E define a lower bidiagonal matrix. */
588 /* > \param[in] SMLSIZ */
590 /* > SMLSIZ is INTEGER */
591 /* > The maximum size of the subproblems at the bottom of the */
592 /* > computation tree. */
598 /* > The dimension of the bidiagonal matrix. N >= 0. */
601 /* > \param[in] NRHS */
603 /* > NRHS is INTEGER */
604 /* > The number of columns of B. NRHS must be at least 1. */
607 /* > \param[in,out] D */
609 /* > D is REAL array, dimension (N) */
610 /* > On entry D contains the main diagonal of the bidiagonal */
611 /* > matrix. On exit, if INFO = 0, D contains its singular values. */
614 /* > \param[in,out] E */
616 /* > E is REAL array, dimension (N-1) */
617 /* > Contains the super-diagonal entries of the bidiagonal matrix. */
618 /* > On exit, E has been destroyed. */
621 /* > \param[in,out] B */
623 /* > B is COMPLEX array, dimension (LDB,NRHS) */
624 /* > On input, B contains the right hand sides of the least */
625 /* > squares problem. On output, B contains the solution X. */
628 /* > \param[in] LDB */
630 /* > LDB is INTEGER */
631 /* > The leading dimension of B in the calling subprogram. */
632 /* > LDB must be at least f2cmax(1,N). */
635 /* > \param[in] RCOND */
637 /* > RCOND is REAL */
638 /* > The singular values of A less than or equal to RCOND times */
639 /* > the largest singular value are treated as zero in solving */
640 /* > the least squares problem. If RCOND is negative, */
641 /* > machine precision is used instead. */
642 /* > For example, if diag(S)*X=B were the least squares problem, */
643 /* > where diag(S) is a diagonal matrix of singular values, the */
644 /* > solution would be X(i) = B(i) / S(i) if S(i) is greater than */
645 /* > RCOND*f2cmax(S), and X(i) = 0 if S(i) is less than or equal to */
646 /* > RCOND*f2cmax(S). */
649 /* > \param[out] RANK */
651 /* > RANK is INTEGER */
652 /* > The number of singular values of A greater than RCOND times */
653 /* > the largest singular value. */
656 /* > \param[out] WORK */
658 /* > WORK is COMPLEX array, dimension (N * NRHS). */
661 /* > \param[out] RWORK */
663 /* > RWORK is REAL array, dimension at least */
664 /* > (9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + */
665 /* > MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS ), */
667 /* > NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
670 /* > \param[out] IWORK */
672 /* > IWORK is INTEGER array, dimension (3*N*NLVL + 11*N). */
675 /* > \param[out] INFO */
677 /* > INFO is INTEGER */
678 /* > = 0: successful exit. */
679 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
680 /* > > 0: The algorithm failed to compute a singular value while */
681 /* > working on the submatrix lying in rows and columns */
682 /* > INFO/(N+1) through MOD(INFO,N+1). */
688 /* > \author Univ. of Tennessee */
689 /* > \author Univ. of California Berkeley */
690 /* > \author Univ. of Colorado Denver */
691 /* > \author NAG Ltd. */
693 /* > \date December 2016 */
695 /* > \ingroup complexOTHERcomputational */
697 /* > \par Contributors: */
698 /* ================== */
700 /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */
701 /* > California at Berkeley, USA \n */
702 /* > Osni Marques, LBNL/NERSC, USA \n */
704 /* ===================================================================== */
705 /* Subroutine */ int clalsd_(char *uplo, integer *smlsiz, integer *n, integer
706 *nrhs, real *d__, real *e, complex *b, integer *ldb, real *rcond,
707 integer *rank, complex *work, real *rwork, integer *iwork, integer *
710 /* System generated locals */
711 integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6;
715 /* Local variables */
718 integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu, c__, i__, j,
721 integer s, u, jimag, z__, jreal;
722 extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *,
723 integer *, real *, real *, integer *, real *, integer *, real *,
726 extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
727 complex *, integer *);
728 integer poles, sizei, irwrb, nsize;
729 extern /* Subroutine */ int csrot_(integer *, complex *, integer *,
730 complex *, integer *, real *, real *);
731 integer irwvt, icmpq1, icmpq2;
734 extern /* Subroutine */ int clalsa_(integer *, integer *, integer *,
735 integer *, complex *, integer *, complex *, integer *, real *,
736 integer *, real *, integer *, real *, real *, real *, real *,
737 integer *, integer *, integer *, integer *, real *, real *, real *
738 , real *, integer *, integer *);
740 extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *,
741 real *, integer *, integer *, complex *, integer *, integer *);
743 extern real slamch_(char *);
744 extern /* Subroutine */ int slasda_(integer *, integer *, integer *,
745 integer *, real *, real *, real *, integer *, real *, integer *,
746 real *, real *, real *, real *, integer *, integer *, integer *,
747 integer *, real *, real *, real *, real *, integer *, integer *);
749 extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex
750 *, integer *, complex *, integer *), claset_(char *,
751 integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *, ftnlen), slascl_(char *,
752 integer *, integer *, real *, real *, integer *, integer *, real *
753 , integer *, integer *);
754 extern integer isamax_(integer *, real *, integer *);
756 extern /* Subroutine */ int slasdq_(char *, integer *, integer *, integer
757 *, integer *, integer *, real *, real *, real *, integer *, real *
758 , integer *, real *, integer *, real *, integer *),
759 slaset_(char *, integer *, integer *, real *, real *, real *,
760 integer *), slartg_(real *, real *, real *, real *, real *
764 extern real slanst_(char *, integer *, real *, real *);
765 extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *);
766 integer givptr, nm1, nrwork, irwwrk, smlszp, st1;
772 /* -- LAPACK computational routine (version 3.7.0) -- */
773 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
774 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
778 /* ===================================================================== */
781 /* Test the input parameters. */
783 /* Parameter adjustments */
787 b_offset = 1 + b_dim1 * 1;
798 } else if (*nrhs < 1) {
800 } else if (*ldb < 1 || *ldb < *n) {
805 xerbla_("CLALSD", &i__1, (ftnlen)6);
809 eps = slamch_("Epsilon");
811 /* Set up the tolerance. */
813 if (*rcond <= 0.f || *rcond >= 1.f) {
821 /* Quick return if possible. */
825 } else if (*n == 1) {
827 claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
830 clascl_("G", &c__0, &c__0, &d__[1], &c_b10, &c__1, nrhs, &b[
831 b_offset], ldb, info);
832 d__[1] = abs(d__[1]);
837 /* Rotate the matrix if it is lower bidiagonal. */
839 if (*(unsigned char *)uplo == 'L') {
841 for (i__ = 1; i__ <= i__1; ++i__) {
842 slartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
844 e[i__] = sn * d__[i__ + 1];
845 d__[i__ + 1] = cs * d__[i__ + 1];
847 csrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
850 rwork[(i__ << 1) - 1] = cs;
857 for (i__ = 1; i__ <= i__1; ++i__) {
859 for (j = 1; j <= i__2; ++j) {
860 cs = rwork[(j << 1) - 1];
862 csrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__
863 * b_dim1], &c__1, &cs, &sn);
874 orgnrm = slanst_("M", n, &d__[1], &e[1]);
876 claset_("A", n, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
880 slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, &c__1, &d__[1], n, info);
881 slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, &nm1, &c__1, &e[1], &nm1,
884 /* If N is smaller than the minimum divide size SMLSIZ, then solve */
885 /* the problem with another solver. */
889 irwvt = irwu + *n * *n;
890 irwwrk = irwvt + *n * *n;
892 irwib = irwrb + *n * *nrhs;
893 irwb = irwib + *n * *nrhs;
894 slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwu], n);
895 slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwvt], n);
896 slasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n,
897 &rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info);
902 /* In the real version, B is passed to SLASDQ and multiplied */
903 /* internally by Q**H. Here B is complex and that product is */
904 /* computed below in two steps (real and imaginary parts). */
908 for (jcol = 1; jcol <= i__1; ++jcol) {
910 for (jrow = 1; jrow <= i__2; ++jrow) {
912 i__3 = jrow + jcol * b_dim1;
913 rwork[j] = b[i__3].r;
918 sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n,
919 &c_b35, &rwork[irwrb], n);
922 for (jcol = 1; jcol <= i__1; ++jcol) {
924 for (jrow = 1; jrow <= i__2; ++jrow) {
926 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
931 sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n,
932 &c_b35, &rwork[irwib], n);
936 for (jcol = 1; jcol <= i__1; ++jcol) {
938 for (jrow = 1; jrow <= i__2; ++jrow) {
941 i__3 = jrow + jcol * b_dim1;
944 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
945 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
951 tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1));
953 for (i__ = 1; i__ <= i__1; ++i__) {
954 if (d__[i__] <= tol) {
955 claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb);
957 clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &b[
958 i__ + b_dim1], ldb, info);
964 /* Since B is complex, the following call to SGEMM is performed */
965 /* in two steps (real and imaginary parts). That is for V * B */
966 /* (in the real version of the code V**H is stored in WORK). */
968 /* CALL SGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, */
969 /* $ WORK( NWORK ), N ) */
973 for (jcol = 1; jcol <= i__1; ++jcol) {
975 for (jrow = 1; jrow <= i__2; ++jrow) {
977 i__3 = jrow + jcol * b_dim1;
978 rwork[j] = b[i__3].r;
983 sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb],
984 n, &c_b35, &rwork[irwrb], n);
987 for (jcol = 1; jcol <= i__1; ++jcol) {
989 for (jrow = 1; jrow <= i__2; ++jrow) {
991 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
996 sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb],
997 n, &c_b35, &rwork[irwib], n);
1001 for (jcol = 1; jcol <= i__1; ++jcol) {
1003 for (jrow = 1; jrow <= i__2; ++jrow) {
1006 i__3 = jrow + jcol * b_dim1;
1009 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
1010 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
1018 slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n,
1020 slasrt_("D", n, &d__[1], info);
1021 clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset],
1027 /* Book-keeping and setting up some constants. */
1029 nlvl = (integer) (log((real) (*n) / (real) (*smlsiz + 1)) / log(2.f)) + 1;
1031 smlszp = *smlsiz + 1;
1034 vt = *smlsiz * *n + 1;
1035 difl = vt + smlszp * *n;
1036 difr = difl + nlvl * *n;
1037 z__ = difr + (nlvl * *n << 1);
1038 c__ = z__ + nlvl * *n;
1041 givnum = poles + (nlvl << 1) * *n;
1042 nrwork = givnum + (nlvl << 1) * *n;
1046 irwib = irwrb + *smlsiz * *nrhs;
1047 irwb = irwib + *smlsiz * *nrhs;
1053 givcol = perm + nlvl * *n;
1054 iwk = givcol + (nlvl * *n << 1);
1063 for (i__ = 1; i__ <= i__1; ++i__) {
1064 if ((r__1 = d__[i__], abs(r__1)) < eps) {
1065 d__[i__] = r_sign(&eps, &d__[i__]);
1071 for (i__ = 1; i__ <= i__1; ++i__) {
1072 if ((r__1 = e[i__], abs(r__1)) < eps || i__ == nm1) {
1076 /* Subproblem found. First determine its size and then */
1077 /* apply divide and conquer on it. */
1081 /* A subproblem with E(I) small for I < NM1. */
1083 nsize = i__ - st + 1;
1084 iwork[sizei + nsub - 1] = nsize;
1085 } else if ((r__1 = e[i__], abs(r__1)) >= eps) {
1087 /* A subproblem with E(NM1) not too small but I = NM1. */
1089 nsize = *n - st + 1;
1090 iwork[sizei + nsub - 1] = nsize;
1093 /* A subproblem with E(NM1) small. This implies an */
1094 /* 1-by-1 subproblem at D(N), which is not solved */
1097 nsize = i__ - st + 1;
1098 iwork[sizei + nsub - 1] = nsize;
1101 iwork[sizei + nsub - 1] = 1;
1102 ccopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
1107 /* This is a 1-by-1 subproblem and is not solved */
1110 ccopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
1111 } else if (nsize <= *smlsiz) {
1113 /* This is a small subproblem and is solved by SLASDQ. */
1115 slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[vt + st1],
1117 slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[u + st1],
1119 slasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], &
1120 e[st], &rwork[vt + st1], n, &rwork[u + st1], n, &
1121 rwork[nrwork], &c__1, &rwork[nrwork], info)
1127 /* In the real version, B is passed to SLASDQ and multiplied */
1128 /* internally by Q**H. Here B is complex and that product is */
1129 /* computed below in two steps (real and imaginary parts). */
1133 for (jcol = 1; jcol <= i__2; ++jcol) {
1134 i__3 = st + nsize - 1;
1135 for (jrow = st; jrow <= i__3; ++jrow) {
1137 i__4 = jrow + jcol * b_dim1;
1138 rwork[j] = b[i__4].r;
1143 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
1144 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &
1148 for (jcol = 1; jcol <= i__2; ++jcol) {
1149 i__3 = st + nsize - 1;
1150 for (jrow = st; jrow <= i__3; ++jrow) {
1152 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
1157 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
1158 , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &
1163 for (jcol = 1; jcol <= i__2; ++jcol) {
1164 i__3 = st + nsize - 1;
1165 for (jrow = st; jrow <= i__3; ++jrow) {
1168 i__4 = jrow + jcol * b_dim1;
1171 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
1172 b[i__4].r = q__1.r, b[i__4].i = q__1.i;
1178 clacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx +
1182 /* A large problem. Solve it using divide and conquer. */
1184 slasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
1185 rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1],
1186 &rwork[difl + st1], &rwork[difr + st1], &rwork[z__ +
1187 st1], &rwork[poles + st1], &iwork[givptr + st1], &
1188 iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
1189 givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &
1190 rwork[nrwork], &iwork[iwk], info);
1195 clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
1196 work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], &
1197 iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1]
1198 , &rwork[z__ + st1], &rwork[poles + st1], &iwork[
1199 givptr + st1], &iwork[givcol + st1], n, &iwork[perm +
1200 st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[
1201 s + st1], &rwork[nrwork], &iwork[iwk], info);
1211 /* Apply the singular values and treat the tiny ones as zero. */
1213 tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1));
1216 for (i__ = 1; i__ <= i__1; ++i__) {
1218 /* Some of the elements in D can be negative because 1-by-1 */
1219 /* subproblems were not solved explicitly. */
1221 if ((r__1 = d__[i__], abs(r__1)) <= tol) {
1222 claset_("A", &c__1, nrhs, &c_b1, &c_b1, &work[bx + i__ - 1], n);
1225 clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &work[
1226 bx + i__ - 1], n, info);
1228 d__[i__] = (r__1 = d__[i__], abs(r__1));
1232 /* Now apply back the right singular vectors. */
1236 for (i__ = 1; i__ <= i__1; ++i__) {
1239 nsize = iwork[sizei + i__ - 1];
1242 ccopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
1243 } else if (nsize <= *smlsiz) {
1245 /* Since B and BX are complex, the following call to SGEMM */
1246 /* is performed in two steps (real and imaginary parts). */
1248 /* CALL SGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, */
1249 /* $ RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO, */
1250 /* $ B( ST, 1 ), LDB ) */
1255 for (jcol = 1; jcol <= i__2; ++jcol) {
1258 for (jrow = 1; jrow <= i__3; ++jrow) {
1261 rwork[jreal] = work[i__4].r;
1266 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1],
1267 n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &nsize);
1271 for (jcol = 1; jcol <= i__2; ++jcol) {
1274 for (jrow = 1; jrow <= i__3; ++jrow) {
1276 rwork[jimag] = r_imag(&work[j + jrow]);
1281 sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1],
1282 n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &nsize);
1286 for (jcol = 1; jcol <= i__2; ++jcol) {
1287 i__3 = st + nsize - 1;
1288 for (jrow = st; jrow <= i__3; ++jrow) {
1291 i__4 = jrow + jcol * b_dim1;
1294 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
1295 b[i__4].r = q__1.r, b[i__4].i = q__1.i;
1301 clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st +
1302 b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], &
1303 iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &
1304 rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr +
1305 st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
1306 givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[
1307 nrwork], &iwork[iwk], info);
1315 /* Unscale and sort the singular values. */
1317 slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info);
1318 slasrt_("D", n, &d__[1], info);
1319 clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb,