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 real c_b9 = 1.f;
516 static real c_b10 = 0.f;
517 static integer c__2 = 2;
519 /* > \brief \b CLALSA computes the SVD of the coefficient matrix in compact form. Used by sgelsd. */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download CLALSA + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clalsa.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clalsa.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clalsa.
542 /* SUBROUTINE CLALSA( ICOMPQ, SMLSIZ, N, NRHS, B, LDB, BX, LDBX, U, */
543 /* LDU, VT, K, DIFL, DIFR, Z, POLES, GIVPTR, */
544 /* GIVCOL, LDGCOL, PERM, GIVNUM, C, S, RWORK, */
547 /* INTEGER ICOMPQ, INFO, LDB, LDBX, LDGCOL, LDU, N, NRHS, */
549 /* INTEGER GIVCOL( LDGCOL, * ), GIVPTR( * ), IWORK( * ), */
550 /* $ K( * ), PERM( LDGCOL, * ) */
551 /* REAL C( * ), DIFL( LDU, * ), DIFR( LDU, * ), */
552 /* $ GIVNUM( LDU, * ), POLES( LDU, * ), RWORK( * ), */
553 /* $ S( * ), U( LDU, * ), VT( LDU, * ), Z( LDU, * ) */
554 /* COMPLEX B( LDB, * ), BX( LDBX, * ) */
557 /* > \par Purpose: */
562 /* > CLALSA is an itermediate step in solving the least squares problem */
563 /* > by computing the SVD of the coefficient matrix in compact form (The */
564 /* > singular vectors are computed as products of simple orthorgonal */
567 /* > If ICOMPQ = 0, CLALSA applies the inverse of the left singular vector */
568 /* > matrix of an upper bidiagonal matrix to the right hand side; and if */
569 /* > ICOMPQ = 1, CLALSA applies the right singular vector matrix to the */
570 /* > right hand side. The singular vector matrices were generated in */
571 /* > compact form by CLALSA. */
577 /* > \param[in] ICOMPQ */
579 /* > ICOMPQ is INTEGER */
580 /* > Specifies whether the left or the right singular vector */
581 /* > matrix is involved. */
582 /* > = 0: Left singular vector matrix */
583 /* > = 1: Right singular vector matrix */
586 /* > \param[in] SMLSIZ */
588 /* > SMLSIZ is INTEGER */
589 /* > The maximum size of the subproblems at the bottom of the */
590 /* > computation tree. */
596 /* > The row and column dimensions of the upper bidiagonal matrix. */
599 /* > \param[in] NRHS */
601 /* > NRHS is INTEGER */
602 /* > The number of columns of B and BX. NRHS must be at least 1. */
605 /* > \param[in,out] B */
607 /* > B is COMPLEX array, dimension ( LDB, NRHS ) */
608 /* > On input, B contains the right hand sides of the least */
609 /* > squares problem in rows 1 through M. */
610 /* > On output, B contains the solution X in rows 1 through N. */
613 /* > \param[in] LDB */
615 /* > LDB is INTEGER */
616 /* > The leading dimension of B in the calling subprogram. */
617 /* > LDB must be at least f2cmax(1,MAX( M, N ) ). */
620 /* > \param[out] BX */
622 /* > BX is COMPLEX array, dimension ( LDBX, NRHS ) */
623 /* > On exit, the result of applying the left or right singular */
624 /* > vector matrix to B. */
627 /* > \param[in] LDBX */
629 /* > LDBX is INTEGER */
630 /* > The leading dimension of BX. */
635 /* > U is REAL array, dimension ( LDU, SMLSIZ ). */
636 /* > On entry, U contains the left singular vector matrices of all */
637 /* > subproblems at the bottom level. */
640 /* > \param[in] LDU */
642 /* > LDU is INTEGER, LDU = > N. */
643 /* > The leading dimension of arrays U, VT, DIFL, DIFR, */
644 /* > POLES, GIVNUM, and Z. */
647 /* > \param[in] VT */
649 /* > VT is REAL array, dimension ( LDU, SMLSIZ+1 ). */
650 /* > On entry, VT**H contains the right singular vector matrices of */
651 /* > all subproblems at the bottom level. */
656 /* > K is INTEGER array, dimension ( N ). */
659 /* > \param[in] DIFL */
661 /* > DIFL is REAL array, dimension ( LDU, NLVL ). */
662 /* > where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1. */
665 /* > \param[in] DIFR */
667 /* > DIFR is REAL array, dimension ( LDU, 2 * NLVL ). */
668 /* > On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record */
669 /* > distances between singular values on the I-th level and */
670 /* > singular values on the (I -1)-th level, and DIFR(*, 2 * I) */
671 /* > record the normalizing factors of the right singular vectors */
672 /* > matrices of subproblems on I-th level. */
677 /* > Z is REAL array, dimension ( LDU, NLVL ). */
678 /* > On entry, Z(1, I) contains the components of the deflation- */
679 /* > adjusted updating row vector for subproblems on the I-th */
683 /* > \param[in] POLES */
685 /* > POLES is REAL array, dimension ( LDU, 2 * NLVL ). */
686 /* > On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old */
687 /* > singular values involved in the secular equations on the I-th */
691 /* > \param[in] GIVPTR */
693 /* > GIVPTR is INTEGER array, dimension ( N ). */
694 /* > On entry, GIVPTR( I ) records the number of Givens */
695 /* > rotations performed on the I-th problem on the computation */
699 /* > \param[in] GIVCOL */
701 /* > GIVCOL is INTEGER array, dimension ( LDGCOL, 2 * NLVL ). */
702 /* > On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the */
703 /* > locations of Givens rotations performed on the I-th level on */
704 /* > the computation tree. */
707 /* > \param[in] LDGCOL */
709 /* > LDGCOL is INTEGER, LDGCOL = > N. */
710 /* > The leading dimension of arrays GIVCOL and PERM. */
713 /* > \param[in] PERM */
715 /* > PERM is INTEGER array, dimension ( LDGCOL, NLVL ). */
716 /* > On entry, PERM(*, I) records permutations done on the I-th */
717 /* > level of the computation tree. */
720 /* > \param[in] GIVNUM */
722 /* > GIVNUM is REAL array, dimension ( LDU, 2 * NLVL ). */
723 /* > On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S- */
724 /* > values of Givens rotations performed on the I-th level on the */
725 /* > computation tree. */
730 /* > C is REAL array, dimension ( N ). */
731 /* > On entry, if the I-th subproblem is not square, */
732 /* > C( I ) contains the C-value of a Givens rotation related to */
733 /* > the right null space of the I-th subproblem. */
738 /* > S is REAL array, dimension ( N ). */
739 /* > On entry, if the I-th subproblem is not square, */
740 /* > S( I ) contains the S-value of a Givens rotation related to */
741 /* > the right null space of the I-th subproblem. */
744 /* > \param[out] RWORK */
746 /* > RWORK is REAL array, dimension at least */
747 /* > MAX( (SMLSZ+1)*NRHS*3, N*(1+NRHS) + 2*NRHS ). */
750 /* > \param[out] IWORK */
752 /* > IWORK is INTEGER array, dimension (3*N) */
755 /* > \param[out] INFO */
757 /* > INFO is INTEGER */
758 /* > = 0: successful exit. */
759 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
765 /* > \author Univ. of Tennessee */
766 /* > \author Univ. of California Berkeley */
767 /* > \author Univ. of Colorado Denver */
768 /* > \author NAG Ltd. */
770 /* > \date June 2017 */
772 /* > \ingroup complexOTHERcomputational */
774 /* > \par Contributors: */
775 /* ================== */
777 /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */
778 /* > California at Berkeley, USA \n */
779 /* > Osni Marques, LBNL/NERSC, USA \n */
781 /* ===================================================================== */
782 /* Subroutine */ int clalsa_(integer *icompq, integer *smlsiz, integer *n,
783 integer *nrhs, complex *b, integer *ldb, complex *bx, integer *ldbx,
784 real *u, integer *ldu, real *vt, integer *k, real *difl, real *difr,
785 real *z__, real *poles, integer *givptr, integer *givcol, integer *
786 ldgcol, integer *perm, real *givnum, real *c__, real *s, real *rwork,
787 integer *iwork, integer *info)
789 /* System generated locals */
790 integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
791 difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
792 poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
793 z_dim1, z_offset, b_dim1, b_offset, bx_dim1, bx_offset, i__1,
794 i__2, i__3, i__4, i__5, i__6;
797 /* Local variables */
798 integer jcol, nlvl, sqre, jrow, i__, j, jimag, jreal, inode, ndiml;
799 extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *,
800 integer *, real *, real *, integer *, real *, integer *, real *,
803 extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
804 complex *, integer *);
806 extern /* Subroutine */ int clals0_(integer *, integer *, integer *,
807 integer *, integer *, complex *, integer *, complex *, integer *,
808 integer *, integer *, integer *, integer *, real *, integer *,
809 real *, real *, real *, real *, integer *, real *, real *, real *,
811 integer ic, lf, nd, ll, nl, nr;
812 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), slasdt_(
813 integer *, integer *, integer *, integer *, integer *, integer *,
815 integer im1, nlf, nrf, lvl, ndb1, nlp1, lvl2, nrp1;
818 /* -- LAPACK computational routine (version 3.7.1) -- */
819 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
820 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
824 /* ===================================================================== */
827 /* Test the input parameters. */
829 /* Parameter adjustments */
831 b_offset = 1 + b_dim1 * 1;
834 bx_offset = 1 + bx_dim1 * 1;
837 givnum_offset = 1 + givnum_dim1 * 1;
838 givnum -= givnum_offset;
840 poles_offset = 1 + poles_dim1 * 1;
841 poles -= poles_offset;
843 z_offset = 1 + z_dim1 * 1;
846 difr_offset = 1 + difr_dim1 * 1;
849 difl_offset = 1 + difl_dim1 * 1;
852 vt_offset = 1 + vt_dim1 * 1;
855 u_offset = 1 + u_dim1 * 1;
860 perm_offset = 1 + perm_dim1 * 1;
862 givcol_dim1 = *ldgcol;
863 givcol_offset = 1 + givcol_dim1 * 1;
864 givcol -= givcol_offset;
873 if (*icompq < 0 || *icompq > 1) {
875 } else if (*smlsiz < 3) {
877 } else if (*n < *smlsiz) {
879 } else if (*nrhs < 1) {
881 } else if (*ldb < *n) {
883 } else if (*ldbx < *n) {
885 } else if (*ldu < *n) {
887 } else if (*ldgcol < *n) {
892 xerbla_("CLALSA", &i__1, (ftnlen)6);
896 /* Book-keeping and setting up the computation tree. */
902 slasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
905 /* The following code applies back the left singular vector factors. */
906 /* For applying back the right singular vector factors, go to 170. */
912 /* The nodes on the bottom level of the tree were solved */
913 /* by SLASDQ. The corresponding left and right singular vector */
914 /* matrices are in explicit form. First apply back the left */
915 /* singular vector matrices. */
919 for (i__ = ndb1; i__ <= i__1; ++i__) {
921 /* IC : center row of each node */
922 /* NL : number of rows of left subproblem */
923 /* NR : number of rows of right subproblem */
924 /* NLF: starting row of the left subproblem */
925 /* NRF: starting row of the right subproblem */
928 ic = iwork[inode + i1];
929 nl = iwork[ndiml + i1];
930 nr = iwork[ndimr + i1];
934 /* Since B and BX are complex, the following call to SGEMM */
935 /* is performed in two steps (real and imaginary parts). */
937 /* CALL SGEMM( 'T', 'N', NL, NRHS, NL, ONE, U( NLF, 1 ), LDU, */
938 /* $ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX ) */
942 for (jcol = 1; jcol <= i__2; ++jcol) {
944 for (jrow = nlf; jrow <= i__3; ++jrow) {
946 i__4 = jrow + jcol * b_dim1;
947 rwork[j] = b[i__4].r;
952 sgemm_("T", "N", &nl, nrhs, &nl, &c_b9, &u[nlf + u_dim1], ldu, &rwork[
953 (nl * *nrhs << 1) + 1], &nl, &c_b10, &rwork[1], &nl);
956 for (jcol = 1; jcol <= i__2; ++jcol) {
958 for (jrow = nlf; jrow <= i__3; ++jrow) {
960 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
965 sgemm_("T", "N", &nl, nrhs, &nl, &c_b9, &u[nlf + u_dim1], ldu, &rwork[
966 (nl * *nrhs << 1) + 1], &nl, &c_b10, &rwork[nl * *nrhs + 1], &
971 for (jcol = 1; jcol <= i__2; ++jcol) {
973 for (jrow = nlf; jrow <= i__3; ++jrow) {
976 i__4 = jrow + jcol * bx_dim1;
979 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
980 bx[i__4].r = q__1.r, bx[i__4].i = q__1.i;
986 /* Since B and BX are complex, the following call to SGEMM */
987 /* is performed in two steps (real and imaginary parts). */
989 /* CALL SGEMM( 'T', 'N', NR, NRHS, NR, ONE, U( NRF, 1 ), LDU, */
990 /* $ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX ) */
994 for (jcol = 1; jcol <= i__2; ++jcol) {
996 for (jrow = nrf; jrow <= i__3; ++jrow) {
998 i__4 = jrow + jcol * b_dim1;
999 rwork[j] = b[i__4].r;
1004 sgemm_("T", "N", &nr, nrhs, &nr, &c_b9, &u[nrf + u_dim1], ldu, &rwork[
1005 (nr * *nrhs << 1) + 1], &nr, &c_b10, &rwork[1], &nr);
1006 j = nr * *nrhs << 1;
1008 for (jcol = 1; jcol <= i__2; ++jcol) {
1009 i__3 = nrf + nr - 1;
1010 for (jrow = nrf; jrow <= i__3; ++jrow) {
1012 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
1017 sgemm_("T", "N", &nr, nrhs, &nr, &c_b9, &u[nrf + u_dim1], ldu, &rwork[
1018 (nr * *nrhs << 1) + 1], &nr, &c_b10, &rwork[nr * *nrhs + 1], &
1023 for (jcol = 1; jcol <= i__2; ++jcol) {
1024 i__3 = nrf + nr - 1;
1025 for (jrow = nrf; jrow <= i__3; ++jrow) {
1028 i__4 = jrow + jcol * bx_dim1;
1031 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
1032 bx[i__4].r = q__1.r, bx[i__4].i = q__1.i;
1041 /* Next copy the rows of B that correspond to unchanged rows */
1042 /* in the bidiagonal matrix to BX. */
1045 for (i__ = 1; i__ <= i__1; ++i__) {
1046 ic = iwork[inode + i__ - 1];
1047 ccopy_(nrhs, &b[ic + b_dim1], ldb, &bx[ic + bx_dim1], ldbx);
1051 /* Finally go through the left singular vector matrices of all */
1052 /* the other subproblems bottom-up on the tree. */
1054 j = pow_ii(&c__2, &nlvl);
1057 for (lvl = nlvl; lvl >= 1; --lvl) {
1058 lvl2 = (lvl << 1) - 1;
1060 /* find the first node LF and last node LL on */
1061 /* the current level LVL */
1068 lf = pow_ii(&c__2, &i__1);
1072 for (i__ = lf; i__ <= i__1; ++i__) {
1074 ic = iwork[inode + im1];
1075 nl = iwork[ndiml + im1];
1076 nr = iwork[ndimr + im1];
1080 clals0_(icompq, &nl, &nr, &sqre, nrhs, &bx[nlf + bx_dim1], ldbx, &
1081 b[nlf + b_dim1], ldb, &perm[nlf + lvl * perm_dim1], &
1082 givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
1083 givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
1084 poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
1085 lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
1086 j], &s[j], &rwork[1], info);
1093 /* ICOMPQ = 1: applying back the right singular vector factors. */
1097 /* First now go through the right singular vector matrices of all */
1098 /* the tree nodes top-down. */
1102 for (lvl = 1; lvl <= i__1; ++lvl) {
1103 lvl2 = (lvl << 1) - 1;
1105 /* Find the first node LF and last node LL on */
1106 /* the current level LVL. */
1113 lf = pow_ii(&c__2, &i__2);
1117 for (i__ = ll; i__ >= i__2; --i__) {
1119 ic = iwork[inode + im1];
1120 nl = iwork[ndiml + im1];
1121 nr = iwork[ndimr + im1];
1130 clals0_(icompq, &nl, &nr, &sqre, nrhs, &b[nlf + b_dim1], ldb, &bx[
1131 nlf + bx_dim1], ldbx, &perm[nlf + lvl * perm_dim1], &
1132 givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
1133 givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
1134 poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
1135 lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
1136 j], &s[j], &rwork[1], info);
1142 /* The nodes on the bottom level of the tree were solved */
1143 /* by SLASDQ. The corresponding right singular vector */
1144 /* matrices are in explicit form. Apply them back. */
1146 ndb1 = (nd + 1) / 2;
1148 for (i__ = ndb1; i__ <= i__1; ++i__) {
1150 ic = iwork[inode + i1];
1151 nl = iwork[ndiml + i1];
1152 nr = iwork[ndimr + i1];
1162 /* Since B and BX are complex, the following call to SGEMM is */
1163 /* performed in two steps (real and imaginary parts). */
1165 /* CALL SGEMM( 'T', 'N', NLP1, NRHS, NLP1, ONE, VT( NLF, 1 ), LDU, */
1166 /* $ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX ) */
1168 j = nlp1 * *nrhs << 1;
1170 for (jcol = 1; jcol <= i__2; ++jcol) {
1171 i__3 = nlf + nlp1 - 1;
1172 for (jrow = nlf; jrow <= i__3; ++jrow) {
1174 i__4 = jrow + jcol * b_dim1;
1175 rwork[j] = b[i__4].r;
1180 sgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b9, &vt[nlf + vt_dim1], ldu, &
1181 rwork[(nlp1 * *nrhs << 1) + 1], &nlp1, &c_b10, &rwork[1], &
1183 j = nlp1 * *nrhs << 1;
1185 for (jcol = 1; jcol <= i__2; ++jcol) {
1186 i__3 = nlf + nlp1 - 1;
1187 for (jrow = nlf; jrow <= i__3; ++jrow) {
1189 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
1194 sgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b9, &vt[nlf + vt_dim1], ldu, &
1195 rwork[(nlp1 * *nrhs << 1) + 1], &nlp1, &c_b10, &rwork[nlp1 * *
1198 jimag = nlp1 * *nrhs;
1200 for (jcol = 1; jcol <= i__2; ++jcol) {
1201 i__3 = nlf + nlp1 - 1;
1202 for (jrow = nlf; jrow <= i__3; ++jrow) {
1205 i__4 = jrow + jcol * bx_dim1;
1208 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
1209 bx[i__4].r = q__1.r, bx[i__4].i = q__1.i;
1215 /* Since B and BX are complex, the following call to SGEMM is */
1216 /* performed in two steps (real and imaginary parts). */
1218 /* CALL SGEMM( 'T', 'N', NRP1, NRHS, NRP1, ONE, VT( NRF, 1 ), LDU, */
1219 /* $ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX ) */
1221 j = nrp1 * *nrhs << 1;
1223 for (jcol = 1; jcol <= i__2; ++jcol) {
1224 i__3 = nrf + nrp1 - 1;
1225 for (jrow = nrf; jrow <= i__3; ++jrow) {
1227 i__4 = jrow + jcol * b_dim1;
1228 rwork[j] = b[i__4].r;
1233 sgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b9, &vt[nrf + vt_dim1], ldu, &
1234 rwork[(nrp1 * *nrhs << 1) + 1], &nrp1, &c_b10, &rwork[1], &
1236 j = nrp1 * *nrhs << 1;
1238 for (jcol = 1; jcol <= i__2; ++jcol) {
1239 i__3 = nrf + nrp1 - 1;
1240 for (jrow = nrf; jrow <= i__3; ++jrow) {
1242 rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
1247 sgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b9, &vt[nrf + vt_dim1], ldu, &
1248 rwork[(nrp1 * *nrhs << 1) + 1], &nrp1, &c_b10, &rwork[nrp1 * *
1251 jimag = nrp1 * *nrhs;
1253 for (jcol = 1; jcol <= i__2; ++jcol) {
1254 i__3 = nrf + nrp1 - 1;
1255 for (jrow = nrf; jrow <= i__3; ++jrow) {
1258 i__4 = jrow + jcol * bx_dim1;
1261 q__1.r = rwork[i__5], q__1.i = rwork[i__6];
1262 bx[i__4].r = q__1.r, bx[i__4].i = q__1.i;