C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zlaed7.c
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
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow = _Cmulcc(pow, x);
329                         if(u >>= 1) x = _Cmulcc(x, x);
330                         else break;
331                 }
332         }
333         return pow;
334 }
335 #else
336 static _Complex double zpow_ui(_Complex double x, integer n) {
337         _Complex double pow=1.0; unsigned long int u;
338         if(n != 0) {
339                 if(n < 0) n = -n, x = 1/x;
340                 for(u = n; ; ) {
341                         if(u & 01) pow *= x;
342                         if(u >>= 1) x *= x;
343                         else break;
344                 }
345         }
346         return pow;
347 }
348 #endif
349 static integer pow_ii(integer x, integer n) {
350         integer pow; unsigned long int u;
351         if (n <= 0) {
352                 if (n == 0 || x == 1) pow = 1;
353                 else if (x != -1) pow = x == 0 ? 1/x : 0;
354                 else n = -n;
355         }
356         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
357                 u = n;
358                 for(pow = 1; ; ) {
359                         if(u & 01) pow *= x;
360                         if(u >>= 1) x *= x;
361                         else break;
362                 }
363         }
364         return pow;
365 }
366 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
367 {
368         double m; integer i, mi;
369         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
370                 if (w[i-1]>m) mi=i ,m=w[i-1];
371         return mi-s+1;
372 }
373 static integer smaxloc_(float *w, integer s, integer e, integer *n)
374 {
375         float m; integer i, mi;
376         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
377                 if (w[i-1]>m) mi=i ,m=w[i-1];
378         return mi-s+1;
379 }
380 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
381         integer n = *n_, incx = *incx_, incy = *incy_, i;
382 #ifdef _MSC_VER
383         _Fcomplex zdotc = {0.0, 0.0};
384         if (incx == 1 && incy == 1) {
385                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
386                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
387                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
388                 }
389         } else {
390                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
391                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
392                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
393                 }
394         }
395         pCf(z) = zdotc;
396 }
397 #else
398         _Complex float zdotc = 0.0;
399         if (incx == 1 && incy == 1) {
400                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
401                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
402                 }
403         } else {
404                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
405                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
406                 }
407         }
408         pCf(z) = zdotc;
409 }
410 #endif
411 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
412         integer n = *n_, incx = *incx_, incy = *incy_, i;
413 #ifdef _MSC_VER
414         _Dcomplex zdotc = {0.0, 0.0};
415         if (incx == 1 && incy == 1) {
416                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
417                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
418                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
419                 }
420         } else {
421                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
422                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
423                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
424                 }
425         }
426         pCd(z) = zdotc;
427 }
428 #else
429         _Complex double zdotc = 0.0;
430         if (incx == 1 && incy == 1) {
431                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
432                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
433                 }
434         } else {
435                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
436                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
437                 }
438         }
439         pCd(z) = zdotc;
440 }
441 #endif  
442 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
443         integer n = *n_, incx = *incx_, incy = *incy_, i;
444 #ifdef _MSC_VER
445         _Fcomplex zdotc = {0.0, 0.0};
446         if (incx == 1 && incy == 1) {
447                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
448                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
449                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
450                 }
451         } else {
452                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
453                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
454                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
455                 }
456         }
457         pCf(z) = zdotc;
458 }
459 #else
460         _Complex float zdotc = 0.0;
461         if (incx == 1 && incy == 1) {
462                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
463                         zdotc += Cf(&x[i]) * Cf(&y[i]);
464                 }
465         } else {
466                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
467                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
468                 }
469         }
470         pCf(z) = zdotc;
471 }
472 #endif
473 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
474         integer n = *n_, incx = *incx_, incy = *incy_, i;
475 #ifdef _MSC_VER
476         _Dcomplex zdotc = {0.0, 0.0};
477         if (incx == 1 && incy == 1) {
478                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
479                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
480                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
481                 }
482         } else {
483                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
484                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
485                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
486                 }
487         }
488         pCd(z) = zdotc;
489 }
490 #else
491         _Complex double zdotc = 0.0;
492         if (incx == 1 && incy == 1) {
493                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
494                         zdotc += Cd(&x[i]) * Cd(&y[i]);
495                 }
496         } else {
497                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
498                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
499                 }
500         }
501         pCd(z) = zdotc;
502 }
503 #endif
504 /*  -- translated by f2c (version 20000121).
505    You must link the resulting object file with the libraries:
506         -lf2c -lm   (in that order)
507 */
508
509
510
511
512 /* Table of constant values */
513
514 static integer c__2 = 2;
515 static integer c__1 = 1;
516 static integer c_n1 = -1;
517
518 /* > \brief \b ZLAED7 used by sstedc. Computes the updated eigensystem of a diagonal matrix after modification
519  by a rank-one symmetric matrix. Used when the original matrix is dense. */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download ZLAED7 + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlaed7.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlaed7.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlaed7.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE ZLAED7( N, CUTPNT, QSIZ, TLVLS, CURLVL, CURPBM, D, Q, */
543 /*                          LDQ, RHO, INDXQ, QSTORE, QPTR, PRMPTR, PERM, */
544 /*                          GIVPTR, GIVCOL, GIVNUM, WORK, RWORK, IWORK, */
545 /*                          INFO ) */
546
547 /*       INTEGER            CURLVL, CURPBM, CUTPNT, INFO, LDQ, N, QSIZ, */
548 /*      $                   TLVLS */
549 /*       DOUBLE PRECISION   RHO */
550 /*       INTEGER            GIVCOL( 2, * ), GIVPTR( * ), INDXQ( * ), */
551 /*      $                   IWORK( * ), PERM( * ), PRMPTR( * ), QPTR( * ) */
552 /*       DOUBLE PRECISION   D( * ), GIVNUM( 2, * ), QSTORE( * ), RWORK( * ) */
553 /*       COMPLEX*16         Q( LDQ, * ), WORK( * ) */
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* > ZLAED7 computes the updated eigensystem of a diagonal */
562 /* > matrix after modification by a rank-one symmetric matrix. This */
563 /* > routine is used only for the eigenproblem which requires all */
564 /* > eigenvalues and optionally eigenvectors of a dense or banded */
565 /* > Hermitian matrix that has been reduced to tridiagonal form. */
566 /* > */
567 /* >   T = Q(in) ( D(in) + RHO * Z*Z**H ) Q**H(in) = Q(out) * D(out) * Q**H(out) */
568 /* > */
569 /* >   where Z = Q**Hu, u is a vector of length N with ones in the */
570 /* >   CUTPNT and CUTPNT + 1 th elements and zeros elsewhere. */
571 /* > */
572 /* >    The eigenvectors of the original matrix are stored in Q, and the */
573 /* >    eigenvalues are in D.  The algorithm consists of three stages: */
574 /* > */
575 /* >       The first stage consists of deflating the size of the problem */
576 /* >       when there are multiple eigenvalues or if there is a zero in */
577 /* >       the Z vector.  For each such occurrence the dimension of the */
578 /* >       secular equation problem is reduced by one.  This stage is */
579 /* >       performed by the routine DLAED2. */
580 /* > */
581 /* >       The second stage consists of calculating the updated */
582 /* >       eigenvalues. This is done by finding the roots of the secular */
583 /* >       equation via the routine DLAED4 (as called by SLAED3). */
584 /* >       This routine also calculates the eigenvectors of the current */
585 /* >       problem. */
586 /* > */
587 /* >       The final stage consists of computing the updated eigenvectors */
588 /* >       directly using the updated eigenvalues.  The eigenvectors for */
589 /* >       the current problem are multiplied with the eigenvectors from */
590 /* >       the overall problem. */
591 /* > \endverbatim */
592
593 /*  Arguments: */
594 /*  ========== */
595
596 /* > \param[in] N */
597 /* > \verbatim */
598 /* >          N is INTEGER */
599 /* >         The dimension of the symmetric tridiagonal matrix.  N >= 0. */
600 /* > \endverbatim */
601 /* > */
602 /* > \param[in] CUTPNT */
603 /* > \verbatim */
604 /* >          CUTPNT is INTEGER */
605 /* >         Contains the location of the last eigenvalue in the leading */
606 /* >         sub-matrix.  f2cmin(1,N) <= CUTPNT <= N. */
607 /* > \endverbatim */
608 /* > */
609 /* > \param[in] QSIZ */
610 /* > \verbatim */
611 /* >          QSIZ is INTEGER */
612 /* >         The dimension of the unitary matrix used to reduce */
613 /* >         the full matrix to tridiagonal form.  QSIZ >= N. */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[in] TLVLS */
617 /* > \verbatim */
618 /* >          TLVLS is INTEGER */
619 /* >         The total number of merging levels in the overall divide and */
620 /* >         conquer tree. */
621 /* > \endverbatim */
622 /* > */
623 /* > \param[in] CURLVL */
624 /* > \verbatim */
625 /* >          CURLVL is INTEGER */
626 /* >         The current level in the overall merge routine, */
627 /* >         0 <= curlvl <= tlvls. */
628 /* > \endverbatim */
629 /* > */
630 /* > \param[in] CURPBM */
631 /* > \verbatim */
632 /* >          CURPBM is INTEGER */
633 /* >         The current problem in the current level in the overall */
634 /* >         merge routine (counting from upper left to lower right). */
635 /* > \endverbatim */
636 /* > */
637 /* > \param[in,out] D */
638 /* > \verbatim */
639 /* >          D is DOUBLE PRECISION array, dimension (N) */
640 /* >         On entry, the eigenvalues of the rank-1-perturbed matrix. */
641 /* >         On exit, the eigenvalues of the repaired matrix. */
642 /* > \endverbatim */
643 /* > */
644 /* > \param[in,out] Q */
645 /* > \verbatim */
646 /* >          Q is COMPLEX*16 array, dimension (LDQ,N) */
647 /* >         On entry, the eigenvectors of the rank-1-perturbed matrix. */
648 /* >         On exit, the eigenvectors of the repaired tridiagonal matrix. */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in] LDQ */
652 /* > \verbatim */
653 /* >          LDQ is INTEGER */
654 /* >         The leading dimension of the array Q.  LDQ >= f2cmax(1,N). */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] RHO */
658 /* > \verbatim */
659 /* >          RHO is DOUBLE PRECISION */
660 /* >         Contains the subdiagonal element used to create the rank-1 */
661 /* >         modification. */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[out] INDXQ */
665 /* > \verbatim */
666 /* >          INDXQ is INTEGER array, dimension (N) */
667 /* >         This contains the permutation which will reintegrate the */
668 /* >         subproblem just solved back into sorted order, */
669 /* >         ie. D( INDXQ( I = 1, N ) ) will be in ascending order. */
670 /* > \endverbatim */
671 /* > */
672 /* > \param[out] IWORK */
673 /* > \verbatim */
674 /* >          IWORK is INTEGER array, dimension (4*N) */
675 /* > \endverbatim */
676 /* > */
677 /* > \param[out] RWORK */
678 /* > \verbatim */
679 /* >          RWORK is DOUBLE PRECISION array, */
680 /* >                                 dimension (3*N+2*QSIZ*N) */
681 /* > \endverbatim */
682 /* > */
683 /* > \param[out] WORK */
684 /* > \verbatim */
685 /* >          WORK is COMPLEX*16 array, dimension (QSIZ*N) */
686 /* > \endverbatim */
687 /* > */
688 /* > \param[in,out] QSTORE */
689 /* > \verbatim */
690 /* >          QSTORE is DOUBLE PRECISION array, dimension (N**2+1) */
691 /* >         Stores eigenvectors of submatrices encountered during */
692 /* >         divide and conquer, packed together. QPTR points to */
693 /* >         beginning of the submatrices. */
694 /* > \endverbatim */
695 /* > */
696 /* > \param[in,out] QPTR */
697 /* > \verbatim */
698 /* >          QPTR is INTEGER array, dimension (N+2) */
699 /* >         List of indices pointing to beginning of submatrices stored */
700 /* >         in QSTORE. The submatrices are numbered starting at the */
701 /* >         bottom left of the divide and conquer tree, from left to */
702 /* >         right and bottom to top. */
703 /* > \endverbatim */
704 /* > */
705 /* > \param[in] PRMPTR */
706 /* > \verbatim */
707 /* >          PRMPTR is INTEGER array, dimension (N lg N) */
708 /* >         Contains a list of pointers which indicate where in PERM a */
709 /* >         level's permutation is stored.  PRMPTR(i+1) - PRMPTR(i) */
710 /* >         indicates the size of the permutation and also the size of */
711 /* >         the full, non-deflated problem. */
712 /* > \endverbatim */
713 /* > */
714 /* > \param[in] PERM */
715 /* > \verbatim */
716 /* >          PERM is INTEGER array, dimension (N lg N) */
717 /* >         Contains the permutations (from deflation and sorting) to be */
718 /* >         applied to each eigenblock. */
719 /* > \endverbatim */
720 /* > */
721 /* > \param[in] GIVPTR */
722 /* > \verbatim */
723 /* >          GIVPTR is INTEGER array, dimension (N lg N) */
724 /* >         Contains a list of pointers which indicate where in GIVCOL a */
725 /* >         level's Givens rotations are stored.  GIVPTR(i+1) - GIVPTR(i) */
726 /* >         indicates the number of Givens rotations. */
727 /* > \endverbatim */
728 /* > */
729 /* > \param[in] GIVCOL */
730 /* > \verbatim */
731 /* >          GIVCOL is INTEGER array, dimension (2, N lg N) */
732 /* >         Each pair of numbers indicates a pair of columns to take place */
733 /* >         in a Givens rotation. */
734 /* > \endverbatim */
735 /* > */
736 /* > \param[in] GIVNUM */
737 /* > \verbatim */
738 /* >          GIVNUM is DOUBLE PRECISION array, dimension (2, N lg N) */
739 /* >         Each number indicates the S value to be used in the */
740 /* >         corresponding Givens rotation. */
741 /* > \endverbatim */
742 /* > */
743 /* > \param[out] INFO */
744 /* > \verbatim */
745 /* >          INFO is INTEGER */
746 /* >          = 0:  successful exit. */
747 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
748 /* >          > 0:  if INFO = 1, an eigenvalue did not converge */
749 /* > \endverbatim */
750
751 /*  Authors: */
752 /*  ======== */
753
754 /* > \author Univ. of Tennessee */
755 /* > \author Univ. of California Berkeley */
756 /* > \author Univ. of Colorado Denver */
757 /* > \author NAG Ltd. */
758
759 /* > \date June 2016 */
760
761 /* > \ingroup complex16OTHERcomputational */
762
763 /*  ===================================================================== */
764 /* Subroutine */ int zlaed7_(integer *n, integer *cutpnt, integer *qsiz, 
765         integer *tlvls, integer *curlvl, integer *curpbm, doublereal *d__, 
766         doublecomplex *q, integer *ldq, doublereal *rho, integer *indxq, 
767         doublereal *qstore, integer *qptr, integer *prmptr, integer *perm, 
768         integer *givptr, integer *givcol, doublereal *givnum, doublecomplex *
769         work, doublereal *rwork, integer *iwork, integer *info)
770 {
771     /* System generated locals */
772     integer q_dim1, q_offset, i__1, i__2;
773
774     /* Local variables */
775     integer indx, curr, i__, k, indxc, indxp, n1, n2;
776     extern /* Subroutine */ int dlaed9_(integer *, integer *, integer *, 
777             integer *, doublereal *, doublereal *, integer *, doublereal *, 
778             doublereal *, doublereal *, doublereal *, integer *, integer *), 
779             zlaed8_(integer *, integer *, integer *, doublecomplex *, integer 
780             *, doublereal *, doublereal *, integer *, doublereal *, 
781             doublereal *, doublecomplex *, integer *, doublereal *, integer *,
782              integer *, integer *, integer *, integer *, integer *, 
783             doublereal *, integer *), dlaeda_(integer *, integer *, integer *,
784              integer *, integer *, integer *, integer *, integer *, 
785             doublereal *, doublereal *, integer *, doublereal *, doublereal *,
786              integer *);
787     integer idlmda, iq, iw, iz;
788     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *, 
789             integer *, integer *, integer *), xerbla_(char *, integer *, ftnlen), zlacrm_(integer *, integer *, doublecomplex *, integer *,
790              doublereal *, integer *, doublecomplex *, integer *, doublereal *
791             );
792     integer coltyp, ptr;
793
794
795 /*  -- LAPACK computational routine (version 3.7.0) -- */
796 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
797 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
798 /*     June 2016 */
799
800
801 /*  ===================================================================== */
802
803
804 /*     Test the input parameters. */
805
806     /* Parameter adjustments */
807     --d__;
808     q_dim1 = *ldq;
809     q_offset = 1 + q_dim1 * 1;
810     q -= q_offset;
811     --indxq;
812     --qstore;
813     --qptr;
814     --prmptr;
815     --perm;
816     --givptr;
817     givcol -= 3;
818     givnum -= 3;
819     --work;
820     --rwork;
821     --iwork;
822
823     /* Function Body */
824     *info = 0;
825
826 /*     IF( ICOMPQ.LT.0 .OR. ICOMPQ.GT.1 ) THEN */
827 /*        INFO = -1 */
828 /*     ELSE IF( N.LT.0 ) THEN */
829     if (*n < 0) {
830         *info = -1;
831     } else if (f2cmin(1,*n) > *cutpnt || *n < *cutpnt) {
832         *info = -2;
833     } else if (*qsiz < *n) {
834         *info = -3;
835     } else if (*ldq < f2cmax(1,*n)) {
836         *info = -9;
837     }
838     if (*info != 0) {
839         i__1 = -(*info);
840         xerbla_("ZLAED7", &i__1, (ftnlen)6);
841         return 0;
842     }
843
844 /*     Quick return if possible */
845
846     if (*n == 0) {
847         return 0;
848     }
849
850 /*     The following values are for bookkeeping purposes only.  They are */
851 /*     integer pointers which indicate the portion of the workspace */
852 /*     used by a particular array in DLAED2 and SLAED3. */
853
854     iz = 1;
855     idlmda = iz + *n;
856     iw = idlmda + *n;
857     iq = iw + *n;
858
859     indx = 1;
860     indxc = indx + *n;
861     coltyp = indxc + *n;
862     indxp = coltyp + *n;
863
864 /*     Form the z-vector which consists of the last row of Q_1 and the */
865 /*     first row of Q_2. */
866
867     ptr = pow_ii(&c__2, tlvls) + 1;
868     i__1 = *curlvl - 1;
869     for (i__ = 1; i__ <= i__1; ++i__) {
870         i__2 = *tlvls - i__;
871         ptr += pow_ii(&c__2, &i__2);
872 /* L10: */
873     }
874     curr = ptr + *curpbm;
875     dlaeda_(n, tlvls, curlvl, curpbm, &prmptr[1], &perm[1], &givptr[1], &
876             givcol[3], &givnum[3], &qstore[1], &qptr[1], &rwork[iz], &rwork[
877             iz + *n], info);
878
879 /*     When solving the final problem, we no longer need the stored data, */
880 /*     so we will overwrite the data from this level onto the previously */
881 /*     used storage space. */
882
883     if (*curlvl == *tlvls) {
884         qptr[curr] = 1;
885         prmptr[curr] = 1;
886         givptr[curr] = 1;
887     }
888
889 /*     Sort and Deflate eigenvalues. */
890
891     zlaed8_(&k, n, qsiz, &q[q_offset], ldq, &d__[1], rho, cutpnt, &rwork[iz], 
892             &rwork[idlmda], &work[1], qsiz, &rwork[iw], &iwork[indxp], &iwork[
893             indx], &indxq[1], &perm[prmptr[curr]], &givptr[curr + 1], &givcol[
894             (givptr[curr] << 1) + 1], &givnum[(givptr[curr] << 1) + 1], info);
895     prmptr[curr + 1] = prmptr[curr] + *n;
896     givptr[curr + 1] += givptr[curr];
897
898 /*     Solve Secular Equation. */
899
900     if (k != 0) {
901         dlaed9_(&k, &c__1, &k, n, &d__[1], &rwork[iq], &k, rho, &rwork[idlmda]
902                 , &rwork[iw], &qstore[qptr[curr]], &k, info);
903         zlacrm_(qsiz, &k, &work[1], qsiz, &qstore[qptr[curr]], &k, &q[
904                 q_offset], ldq, &rwork[iq]);
905 /* Computing 2nd power */
906         i__1 = k;
907         qptr[curr + 1] = qptr[curr] + i__1 * i__1;
908         if (*info != 0) {
909             return 0;
910         }
911
912 /*     Prepare the INDXQ sorting premutation. */
913
914         n1 = k;
915         n2 = *n - k;
916         dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
917     } else {
918         qptr[curr + 1] = qptr[curr];
919         i__1 = *n;
920         for (i__ = 1; i__ <= i__1; ++i__) {
921             indxq[i__] = i__;
922 /* L20: */
923         }
924     }
925
926     return 0;
927
928 /*     End of ZLAED7 */
929
930 } /* zlaed7_ */
931