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.

sgbbrd.c 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static real c_b8 = 0.f;
  236. static real c_b9 = 1.f;
  237. static integer c__1 = 1;
  238. /* > \brief \b SGBBRD */
  239. /* =========== DOCUMENTATION =========== */
  240. /* Online html documentation available at */
  241. /* http://www.netlib.org/lapack/explore-html/ */
  242. /* > \htmlonly */
  243. /* > Download SGBBRD + dependencies */
  244. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgbbrd.
  245. f"> */
  246. /* > [TGZ]</a> */
  247. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgbbrd.
  248. f"> */
  249. /* > [ZIP]</a> */
  250. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgbbrd.
  251. f"> */
  252. /* > [TXT]</a> */
  253. /* > \endhtmlonly */
  254. /* Definition: */
  255. /* =========== */
  256. /* SUBROUTINE SGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q, */
  257. /* LDQ, PT, LDPT, C, LDC, WORK, INFO ) */
  258. /* CHARACTER VECT */
  259. /* INTEGER INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC */
  260. /* REAL AB( LDAB, * ), C( LDC, * ), D( * ), E( * ), */
  261. /* $ PT( LDPT, * ), Q( LDQ, * ), WORK( * ) */
  262. /* > \par Purpose: */
  263. /* ============= */
  264. /* > */
  265. /* > \verbatim */
  266. /* > */
  267. /* > SGBBRD reduces a real general m-by-n band matrix A to upper */
  268. /* > bidiagonal form B by an orthogonal transformation: Q**T * A * P = B. */
  269. /* > */
  270. /* > The routine computes B, and optionally forms Q or P**T, or computes */
  271. /* > Q**T*C for a given matrix C. */
  272. /* > \endverbatim */
  273. /* Arguments: */
  274. /* ========== */
  275. /* > \param[in] VECT */
  276. /* > \verbatim */
  277. /* > VECT is CHARACTER*1 */
  278. /* > Specifies whether or not the matrices Q and P**T are to be */
  279. /* > formed. */
  280. /* > = 'N': do not form Q or P**T; */
  281. /* > = 'Q': form Q only; */
  282. /* > = 'P': form P**T only; */
  283. /* > = 'B': form both. */
  284. /* > \endverbatim */
  285. /* > */
  286. /* > \param[in] M */
  287. /* > \verbatim */
  288. /* > M is INTEGER */
  289. /* > The number of rows of the matrix A. M >= 0. */
  290. /* > \endverbatim */
  291. /* > */
  292. /* > \param[in] N */
  293. /* > \verbatim */
  294. /* > N is INTEGER */
  295. /* > The number of columns of the matrix A. N >= 0. */
  296. /* > \endverbatim */
  297. /* > */
  298. /* > \param[in] NCC */
  299. /* > \verbatim */
  300. /* > NCC is INTEGER */
  301. /* > The number of columns of the matrix C. NCC >= 0. */
  302. /* > \endverbatim */
  303. /* > */
  304. /* > \param[in] KL */
  305. /* > \verbatim */
  306. /* > KL is INTEGER */
  307. /* > The number of subdiagonals of the matrix A. KL >= 0. */
  308. /* > \endverbatim */
  309. /* > */
  310. /* > \param[in] KU */
  311. /* > \verbatim */
  312. /* > KU is INTEGER */
  313. /* > The number of superdiagonals of the matrix A. KU >= 0. */
  314. /* > \endverbatim */
  315. /* > */
  316. /* > \param[in,out] AB */
  317. /* > \verbatim */
  318. /* > AB is REAL array, dimension (LDAB,N) */
  319. /* > On entry, the m-by-n band matrix A, stored in rows 1 to */
  320. /* > KL+KU+1. The j-th column of A is stored in the j-th column of */
  321. /* > the array AB as follows: */
  322. /* > AB(ku+1+i-j,j) = A(i,j) for f2cmax(1,j-ku)<=i<=f2cmin(m,j+kl). */
  323. /* > On exit, A is overwritten by values generated during the */
  324. /* > reduction. */
  325. /* > \endverbatim */
  326. /* > */
  327. /* > \param[in] LDAB */
  328. /* > \verbatim */
  329. /* > LDAB is INTEGER */
  330. /* > The leading dimension of the array A. LDAB >= KL+KU+1. */
  331. /* > \endverbatim */
  332. /* > */
  333. /* > \param[out] D */
  334. /* > \verbatim */
  335. /* > D is REAL array, dimension (f2cmin(M,N)) */
  336. /* > The diagonal elements of the bidiagonal matrix B. */
  337. /* > \endverbatim */
  338. /* > */
  339. /* > \param[out] E */
  340. /* > \verbatim */
  341. /* > E is REAL array, dimension (f2cmin(M,N)-1) */
  342. /* > The superdiagonal elements of the bidiagonal matrix B. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[out] Q */
  346. /* > \verbatim */
  347. /* > Q is REAL array, dimension (LDQ,M) */
  348. /* > If VECT = 'Q' or 'B', the m-by-m orthogonal matrix Q. */
  349. /* > If VECT = 'N' or 'P', the array Q is not referenced. */
  350. /* > \endverbatim */
  351. /* > */
  352. /* > \param[in] LDQ */
  353. /* > \verbatim */
  354. /* > LDQ is INTEGER */
  355. /* > The leading dimension of the array Q. */
  356. /* > LDQ >= f2cmax(1,M) if VECT = 'Q' or 'B'; LDQ >= 1 otherwise. */
  357. /* > \endverbatim */
  358. /* > */
  359. /* > \param[out] PT */
  360. /* > \verbatim */
  361. /* > PT is REAL array, dimension (LDPT,N) */
  362. /* > If VECT = 'P' or 'B', the n-by-n orthogonal matrix P'. */
  363. /* > If VECT = 'N' or 'Q', the array PT is not referenced. */
  364. /* > \endverbatim */
  365. /* > */
  366. /* > \param[in] LDPT */
  367. /* > \verbatim */
  368. /* > LDPT is INTEGER */
  369. /* > The leading dimension of the array PT. */
  370. /* > LDPT >= f2cmax(1,N) if VECT = 'P' or 'B'; LDPT >= 1 otherwise. */
  371. /* > \endverbatim */
  372. /* > */
  373. /* > \param[in,out] C */
  374. /* > \verbatim */
  375. /* > C is REAL array, dimension (LDC,NCC) */
  376. /* > On entry, an m-by-ncc matrix C. */
  377. /* > On exit, C is overwritten by Q**T*C. */
  378. /* > C is not referenced if NCC = 0. */
  379. /* > \endverbatim */
  380. /* > */
  381. /* > \param[in] LDC */
  382. /* > \verbatim */
  383. /* > LDC is INTEGER */
  384. /* > The leading dimension of the array C. */
  385. /* > LDC >= f2cmax(1,M) if NCC > 0; LDC >= 1 if NCC = 0. */
  386. /* > \endverbatim */
  387. /* > */
  388. /* > \param[out] WORK */
  389. /* > \verbatim */
  390. /* > WORK is REAL array, dimension (2*f2cmax(M,N)) */
  391. /* > \endverbatim */
  392. /* > */
  393. /* > \param[out] INFO */
  394. /* > \verbatim */
  395. /* > INFO is INTEGER */
  396. /* > = 0: successful exit. */
  397. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  398. /* > \endverbatim */
  399. /* Authors: */
  400. /* ======== */
  401. /* > \author Univ. of Tennessee */
  402. /* > \author Univ. of California Berkeley */
  403. /* > \author Univ. of Colorado Denver */
  404. /* > \author NAG Ltd. */
  405. /* > \date December 2016 */
  406. /* > \ingroup realGBcomputational */
  407. /* ===================================================================== */
  408. /* Subroutine */ void sgbbrd_(char *vect, integer *m, integer *n, integer *ncc,
  409. integer *kl, integer *ku, real *ab, integer *ldab, real *d__, real *
  410. e, real *q, integer *ldq, real *pt, integer *ldpt, real *c__, integer
  411. *ldc, real *work, integer *info)
  412. {
  413. /* System generated locals */
  414. integer ab_dim1, ab_offset, c_dim1, c_offset, pt_dim1, pt_offset, q_dim1,
  415. q_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7;
  416. /* Local variables */
  417. integer inca;
  418. extern /* Subroutine */ void srot_(integer *, real *, integer *, real *,
  419. integer *, real *, real *);
  420. integer i__, j, l;
  421. extern logical lsame_(char *, char *);
  422. logical wantb, wantc;
  423. integer minmn;
  424. logical wantq;
  425. integer j1, j2, kb;
  426. real ra, rb, rc;
  427. integer kk, ml, mn, nr, mu;
  428. real rs;
  429. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  430. extern void slaset_(
  431. char *, integer *, integer *, real *, real *, real *, integer *), slartg_(real *, real *, real *, real *, real *);
  432. integer kb1;
  433. extern /* Subroutine */ void slargv_(integer *, real *, integer *, real *,
  434. integer *, real *, integer *);
  435. integer ml0;
  436. extern /* Subroutine */ void slartv_(integer *, real *, integer *, real *,
  437. integer *, real *, real *, integer *);
  438. logical wantpt;
  439. integer mu0, klm, kun, nrt, klu1;
  440. /* -- LAPACK computational routine (version 3.7.0) -- */
  441. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  442. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  443. /* December 2016 */
  444. /* ===================================================================== */
  445. /* Test the input parameters */
  446. /* Parameter adjustments */
  447. ab_dim1 = *ldab;
  448. ab_offset = 1 + ab_dim1 * 1;
  449. ab -= ab_offset;
  450. --d__;
  451. --e;
  452. q_dim1 = *ldq;
  453. q_offset = 1 + q_dim1 * 1;
  454. q -= q_offset;
  455. pt_dim1 = *ldpt;
  456. pt_offset = 1 + pt_dim1 * 1;
  457. pt -= pt_offset;
  458. c_dim1 = *ldc;
  459. c_offset = 1 + c_dim1 * 1;
  460. c__ -= c_offset;
  461. --work;
  462. /* Function Body */
  463. wantb = lsame_(vect, "B");
  464. wantq = lsame_(vect, "Q") || wantb;
  465. wantpt = lsame_(vect, "P") || wantb;
  466. wantc = *ncc > 0;
  467. klu1 = *kl + *ku + 1;
  468. *info = 0;
  469. if (! wantq && ! wantpt && ! lsame_(vect, "N")) {
  470. *info = -1;
  471. } else if (*m < 0) {
  472. *info = -2;
  473. } else if (*n < 0) {
  474. *info = -3;
  475. } else if (*ncc < 0) {
  476. *info = -4;
  477. } else if (*kl < 0) {
  478. *info = -5;
  479. } else if (*ku < 0) {
  480. *info = -6;
  481. } else if (*ldab < klu1) {
  482. *info = -8;
  483. } else if (*ldq < 1 || wantq && *ldq < f2cmax(1,*m)) {
  484. *info = -12;
  485. } else if (*ldpt < 1 || wantpt && *ldpt < f2cmax(1,*n)) {
  486. *info = -14;
  487. } else if (*ldc < 1 || wantc && *ldc < f2cmax(1,*m)) {
  488. *info = -16;
  489. }
  490. if (*info != 0) {
  491. i__1 = -(*info);
  492. xerbla_("SGBBRD", &i__1, (ftnlen)6);
  493. return;
  494. }
  495. /* Initialize Q and P**T to the unit matrix, if needed */
  496. if (wantq) {
  497. slaset_("Full", m, m, &c_b8, &c_b9, &q[q_offset], ldq);
  498. }
  499. if (wantpt) {
  500. slaset_("Full", n, n, &c_b8, &c_b9, &pt[pt_offset], ldpt);
  501. }
  502. /* Quick return if possible. */
  503. if (*m == 0 || *n == 0) {
  504. return;
  505. }
  506. minmn = f2cmin(*m,*n);
  507. if (*kl + *ku > 1) {
  508. /* Reduce to upper bidiagonal form if KU > 0; if KU = 0, reduce */
  509. /* first to lower bidiagonal form and then transform to upper */
  510. /* bidiagonal */
  511. if (*ku > 0) {
  512. ml0 = 1;
  513. mu0 = 2;
  514. } else {
  515. ml0 = 2;
  516. mu0 = 1;
  517. }
  518. /* Wherever possible, plane rotations are generated and applied in */
  519. /* vector operations of length NR over the index set J1:J2:KLU1. */
  520. /* The sines of the plane rotations are stored in WORK(1:f2cmax(m,n)) */
  521. /* and the cosines in WORK(f2cmax(m,n)+1:2*f2cmax(m,n)). */
  522. mn = f2cmax(*m,*n);
  523. /* Computing MIN */
  524. i__1 = *m - 1;
  525. klm = f2cmin(i__1,*kl);
  526. /* Computing MIN */
  527. i__1 = *n - 1;
  528. kun = f2cmin(i__1,*ku);
  529. kb = klm + kun;
  530. kb1 = kb + 1;
  531. inca = kb1 * *ldab;
  532. nr = 0;
  533. j1 = klm + 2;
  534. j2 = 1 - kun;
  535. i__1 = minmn;
  536. for (i__ = 1; i__ <= i__1; ++i__) {
  537. /* Reduce i-th column and i-th row of matrix to bidiagonal form */
  538. ml = klm + 1;
  539. mu = kun + 1;
  540. i__2 = kb;
  541. for (kk = 1; kk <= i__2; ++kk) {
  542. j1 += kb;
  543. j2 += kb;
  544. /* generate plane rotations to annihilate nonzero elements */
  545. /* which have been created below the band */
  546. if (nr > 0) {
  547. slargv_(&nr, &ab[klu1 + (j1 - klm - 1) * ab_dim1], &inca,
  548. &work[j1], &kb1, &work[mn + j1], &kb1);
  549. }
  550. /* apply plane rotations from the left */
  551. i__3 = kb;
  552. for (l = 1; l <= i__3; ++l) {
  553. if (j2 - klm + l - 1 > *n) {
  554. nrt = nr - 1;
  555. } else {
  556. nrt = nr;
  557. }
  558. if (nrt > 0) {
  559. slartv_(&nrt, &ab[klu1 - l + (j1 - klm + l - 1) *
  560. ab_dim1], &inca, &ab[klu1 - l + 1 + (j1 - klm
  561. + l - 1) * ab_dim1], &inca, &work[mn + j1], &
  562. work[j1], &kb1);
  563. }
  564. /* L10: */
  565. }
  566. if (ml > ml0) {
  567. if (ml <= *m - i__ + 1) {
  568. /* generate plane rotation to annihilate a(i+ml-1,i) */
  569. /* within the band, and apply rotation from the left */
  570. slartg_(&ab[*ku + ml - 1 + i__ * ab_dim1], &ab[*ku +
  571. ml + i__ * ab_dim1], &work[mn + i__ + ml - 1],
  572. &work[i__ + ml - 1], &ra);
  573. ab[*ku + ml - 1 + i__ * ab_dim1] = ra;
  574. if (i__ < *n) {
  575. /* Computing MIN */
  576. i__4 = *ku + ml - 2, i__5 = *n - i__;
  577. i__3 = f2cmin(i__4,i__5);
  578. i__6 = *ldab - 1;
  579. i__7 = *ldab - 1;
  580. srot_(&i__3, &ab[*ku + ml - 2 + (i__ + 1) *
  581. ab_dim1], &i__6, &ab[*ku + ml - 1 + (i__
  582. + 1) * ab_dim1], &i__7, &work[mn + i__ +
  583. ml - 1], &work[i__ + ml - 1]);
  584. }
  585. }
  586. ++nr;
  587. j1 -= kb1;
  588. }
  589. if (wantq) {
  590. /* accumulate product of plane rotations in Q */
  591. i__3 = j2;
  592. i__4 = kb1;
  593. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4)
  594. {
  595. srot_(m, &q[(j - 1) * q_dim1 + 1], &c__1, &q[j *
  596. q_dim1 + 1], &c__1, &work[mn + j], &work[j]);
  597. /* L20: */
  598. }
  599. }
  600. if (wantc) {
  601. /* apply plane rotations to C */
  602. i__4 = j2;
  603. i__3 = kb1;
  604. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3)
  605. {
  606. srot_(ncc, &c__[j - 1 + c_dim1], ldc, &c__[j + c_dim1]
  607. , ldc, &work[mn + j], &work[j]);
  608. /* L30: */
  609. }
  610. }
  611. if (j2 + kun > *n) {
  612. /* adjust J2 to keep within the bounds of the matrix */
  613. --nr;
  614. j2 -= kb1;
  615. }
  616. i__3 = j2;
  617. i__4 = kb1;
  618. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  619. /* create nonzero element a(j-1,j+ku) above the band */
  620. /* and store it in WORK(n+1:2*n) */
  621. work[j + kun] = work[j] * ab[(j + kun) * ab_dim1 + 1];
  622. ab[(j + kun) * ab_dim1 + 1] = work[mn + j] * ab[(j + kun)
  623. * ab_dim1 + 1];
  624. /* L40: */
  625. }
  626. /* generate plane rotations to annihilate nonzero elements */
  627. /* which have been generated above the band */
  628. if (nr > 0) {
  629. slargv_(&nr, &ab[(j1 + kun - 1) * ab_dim1 + 1], &inca, &
  630. work[j1 + kun], &kb1, &work[mn + j1 + kun], &kb1);
  631. }
  632. /* apply plane rotations from the right */
  633. i__4 = kb;
  634. for (l = 1; l <= i__4; ++l) {
  635. if (j2 + l - 1 > *m) {
  636. nrt = nr - 1;
  637. } else {
  638. nrt = nr;
  639. }
  640. if (nrt > 0) {
  641. slartv_(&nrt, &ab[l + 1 + (j1 + kun - 1) * ab_dim1], &
  642. inca, &ab[l + (j1 + kun) * ab_dim1], &inca, &
  643. work[mn + j1 + kun], &work[j1 + kun], &kb1);
  644. }
  645. /* L50: */
  646. }
  647. if (ml == ml0 && mu > mu0) {
  648. if (mu <= *n - i__ + 1) {
  649. /* generate plane rotation to annihilate a(i,i+mu-1) */
  650. /* within the band, and apply rotation from the right */
  651. slartg_(&ab[*ku - mu + 3 + (i__ + mu - 2) * ab_dim1],
  652. &ab[*ku - mu + 2 + (i__ + mu - 1) * ab_dim1],
  653. &work[mn + i__ + mu - 1], &work[i__ + mu - 1],
  654. &ra);
  655. ab[*ku - mu + 3 + (i__ + mu - 2) * ab_dim1] = ra;
  656. /* Computing MIN */
  657. i__3 = *kl + mu - 2, i__5 = *m - i__;
  658. i__4 = f2cmin(i__3,i__5);
  659. srot_(&i__4, &ab[*ku - mu + 4 + (i__ + mu - 2) *
  660. ab_dim1], &c__1, &ab[*ku - mu + 3 + (i__ + mu
  661. - 1) * ab_dim1], &c__1, &work[mn + i__ + mu -
  662. 1], &work[i__ + mu - 1]);
  663. }
  664. ++nr;
  665. j1 -= kb1;
  666. }
  667. if (wantpt) {
  668. /* accumulate product of plane rotations in P**T */
  669. i__4 = j2;
  670. i__3 = kb1;
  671. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3)
  672. {
  673. srot_(n, &pt[j + kun - 1 + pt_dim1], ldpt, &pt[j +
  674. kun + pt_dim1], ldpt, &work[mn + j + kun], &
  675. work[j + kun]);
  676. /* L60: */
  677. }
  678. }
  679. if (j2 + kb > *m) {
  680. /* adjust J2 to keep within the bounds of the matrix */
  681. --nr;
  682. j2 -= kb1;
  683. }
  684. i__3 = j2;
  685. i__4 = kb1;
  686. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  687. /* create nonzero element a(j+kl+ku,j+ku-1) below the */
  688. /* band and store it in WORK(1:n) */
  689. work[j + kb] = work[j + kun] * ab[klu1 + (j + kun) *
  690. ab_dim1];
  691. ab[klu1 + (j + kun) * ab_dim1] = work[mn + j + kun] * ab[
  692. klu1 + (j + kun) * ab_dim1];
  693. /* L70: */
  694. }
  695. if (ml > ml0) {
  696. --ml;
  697. } else {
  698. --mu;
  699. }
  700. /* L80: */
  701. }
  702. /* L90: */
  703. }
  704. }
  705. if (*ku == 0 && *kl > 0) {
  706. /* A has been reduced to lower bidiagonal form */
  707. /* Transform lower bidiagonal form to upper bidiagonal by applying */
  708. /* plane rotations from the left, storing diagonal elements in D */
  709. /* and off-diagonal elements in E */
  710. /* Computing MIN */
  711. i__2 = *m - 1;
  712. i__1 = f2cmin(i__2,*n);
  713. for (i__ = 1; i__ <= i__1; ++i__) {
  714. slartg_(&ab[i__ * ab_dim1 + 1], &ab[i__ * ab_dim1 + 2], &rc, &rs,
  715. &ra);
  716. d__[i__] = ra;
  717. if (i__ < *n) {
  718. e[i__] = rs * ab[(i__ + 1) * ab_dim1 + 1];
  719. ab[(i__ + 1) * ab_dim1 + 1] = rc * ab[(i__ + 1) * ab_dim1 + 1]
  720. ;
  721. }
  722. if (wantq) {
  723. srot_(m, &q[i__ * q_dim1 + 1], &c__1, &q[(i__ + 1) * q_dim1 +
  724. 1], &c__1, &rc, &rs);
  725. }
  726. if (wantc) {
  727. srot_(ncc, &c__[i__ + c_dim1], ldc, &c__[i__ + 1 + c_dim1],
  728. ldc, &rc, &rs);
  729. }
  730. /* L100: */
  731. }
  732. if (*m <= *n) {
  733. d__[*m] = ab[*m * ab_dim1 + 1];
  734. }
  735. } else if (*ku > 0) {
  736. /* A has been reduced to upper bidiagonal form */
  737. if (*m < *n) {
  738. /* Annihilate a(m,m+1) by applying plane rotations from the */
  739. /* right, storing diagonal elements in D and off-diagonal */
  740. /* elements in E */
  741. rb = ab[*ku + (*m + 1) * ab_dim1];
  742. for (i__ = *m; i__ >= 1; --i__) {
  743. slartg_(&ab[*ku + 1 + i__ * ab_dim1], &rb, &rc, &rs, &ra);
  744. d__[i__] = ra;
  745. if (i__ > 1) {
  746. rb = -rs * ab[*ku + i__ * ab_dim1];
  747. e[i__ - 1] = rc * ab[*ku + i__ * ab_dim1];
  748. }
  749. if (wantpt) {
  750. srot_(n, &pt[i__ + pt_dim1], ldpt, &pt[*m + 1 + pt_dim1],
  751. ldpt, &rc, &rs);
  752. }
  753. /* L110: */
  754. }
  755. } else {
  756. /* Copy off-diagonal elements to E and diagonal elements to D */
  757. i__1 = minmn - 1;
  758. for (i__ = 1; i__ <= i__1; ++i__) {
  759. e[i__] = ab[*ku + (i__ + 1) * ab_dim1];
  760. /* L120: */
  761. }
  762. i__1 = minmn;
  763. for (i__ = 1; i__ <= i__1; ++i__) {
  764. d__[i__] = ab[*ku + 1 + i__ * ab_dim1];
  765. /* L130: */
  766. }
  767. }
  768. } else {
  769. /* A is diagonal. Set elements of E to zero and copy diagonal */
  770. /* elements to D. */
  771. i__1 = minmn - 1;
  772. for (i__ = 1; i__ <= i__1; ++i__) {
  773. e[i__] = 0.f;
  774. /* L140: */
  775. }
  776. i__1 = minmn;
  777. for (i__ = 1; i__ <= i__1; ++i__) {
  778. d__[i__] = ab[i__ * ab_dim1 + 1];
  779. /* L150: */
  780. }
  781. }
  782. return;
  783. /* End of SGBBRD */
  784. } /* sgbbrd_ */