Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / dlaed7.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__2 = 2;
6 static integer c__1 = 1;
7 static doublereal c_b10 = 1.;
8 static doublereal c_b11 = 0.;
9 static integer c_n1 = -1;
10
11 /* Subroutine */ int dlaed7_(integer *icompq, integer *n, integer *qsiz, 
12         integer *tlvls, integer *curlvl, integer *curpbm, doublereal *d__, 
13         doublereal *q, integer *ldq, integer *indxq, doublereal *rho, integer 
14         *cutpnt, doublereal *qstore, integer *qptr, integer *prmptr, integer *
15         perm, integer *givptr, integer *givcol, doublereal *givnum, 
16         doublereal *work, integer *iwork, integer *info)
17 {
18     /* System generated locals */
19     integer q_dim1, q_offset, i__1, i__2;
20
21     /* Builtin functions */
22     integer pow_ii(integer *, integer *);
23
24     /* Local variables */
25     integer i__, k, n1, n2, is, iw, iz, iq2, ptr, ldq2, indx, curr;
26     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, 
27             integer *, doublereal *, doublereal *, integer *, doublereal *, 
28             integer *, doublereal *, doublereal *, integer *);
29     integer indxc, indxp;
30     extern /* Subroutine */ int dlaed8_(integer *, integer *, integer *, 
31             integer *, doublereal *, doublereal *, integer *, integer *, 
32             doublereal *, integer *, doublereal *, doublereal *, doublereal *, 
33              integer *, doublereal *, integer *, integer *, integer *, 
34             doublereal *, integer *, integer *, integer *), dlaed9_(integer *, 
35              integer *, integer *, integer *, doublereal *, doublereal *, 
36             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
37              integer *, integer *), dlaeda_(integer *, integer *, integer *, 
38             integer *, integer *, integer *, integer *, integer *, doublereal 
39             *, doublereal *, integer *, doublereal *, doublereal *, integer *)
40             ;
41     integer idlmda;
42     extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *, 
43             integer *, integer *, integer *), xerbla_(char *, integer *);
44     integer coltyp;
45
46
47 /*  -- LAPACK routine (version 3.1) -- */
48 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
49 /*     November 2006 */
50
51 /*     .. Scalar Arguments .. */
52 /*     .. */
53 /*     .. Array Arguments .. */
54 /*     .. */
55
56 /*  Purpose */
57 /*  ======= */
58
59 /*  DLAED7 computes the updated eigensystem of a diagonal */
60 /*  matrix after modification by a rank-one symmetric matrix. This */
61 /*  routine is used only for the eigenproblem which requires all */
62 /*  eigenvalues and optionally eigenvectors of a dense symmetric matrix */
63 /*  that has been reduced to tridiagonal form.  DLAED1 handles */
64 /*  the case in which all eigenvalues and eigenvectors of a symmetric */
65 /*  tridiagonal matrix are desired. */
66
67 /*    T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out) */
68
69 /*     where Z = Q'u, u is a vector of length N with ones in the */
70 /*     CUTPNT and CUTPNT + 1 th elements and zeros elsewhere. */
71
72 /*     The eigenvectors of the original matrix are stored in Q, and the */
73 /*     eigenvalues are in D.  The algorithm consists of three stages: */
74
75 /*        The first stage consists of deflating the size of the problem */
76 /*        when there are multiple eigenvalues or if there is a zero in */
77 /*        the Z vector.  For each such occurence the dimension of the */
78 /*        secular equation problem is reduced by one.  This stage is */
79 /*        performed by the routine DLAED8. */
80
81 /*        The second stage consists of calculating the updated */
82 /*        eigenvalues. This is done by finding the roots of the secular */
83 /*        equation via the routine DLAED4 (as called by DLAED9). */
84 /*        This routine also calculates the eigenvectors of the current */
85 /*        problem. */
86
87 /*        The final stage consists of computing the updated eigenvectors */
88 /*        directly using the updated eigenvalues.  The eigenvectors for */
89 /*        the current problem are multiplied with the eigenvectors from */
90 /*        the overall problem. */
91
92 /*  Arguments */
93 /*  ========= */
94
95 /*  ICOMPQ  (input) INTEGER */
96 /*          = 0:  Compute eigenvalues only. */
97 /*          = 1:  Compute eigenvectors of original dense symmetric matrix */
98 /*                also.  On entry, Q contains the orthogonal matrix used */
99 /*                to reduce the original matrix to tridiagonal form. */
100
101 /*  N      (input) INTEGER */
102 /*         The dimension of the symmetric tridiagonal matrix.  N >= 0. */
103
104 /*  QSIZ   (input) INTEGER */
105 /*         The dimension of the orthogonal matrix used to reduce */
106 /*         the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1. */
107
108 /*  TLVLS  (input) INTEGER */
109 /*         The total number of merging levels in the overall divide and */
110 /*         conquer tree. */
111
112 /*  CURLVL (input) INTEGER */
113 /*         The current level in the overall merge routine, */
114 /*         0 <= CURLVL <= TLVLS. */
115
116 /*  CURPBM (input) INTEGER */
117 /*         The current problem in the current level in the overall */
118 /*         merge routine (counting from upper left to lower right). */
119
120 /*  D      (input/output) DOUBLE PRECISION array, dimension (N) */
121 /*         On entry, the eigenvalues of the rank-1-perturbed matrix. */
122 /*         On exit, the eigenvalues of the repaired matrix. */
123
124 /*  Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N) */
125 /*         On entry, the eigenvectors of the rank-1-perturbed matrix. */
126 /*         On exit, the eigenvectors of the repaired tridiagonal matrix. */
127
128 /*  LDQ    (input) INTEGER */
129 /*         The leading dimension of the array Q.  LDQ >= max(1,N). */
130
131 /*  INDXQ  (output) INTEGER array, dimension (N) */
132 /*         The permutation which will reintegrate the subproblem just */
133 /*         solved back into sorted order, i.e., D( INDXQ( I = 1, N ) ) */
134 /*         will be in ascending order. */
135
136 /*  RHO    (input) DOUBLE PRECISION */
137 /*         The subdiagonal element used to create the rank-1 */
138 /*         modification. */
139
140 /*  CUTPNT (input) INTEGER */
141 /*         Contains the location of the last eigenvalue in the leading */
142 /*         sub-matrix.  min(1,N) <= CUTPNT <= N. */
143
144 /*  QSTORE (input/output) DOUBLE PRECISION array, dimension (N**2+1) */
145 /*         Stores eigenvectors of submatrices encountered during */
146 /*         divide and conquer, packed together. QPTR points to */
147 /*         beginning of the submatrices. */
148
149 /*  QPTR   (input/output) INTEGER array, dimension (N+2) */
150 /*         List of indices pointing to beginning of submatrices stored */
151 /*         in QSTORE. The submatrices are numbered starting at the */
152 /*         bottom left of the divide and conquer tree, from left to */
153 /*         right and bottom to top. */
154
155 /*  PRMPTR (input) INTEGER array, dimension (N lg N) */
156 /*         Contains a list of pointers which indicate where in PERM a */
157 /*         level's permutation is stored.  PRMPTR(i+1) - PRMPTR(i) */
158 /*         indicates the size of the permutation and also the size of */
159 /*         the full, non-deflated problem. */
160
161 /*  PERM   (input) INTEGER array, dimension (N lg N) */
162 /*         Contains the permutations (from deflation and sorting) to be */
163 /*         applied to each eigenblock. */
164
165 /*  GIVPTR (input) INTEGER array, dimension (N lg N) */
166 /*         Contains a list of pointers which indicate where in GIVCOL a */
167 /*         level's Givens rotations are stored.  GIVPTR(i+1) - GIVPTR(i) */
168 /*         indicates the number of Givens rotations. */
169
170 /*  GIVCOL (input) INTEGER array, dimension (2, N lg N) */
171 /*         Each pair of numbers indicates a pair of columns to take place */
172 /*         in a Givens rotation. */
173
174 /*  GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N) */
175 /*         Each number indicates the S value to be used in the */
176 /*         corresponding Givens rotation. */
177
178 /*  WORK   (workspace) DOUBLE PRECISION array, dimension (3*N+QSIZ*N) */
179
180 /*  IWORK  (workspace) INTEGER array, dimension (4*N) */
181
182 /*  INFO   (output) INTEGER */
183 /*          = 0:  successful exit. */
184 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
185 /*          > 0:  if INFO = 1, an eigenvalue did not converge */
186
187 /*  Further Details */
188 /*  =============== */
189
190 /*  Based on contributions by */
191 /*     Jeff Rutter, Computer Science Division, University of California */
192 /*     at Berkeley, USA */
193
194 /*  ===================================================================== */
195
196 /*     .. Parameters .. */
197 /*     .. */
198 /*     .. Local Scalars .. */
199 /*     .. */
200 /*     .. External Subroutines .. */
201 /*     .. */
202 /*     .. Intrinsic Functions .. */
203 /*     .. */
204 /*     .. Executable Statements .. */
205
206 /*     Test the input parameters. */
207
208     /* Parameter adjustments */
209     --d__;
210     q_dim1 = *ldq;
211     q_offset = 1 + q_dim1;
212     q -= q_offset;
213     --indxq;
214     --qstore;
215     --qptr;
216     --prmptr;
217     --perm;
218     --givptr;
219     givcol -= 3;
220     givnum -= 3;
221     --work;
222     --iwork;
223
224     /* Function Body */
225     *info = 0;
226
227     if (*icompq < 0 || *icompq > 1) {
228         *info = -1;
229     } else if (*n < 0) {
230         *info = -2;
231     } else if (*icompq == 1 && *qsiz < *n) {
232         *info = -4;
233     } else if (*ldq < max(1,*n)) {
234         *info = -9;
235     } else if (min(1,*n) > *cutpnt || *n < *cutpnt) {
236         *info = -12;
237     }
238     if (*info != 0) {
239         i__1 = -(*info);
240         xerbla_("DLAED7", &i__1);
241         return 0;
242     }
243
244 /*     Quick return if possible */
245
246     if (*n == 0) {
247         return 0;
248     }
249
250 /*     The following values are for bookkeeping purposes only.  They are */
251 /*     integer pointers which indicate the portion of the workspace */
252 /*     used by a particular array in DLAED8 and DLAED9. */
253
254     if (*icompq == 1) {
255         ldq2 = *qsiz;
256     } else {
257         ldq2 = *n;
258     }
259
260     iz = 1;
261     idlmda = iz + *n;
262     iw = idlmda + *n;
263     iq2 = iw + *n;
264     is = iq2 + *n * ldq2;
265
266     indx = 1;
267     indxc = indx + *n;
268     coltyp = indxc + *n;
269     indxp = coltyp + *n;
270
271 /*     Form the z-vector which consists of the last row of Q_1 and the */
272 /*     first row of Q_2. */
273
274     ptr = pow_ii(&c__2, tlvls) + 1;
275     i__1 = *curlvl - 1;
276     for (i__ = 1; i__ <= i__1; ++i__) {
277         i__2 = *tlvls - i__;
278         ptr += pow_ii(&c__2, &i__2);
279 /* L10: */
280     }
281     curr = ptr + *curpbm;
282     dlaeda_(n, tlvls, curlvl, curpbm, &prmptr[1], &perm[1], &givptr[1], &
283             givcol[3], &givnum[3], &qstore[1], &qptr[1], &work[iz], &work[iz 
284             + *n], info);
285
286 /*     When solving the final problem, we no longer need the stored data, */
287 /*     so we will overwrite the data from this level onto the previously */
288 /*     used storage space. */
289
290     if (*curlvl == *tlvls) {
291         qptr[curr] = 1;
292         prmptr[curr] = 1;
293         givptr[curr] = 1;
294     }
295
296 /*     Sort and Deflate eigenvalues. */
297
298     dlaed8_(icompq, &k, n, qsiz, &d__[1], &q[q_offset], ldq, &indxq[1], rho, 
299             cutpnt, &work[iz], &work[idlmda], &work[iq2], &ldq2, &work[iw], &
300             perm[prmptr[curr]], &givptr[curr + 1], &givcol[(givptr[curr] << 1)
301              + 1], &givnum[(givptr[curr] << 1) + 1], &iwork[indxp], &iwork[
302             indx], info);
303     prmptr[curr + 1] = prmptr[curr] + *n;
304     givptr[curr + 1] += givptr[curr];
305
306 /*     Solve Secular Equation. */
307
308     if (k != 0) {
309         dlaed9_(&k, &c__1, &k, n, &d__[1], &work[is], &k, rho, &work[idlmda], 
310                 &work[iw], &qstore[qptr[curr]], &k, info);
311         if (*info != 0) {
312             goto L30;
313         }
314         if (*icompq == 1) {
315             dgemm_("N", "N", qsiz, &k, &k, &c_b10, &work[iq2], &ldq2, &qstore[
316                     qptr[curr]], &k, &c_b11, &q[q_offset], ldq);
317         }
318 /* Computing 2nd power */
319         i__1 = k;
320         qptr[curr + 1] = qptr[curr] + i__1 * i__1;
321
322 /*     Prepare the INDXQ sorting permutation. */
323
324         n1 = k;
325         n2 = *n - k;
326         dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
327     } else {
328         qptr[curr + 1] = qptr[curr];
329         i__1 = *n;
330         for (i__ = 1; i__ <= i__1; ++i__) {
331             indxq[i__] = i__;
332 /* L20: */
333         }
334     }
335
336 L30:
337     return 0;
338
339 /*     End of DLAED7 */
340
341 } /* dlaed7_ */