You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cggsvp.c 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #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]);}
  172. #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]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. #define z_abs(z) (cabs(Cd(z)))
  229. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  230. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  231. #define myexit_() break;
  232. #define mycycle() continue;
  233. #define myceiling(w) {ceil(w)}
  234. #define myhuge(w) {HUGE_VAL}
  235. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  236. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  237. /* procedure parameter types for -A and -C++ */
  238. /* -- translated by f2c (version 20000121).
  239. You must link the resulting object file with the libraries:
  240. -lf2c -lm (in that order)
  241. */
  242. /* Table of constant values */
  243. static complex c_b1 = {0.f,0.f};
  244. static complex c_b2 = {1.f,0.f};
  245. /* > \brief \b CGGSVP */
  246. /* =========== DOCUMENTATION =========== */
  247. /* Online html documentation available at */
  248. /* http://www.netlib.org/lapack/explore-html/ */
  249. /* > \htmlonly */
  250. /* > Download CGGSVP + dependencies */
  251. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggsvp.
  252. f"> */
  253. /* > [TGZ]</a> */
  254. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggsvp.
  255. f"> */
  256. /* > [ZIP]</a> */
  257. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggsvp.
  258. f"> */
  259. /* > [TXT]</a> */
  260. /* > \endhtmlonly */
  261. /* Definition: */
  262. /* =========== */
  263. /* SUBROUTINE CGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, */
  264. /* TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ, */
  265. /* IWORK, RWORK, TAU, WORK, INFO ) */
  266. /* CHARACTER JOBQ, JOBU, JOBV */
  267. /* INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P */
  268. /* REAL TOLA, TOLB */
  269. /* INTEGER IWORK( * ) */
  270. /* REAL RWORK( * ) */
  271. /* COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  272. /* $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
  273. /* > \par Purpose: */
  274. /* ============= */
  275. /* > */
  276. /* > \verbatim */
  277. /* > */
  278. /* > This routine is deprecated and has been replaced by routine CGGSVP3. */
  279. /* > */
  280. /* > CGGSVP computes unitary matrices U, V and Q such that */
  281. /* > */
  282. /* > N-K-L K L */
  283. /* > U**H*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0; */
  284. /* > L ( 0 0 A23 ) */
  285. /* > M-K-L ( 0 0 0 ) */
  286. /* > */
  287. /* > N-K-L K L */
  288. /* > = K ( 0 A12 A13 ) if M-K-L < 0; */
  289. /* > M-K ( 0 0 A23 ) */
  290. /* > */
  291. /* > N-K-L K L */
  292. /* > V**H*B*Q = L ( 0 0 B13 ) */
  293. /* > P-L ( 0 0 0 ) */
  294. /* > */
  295. /* > where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
  296. /* > upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
  297. /* > otherwise A23 is (M-K)-by-L upper trapezoidal. K+L = the effective */
  298. /* > numerical rank of the (M+P)-by-N matrix (A**H,B**H)**H. */
  299. /* > */
  300. /* > This decomposition is the preprocessing step for computing the */
  301. /* > Generalized Singular Value Decomposition (GSVD), see subroutine */
  302. /* > CGGSVD. */
  303. /* > \endverbatim */
  304. /* Arguments: */
  305. /* ========== */
  306. /* > \param[in] JOBU */
  307. /* > \verbatim */
  308. /* > JOBU is CHARACTER*1 */
  309. /* > = 'U': Unitary matrix U is computed; */
  310. /* > = 'N': U is not computed. */
  311. /* > \endverbatim */
  312. /* > */
  313. /* > \param[in] JOBV */
  314. /* > \verbatim */
  315. /* > JOBV is CHARACTER*1 */
  316. /* > = 'V': Unitary matrix V is computed; */
  317. /* > = 'N': V is not computed. */
  318. /* > \endverbatim */
  319. /* > */
  320. /* > \param[in] JOBQ */
  321. /* > \verbatim */
  322. /* > JOBQ is CHARACTER*1 */
  323. /* > = 'Q': Unitary matrix Q is computed; */
  324. /* > = 'N': Q is not computed. */
  325. /* > \endverbatim */
  326. /* > */
  327. /* > \param[in] M */
  328. /* > \verbatim */
  329. /* > M is INTEGER */
  330. /* > The number of rows of the matrix A. M >= 0. */
  331. /* > \endverbatim */
  332. /* > */
  333. /* > \param[in] P */
  334. /* > \verbatim */
  335. /* > P is INTEGER */
  336. /* > The number of rows of the matrix B. P >= 0. */
  337. /* > \endverbatim */
  338. /* > */
  339. /* > \param[in] N */
  340. /* > \verbatim */
  341. /* > N is INTEGER */
  342. /* > The number of columns of the matrices A and B. N >= 0. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in,out] A */
  346. /* > \verbatim */
  347. /* > A is COMPLEX array, dimension (LDA,N) */
  348. /* > On entry, the M-by-N matrix A. */
  349. /* > On exit, A contains the triangular (or trapezoidal) matrix */
  350. /* > described in the Purpose section. */
  351. /* > \endverbatim */
  352. /* > */
  353. /* > \param[in] LDA */
  354. /* > \verbatim */
  355. /* > LDA is INTEGER */
  356. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  357. /* > \endverbatim */
  358. /* > */
  359. /* > \param[in,out] B */
  360. /* > \verbatim */
  361. /* > B is COMPLEX array, dimension (LDB,N) */
  362. /* > On entry, the P-by-N matrix B. */
  363. /* > On exit, B contains the triangular matrix described in */
  364. /* > the Purpose section. */
  365. /* > \endverbatim */
  366. /* > */
  367. /* > \param[in] LDB */
  368. /* > \verbatim */
  369. /* > LDB is INTEGER */
  370. /* > The leading dimension of the array B. LDB >= f2cmax(1,P). */
  371. /* > \endverbatim */
  372. /* > */
  373. /* > \param[in] TOLA */
  374. /* > \verbatim */
  375. /* > TOLA is REAL */
  376. /* > \endverbatim */
  377. /* > */
  378. /* > \param[in] TOLB */
  379. /* > \verbatim */
  380. /* > TOLB is REAL */
  381. /* > */
  382. /* > TOLA and TOLB are the thresholds to determine the effective */
  383. /* > numerical rank of matrix B and a subblock of A. Generally, */
  384. /* > they are set to */
  385. /* > TOLA = MAX(M,N)*norm(A)*MACHEPS, */
  386. /* > TOLB = MAX(P,N)*norm(B)*MACHEPS. */
  387. /* > The size of TOLA and TOLB may affect the size of backward */
  388. /* > errors of the decomposition. */
  389. /* > \endverbatim */
  390. /* > */
  391. /* > \param[out] K */
  392. /* > \verbatim */
  393. /* > K is INTEGER */
  394. /* > \endverbatim */
  395. /* > */
  396. /* > \param[out] L */
  397. /* > \verbatim */
  398. /* > L is INTEGER */
  399. /* > */
  400. /* > On exit, K and L specify the dimension of the subblocks */
  401. /* > described in Purpose section. */
  402. /* > K + L = effective numerical rank of (A**H,B**H)**H. */
  403. /* > \endverbatim */
  404. /* > */
  405. /* > \param[out] U */
  406. /* > \verbatim */
  407. /* > U is COMPLEX array, dimension (LDU,M) */
  408. /* > If JOBU = 'U', U contains the unitary matrix U. */
  409. /* > If JOBU = 'N', U is not referenced. */
  410. /* > \endverbatim */
  411. /* > */
  412. /* > \param[in] LDU */
  413. /* > \verbatim */
  414. /* > LDU is INTEGER */
  415. /* > The leading dimension of the array U. LDU >= f2cmax(1,M) if */
  416. /* > JOBU = 'U'; LDU >= 1 otherwise. */
  417. /* > \endverbatim */
  418. /* > */
  419. /* > \param[out] V */
  420. /* > \verbatim */
  421. /* > V is COMPLEX array, dimension (LDV,P) */
  422. /* > If JOBV = 'V', V contains the unitary matrix V. */
  423. /* > If JOBV = 'N', V is not referenced. */
  424. /* > \endverbatim */
  425. /* > */
  426. /* > \param[in] LDV */
  427. /* > \verbatim */
  428. /* > LDV is INTEGER */
  429. /* > The leading dimension of the array V. LDV >= f2cmax(1,P) if */
  430. /* > JOBV = 'V'; LDV >= 1 otherwise. */
  431. /* > \endverbatim */
  432. /* > */
  433. /* > \param[out] Q */
  434. /* > \verbatim */
  435. /* > Q is COMPLEX array, dimension (LDQ,N) */
  436. /* > If JOBQ = 'Q', Q contains the unitary matrix Q. */
  437. /* > If JOBQ = 'N', Q is not referenced. */
  438. /* > \endverbatim */
  439. /* > */
  440. /* > \param[in] LDQ */
  441. /* > \verbatim */
  442. /* > LDQ is INTEGER */
  443. /* > The leading dimension of the array Q. LDQ >= f2cmax(1,N) if */
  444. /* > JOBQ = 'Q'; LDQ >= 1 otherwise. */
  445. /* > \endverbatim */
  446. /* > */
  447. /* > \param[out] IWORK */
  448. /* > \verbatim */
  449. /* > IWORK is INTEGER array, dimension (N) */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[out] RWORK */
  453. /* > \verbatim */
  454. /* > RWORK is REAL array, dimension (2*N) */
  455. /* > \endverbatim */
  456. /* > */
  457. /* > \param[out] TAU */
  458. /* > \verbatim */
  459. /* > TAU is COMPLEX array, dimension (N) */
  460. /* > \endverbatim */
  461. /* > */
  462. /* > \param[out] WORK */
  463. /* > \verbatim */
  464. /* > WORK is COMPLEX array, dimension (f2cmax(3*N,M,P)) */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[out] INFO */
  468. /* > \verbatim */
  469. /* > INFO is INTEGER */
  470. /* > = 0: successful exit */
  471. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  472. /* > \endverbatim */
  473. /* Authors: */
  474. /* ======== */
  475. /* > \author Univ. of Tennessee */
  476. /* > \author Univ. of California Berkeley */
  477. /* > \author Univ. of Colorado Denver */
  478. /* > \author NAG Ltd. */
  479. /* > \date December 2016 */
  480. /* > \ingroup complexOTHERcomputational */
  481. /* > \par Further Details: */
  482. /* ===================== */
  483. /* > */
  484. /* > The subroutine uses LAPACK subroutine CGEQPF for the QR factorization */
  485. /* > with column pivoting to detect the effective numerical rank of the */
  486. /* > a matrix. It may be replaced by a better rank determination strategy. */
  487. /* > */
  488. /* ===================================================================== */
  489. /* Subroutine */ void cggsvp_(char *jobu, char *jobv, char *jobq, integer *m,
  490. integer *p, integer *n, complex *a, integer *lda, complex *b, integer
  491. *ldb, real *tola, real *tolb, integer *k, integer *l, complex *u,
  492. integer *ldu, complex *v, integer *ldv, complex *q, integer *ldq,
  493. integer *iwork, real *rwork, complex *tau, complex *work, integer *
  494. info)
  495. {
  496. /* System generated locals */
  497. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
  498. u_offset, v_dim1, v_offset, i__1, i__2, i__3;
  499. real r__1, r__2;
  500. /* Local variables */
  501. integer i__, j;
  502. extern logical lsame_(char *, char *);
  503. logical wantq, wantu, wantv;
  504. extern /* Subroutine */ void cgeqr2_(integer *, integer *, complex *,
  505. integer *, complex *, complex *, integer *), cgerq2_(integer *,
  506. integer *, complex *, integer *, complex *, complex *, integer *),
  507. cung2r_(integer *, integer *, integer *, complex *, integer *,
  508. complex *, complex *, integer *), cunm2r_(char *, char *, integer
  509. *, integer *, integer *, complex *, integer *, complex *, complex
  510. *, integer *, complex *, integer *), cunmr2_(char
  511. *, char *, integer *, integer *, integer *, complex *, integer *,
  512. complex *, complex *, integer *, complex *, integer *), cgeqpf_(integer *, integer *, complex *, integer *,
  513. integer *, complex *, complex *, real *, integer *), clacpy_(char
  514. *, integer *, integer *, complex *, integer *, complex *, integer
  515. *), claset_(char *, integer *, integer *, complex *,
  516. complex *, complex *, integer *);
  517. extern int xerbla_(char *, integer *, ftnlen);
  518. extern void clapmt_(logical *, integer *, integer *, complex *,
  519. integer *, integer *);
  520. logical forwrd;
  521. /* -- LAPACK computational routine (version 3.7.0) -- */
  522. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  523. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  524. /* December 2016 */
  525. /* ===================================================================== */
  526. /* Test the input parameters */
  527. /* Parameter adjustments */
  528. a_dim1 = *lda;
  529. a_offset = 1 + a_dim1 * 1;
  530. a -= a_offset;
  531. b_dim1 = *ldb;
  532. b_offset = 1 + b_dim1 * 1;
  533. b -= b_offset;
  534. u_dim1 = *ldu;
  535. u_offset = 1 + u_dim1 * 1;
  536. u -= u_offset;
  537. v_dim1 = *ldv;
  538. v_offset = 1 + v_dim1 * 1;
  539. v -= v_offset;
  540. q_dim1 = *ldq;
  541. q_offset = 1 + q_dim1 * 1;
  542. q -= q_offset;
  543. --iwork;
  544. --rwork;
  545. --tau;
  546. --work;
  547. /* Function Body */
  548. wantu = lsame_(jobu, "U");
  549. wantv = lsame_(jobv, "V");
  550. wantq = lsame_(jobq, "Q");
  551. forwrd = TRUE_;
  552. *info = 0;
  553. if (! (wantu || lsame_(jobu, "N"))) {
  554. *info = -1;
  555. } else if (! (wantv || lsame_(jobv, "N"))) {
  556. *info = -2;
  557. } else if (! (wantq || lsame_(jobq, "N"))) {
  558. *info = -3;
  559. } else if (*m < 0) {
  560. *info = -4;
  561. } else if (*p < 0) {
  562. *info = -5;
  563. } else if (*n < 0) {
  564. *info = -6;
  565. } else if (*lda < f2cmax(1,*m)) {
  566. *info = -8;
  567. } else if (*ldb < f2cmax(1,*p)) {
  568. *info = -10;
  569. } else if (*ldu < 1 || wantu && *ldu < *m) {
  570. *info = -16;
  571. } else if (*ldv < 1 || wantv && *ldv < *p) {
  572. *info = -18;
  573. } else if (*ldq < 1 || wantq && *ldq < *n) {
  574. *info = -20;
  575. }
  576. if (*info != 0) {
  577. i__1 = -(*info);
  578. xerbla_("CGGSVP", &i__1, 6);
  579. return;
  580. }
  581. /* QR with column pivoting of B: B*P = V*( S11 S12 ) */
  582. /* ( 0 0 ) */
  583. i__1 = *n;
  584. for (i__ = 1; i__ <= i__1; ++i__) {
  585. iwork[i__] = 0;
  586. /* L10: */
  587. }
  588. cgeqpf_(p, n, &b[b_offset], ldb, &iwork[1], &tau[1], &work[1], &rwork[1],
  589. info);
  590. /* Update A := A*P */
  591. clapmt_(&forwrd, m, n, &a[a_offset], lda, &iwork[1]);
  592. /* Determine the effective rank of matrix B. */
  593. *l = 0;
  594. i__1 = f2cmin(*p,*n);
  595. for (i__ = 1; i__ <= i__1; ++i__) {
  596. i__2 = i__ + i__ * b_dim1;
  597. if ((r__1 = b[i__2].r, abs(r__1)) + (r__2 = r_imag(&b[i__ + i__ *
  598. b_dim1]), abs(r__2)) > *tolb) {
  599. ++(*l);
  600. }
  601. /* L20: */
  602. }
  603. if (wantv) {
  604. /* Copy the details of V, and form V. */
  605. claset_("Full", p, p, &c_b1, &c_b1, &v[v_offset], ldv);
  606. if (*p > 1) {
  607. i__1 = *p - 1;
  608. clacpy_("Lower", &i__1, n, &b[b_dim1 + 2], ldb, &v[v_dim1 + 2],
  609. ldv);
  610. }
  611. i__1 = f2cmin(*p,*n);
  612. cung2r_(p, p, &i__1, &v[v_offset], ldv, &tau[1], &work[1], info);
  613. }
  614. /* Clean up B */
  615. i__1 = *l - 1;
  616. for (j = 1; j <= i__1; ++j) {
  617. i__2 = *l;
  618. for (i__ = j + 1; i__ <= i__2; ++i__) {
  619. i__3 = i__ + j * b_dim1;
  620. b[i__3].r = 0.f, b[i__3].i = 0.f;
  621. /* L30: */
  622. }
  623. /* L40: */
  624. }
  625. if (*p > *l) {
  626. i__1 = *p - *l;
  627. claset_("Full", &i__1, n, &c_b1, &c_b1, &b[*l + 1 + b_dim1], ldb);
  628. }
  629. if (wantq) {
  630. /* Set Q = I and Update Q := Q*P */
  631. claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
  632. clapmt_(&forwrd, n, n, &q[q_offset], ldq, &iwork[1]);
  633. }
  634. if (*p >= *l && *n != *l) {
  635. /* RQ factorization of ( S11 S12 ) = ( 0 S12 )*Z */
  636. cgerq2_(l, n, &b[b_offset], ldb, &tau[1], &work[1], info);
  637. /* Update A := A*Z**H */
  638. cunmr2_("Right", "Conjugate transpose", m, n, l, &b[b_offset], ldb, &
  639. tau[1], &a[a_offset], lda, &work[1], info);
  640. if (wantq) {
  641. /* Update Q := Q*Z**H */
  642. cunmr2_("Right", "Conjugate transpose", n, n, l, &b[b_offset],
  643. ldb, &tau[1], &q[q_offset], ldq, &work[1], info);
  644. }
  645. /* Clean up B */
  646. i__1 = *n - *l;
  647. claset_("Full", l, &i__1, &c_b1, &c_b1, &b[b_offset], ldb);
  648. i__1 = *n;
  649. for (j = *n - *l + 1; j <= i__1; ++j) {
  650. i__2 = *l;
  651. for (i__ = j - *n + *l + 1; i__ <= i__2; ++i__) {
  652. i__3 = i__ + j * b_dim1;
  653. b[i__3].r = 0.f, b[i__3].i = 0.f;
  654. /* L50: */
  655. }
  656. /* L60: */
  657. }
  658. }
  659. /* Let N-L L */
  660. /* A = ( A11 A12 ) M, */
  661. /* then the following does the complete QR decomposition of A11: */
  662. /* A11 = U*( 0 T12 )*P1**H */
  663. /* ( 0 0 ) */
  664. i__1 = *n - *l;
  665. for (i__ = 1; i__ <= i__1; ++i__) {
  666. iwork[i__] = 0;
  667. /* L70: */
  668. }
  669. i__1 = *n - *l;
  670. cgeqpf_(m, &i__1, &a[a_offset], lda, &iwork[1], &tau[1], &work[1], &rwork[
  671. 1], info);
  672. /* Determine the effective rank of A11 */
  673. *k = 0;
  674. /* Computing MIN */
  675. i__2 = *m, i__3 = *n - *l;
  676. i__1 = f2cmin(i__2,i__3);
  677. for (i__ = 1; i__ <= i__1; ++i__) {
  678. i__2 = i__ + i__ * a_dim1;
  679. if ((r__1 = a[i__2].r, abs(r__1)) + (r__2 = r_imag(&a[i__ + i__ *
  680. a_dim1]), abs(r__2)) > *tola) {
  681. ++(*k);
  682. }
  683. /* L80: */
  684. }
  685. /* Update A12 := U**H*A12, where A12 = A( 1:M, N-L+1:N ) */
  686. /* Computing MIN */
  687. i__2 = *m, i__3 = *n - *l;
  688. i__1 = f2cmin(i__2,i__3);
  689. cunm2r_("Left", "Conjugate transpose", m, l, &i__1, &a[a_offset], lda, &
  690. tau[1], &a[(*n - *l + 1) * a_dim1 + 1], lda, &work[1], info);
  691. if (wantu) {
  692. /* Copy the details of U, and form U */
  693. claset_("Full", m, m, &c_b1, &c_b1, &u[u_offset], ldu);
  694. if (*m > 1) {
  695. i__1 = *m - 1;
  696. i__2 = *n - *l;
  697. clacpy_("Lower", &i__1, &i__2, &a[a_dim1 + 2], lda, &u[u_dim1 + 2]
  698. , ldu);
  699. }
  700. /* Computing MIN */
  701. i__2 = *m, i__3 = *n - *l;
  702. i__1 = f2cmin(i__2,i__3);
  703. cung2r_(m, m, &i__1, &u[u_offset], ldu, &tau[1], &work[1], info);
  704. }
  705. if (wantq) {
  706. /* Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1 */
  707. i__1 = *n - *l;
  708. clapmt_(&forwrd, n, &i__1, &q[q_offset], ldq, &iwork[1]);
  709. }
  710. /* Clean up A: set the strictly lower triangular part of */
  711. /* A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0. */
  712. i__1 = *k - 1;
  713. for (j = 1; j <= i__1; ++j) {
  714. i__2 = *k;
  715. for (i__ = j + 1; i__ <= i__2; ++i__) {
  716. i__3 = i__ + j * a_dim1;
  717. a[i__3].r = 0.f, a[i__3].i = 0.f;
  718. /* L90: */
  719. }
  720. /* L100: */
  721. }
  722. if (*m > *k) {
  723. i__1 = *m - *k;
  724. i__2 = *n - *l;
  725. claset_("Full", &i__1, &i__2, &c_b1, &c_b1, &a[*k + 1 + a_dim1], lda);
  726. }
  727. if (*n - *l > *k) {
  728. /* RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1 */
  729. i__1 = *n - *l;
  730. cgerq2_(k, &i__1, &a[a_offset], lda, &tau[1], &work[1], info);
  731. if (wantq) {
  732. /* Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**H */
  733. i__1 = *n - *l;
  734. cunmr2_("Right", "Conjugate transpose", n, &i__1, k, &a[a_offset],
  735. lda, &tau[1], &q[q_offset], ldq, &work[1], info);
  736. }
  737. /* Clean up A */
  738. i__1 = *n - *l - *k;
  739. claset_("Full", k, &i__1, &c_b1, &c_b1, &a[a_offset], lda);
  740. i__1 = *n - *l;
  741. for (j = *n - *l - *k + 1; j <= i__1; ++j) {
  742. i__2 = *k;
  743. for (i__ = j - *n + *l + *k + 1; i__ <= i__2; ++i__) {
  744. i__3 = i__ + j * a_dim1;
  745. a[i__3].r = 0.f, a[i__3].i = 0.f;
  746. /* L110: */
  747. }
  748. /* L120: */
  749. }
  750. }
  751. if (*m > *k) {
  752. /* QR factorization of A( K+1:M,N-L+1:N ) */
  753. i__1 = *m - *k;
  754. cgeqr2_(&i__1, l, &a[*k + 1 + (*n - *l + 1) * a_dim1], lda, &tau[1], &
  755. work[1], info);
  756. if (wantu) {
  757. /* Update U(:,K+1:M) := U(:,K+1:M)*U1 */
  758. i__1 = *m - *k;
  759. /* Computing MIN */
  760. i__3 = *m - *k;
  761. i__2 = f2cmin(i__3,*l);
  762. cunm2r_("Right", "No transpose", m, &i__1, &i__2, &a[*k + 1 + (*n
  763. - *l + 1) * a_dim1], lda, &tau[1], &u[(*k + 1) * u_dim1 +
  764. 1], ldu, &work[1], info);
  765. }
  766. /* Clean up */
  767. i__1 = *n;
  768. for (j = *n - *l + 1; j <= i__1; ++j) {
  769. i__2 = *m;
  770. for (i__ = j - *n + *k + *l + 1; i__ <= i__2; ++i__) {
  771. i__3 = i__ + j * a_dim1;
  772. a[i__3].r = 0.f, a[i__3].i = 0.f;
  773. /* L130: */
  774. }
  775. /* L140: */
  776. }
  777. }
  778. return;
  779. /* End of CGGSVP */
  780. } /* cggsvp_ */