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.

dggsvp3.c 30 kB

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