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