Debian Codegraph @

packages/seacas/libraries/chaco/eigen/lanczos_SO_float.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8
9 #include "defs.h" // for TRUE, FALSE, min, max
10 #include "smalloc.h" // for sfree, smalloc
11 #include "structs.h" // for scanlink, orthlink_float
12 #include <math.h> // for sqrt
13 #include <stdio.h> // for printf, NULL, FILE
14
15 /* See comments in lanczos_SO() */
16
17 void lanczos_SO_float(struct vtx_data **A, /* sparse matrix in row linked list format */
18 int n, /* problem size */
19 int d, /* problem dimension = number of eigvecs to find */
20 double **y, /* columns of y are eigenvectors of A */
21 double *lambda, /* ritz approximation to eigenvals of A */
22 double *bound, /* on ritz pair approximations to eig pairs of A */
23 double eigtol, /* tolerance on eigenvectors */
24 double *vwsqrt, /* square roots of vertex weights */
25 double maxdeg, /* maximum degree of graph */
26 int version, /* flags which version of sel. orth. to use */
27 int cube_or_mesh, /* 0 => hypercube, d => d-dimensional mesh */
28 int nsets, /* number of sets to divide into */
29 int *assignment, /* set number of each vtx (length n+1) */
30 int *active, /* space for nvtxs integers */
31 int mediantype, /* which partitioning strategy to use */
32 double *goal, /* desired set sizes */
33 int vwgt_max /* largest vertex weight */
34 )
35 {
36 extern FILE *Output_File; /* output file or null */
37 extern int LANCZOS_SO_INTERVAL; /* interval between orthogonalizations */
38 extern int LANCZOS_CONVERGENCE_MODE; /* type of Lanczos convergence test */
39 extern int LANCZOS_MAXITNS; /* maximum Lanczos iterations allowed */
40 extern int DEBUG_EVECS; /* print debugging output? */
41 extern int DEBUG_TRACE; /* trace main execution path */
42 extern int WARNING_EVECS; /* print warning messages? */
43 extern double BISECTION_SAFETY; /* safety factor for T bisection */
44 extern double SRESTOL; /* resid tol for T evec comp */
45 extern double DOUBLE_EPSILON; /* machine precision */
46 extern double DOUBLE_MAX; /* largest double value */
47 extern double splarax_time; /* time matvec */
48 extern double orthog_time; /* time orthogonalization work */
49 extern double evec_time; /* time to generate eigenvectors */
50 extern double ql_time; /* time tridiagonal eigenvalue work */
51 extern double blas_time; /* time for blas. linear algebra */
52 extern double init_time; /* time to allocate, initialize variables */
53 extern double scan_time; /* time for scanning eval and bound lists */
54 extern double debug_time; /* time for (some of) debug computations */
55 extern double ritz_time; /* time to generate ritz vectors */
56 extern double pause_time; /* time to compute whether to pause */
57 double bis_safety; /* real safety factor for T bisection */
58 int i, j, k; /* indices */
59 int maxj; /* maximum number of Lanczos iterations */
60 float *u, *r; /* Lanczos vectors */
61 double *u_double; /* double version of u */
62 double *alpha, *beta; /* the Lanczos scalars from each step */
63 double *ritz; /* copy of alpha for ql */
64 double *workj; /* work vector, e.g. copy of beta for ql */
65 float *workn; /* work vector, e.g. product Av for checkeig */
66 double *workn_double; /* work vector, e.g. product Av for checkeig */
67 double *s; /* eigenvector of T */
68 float **q; /* columns of q are Lanczos basis vectors */
69 double *bj; /* beta(j)*(last el. of corr. eigvec s of T) */
70 double Sres; /* how well Tevec calculated eigvec s */
71 double Sres_max; /* Max value of Sres */
72 int inc_bis_safety; /* need to increase bisection safety */
73 double *Ares; /* how well Lanczos calc. eigpair lambda,y */
74 int *index; /* the Ritz index of an eigenpair */
75 struct orthlink_float **solist; /* vec. of structs with vecs. to orthog. against */
76 struct scanlink *scanlist; /* linked list of fields to do with min ritz vals */
77 struct scanlink *curlnk; /* for traversing the scanlist */
78 double bji_tol; /* tol on bji est. of eigen residual of A */
79 int converged; /* has the iteration converged? */
80 double goodtol; /* error tolerance for a good Ritz vector */
81 int ngood; /* total number of good Ritz pairs at current step */
82 int maxngood; /* biggest val of ngood through current step */
83 int left_ngood; /* number of good Ritz pairs on left end */
84 int right_ngood; /* number of good Ritz pairs on right end */
85 int lastpause; /* Most recent step with good ritz vecs */
86 int firstpause; /* Is this the first pause? */
87 int nopauses; /* Have there been any pauses? */
88 int interval; /* number of steps between pauses */
89 double time; /* Current clock time */
90 int left_goodlim; /* number of ritz pairs checked on left end */
91 int right_goodlim; /* number of ritz pairs checked on right end */
92 double Anorm; /* Norm estimate of the Laplacian matrix */
93 int pausemode; /* which Lanczos pausing criterion to use */
94 int pause; /* whether to pause */
95 int temp; /* used to prevent redundant index computations */
96 int *old_assignment = NULL; /* set # of each vtx on previous pause, length n+1 */
97 int *assgn_pntr; /* pntr to assignment vector */
98 int *old_assgn_pntr; /* pntr to previous assignment vector */
99 int assigndiff; /* # of differences between old and new assignment */
100 int assigntol; /* tolerance on convergence of assignment vector */
101 int ritzval_flag; /* status flag for get_ritzvals() */
102 int memory_ok; /* True until lanczos runs out of memory */
103 float *vwsqrt_float; /* float version of vwsqrt */
104
105 if (DEBUG_TRACE > 0) {
106 printf("<Entering lanczos_so_float>\n");
107 }
108
109 if (DEBUG_EVECS > 0) {
110 printf("Selective orthogonalization Lanczos (v. %d), matrix size = %d.\n", version, n);
111 }
112
113 /* Initialize time. */
114 time = lanc_seconds();
115
116 if (n < d + 1) {
117 bail("ERROR: System too small for number of eigenvalues requested.", 1);
118 /* d+1 since don't use zero eigenvalue pair */
119 }
120
121 /* Allocate space. */
122 maxj = LANCZOS_MAXITNS;
123 u = mkvec_float(1, n);
124 u_double = mkvec(1, n);
125 r = mkvec_float(1, n);
126 workn = mkvec_float(1, n);
127 workn_double = mkvec(1, n);
128 Ares = mkvec(0, d);
129 index = smalloc((d + 1) * sizeof(int));
130 alpha = mkvec(1, maxj);
131 beta = mkvec(0, maxj);
132 ritz = mkvec(1, maxj);
133 s = mkvec(1, maxj);
134 bj = mkvec(1, maxj);
135 workj = mkvec(0, maxj);
136 q = smalloc((maxj + 1) * sizeof(float *));
137 solist = smalloc((maxj + 1) * sizeof(struct orthlink_float *));
138 scanlist = mkscanlist(d);
139 if (LANCZOS_CONVERGENCE_MODE == 1) {
140 old_assignment = smalloc((n + 1) * sizeof(int));
141 }
142
143 /* Set some constants governing the orthogonalization heuristic. */
144 ngood = 0;
145 maxngood = 0;
146 bji_tol = eigtol;
147 assigntol = eigtol * n;
148 Anorm = 2 * maxdeg; /* Gershgorin estimate for ||A|| */
149 goodtol = Anorm * sqrt(DOUBLE_EPSILON); /* Parlett & Scott's bound, p.224 */
150 interval = 2 + min(LANCZOS_SO_INTERVAL - 2, n / (2 * LANCZOS_SO_INTERVAL));
151 bis_safety = BISECTION_SAFETY;
152
153 if (DEBUG_EVECS > 0) {
154 printf(" maxdeg %g\n", maxdeg);
155 printf(" goodtol %g\n", goodtol);
156 printf(" interval %d\n", interval);
157 printf(" maxj %d\n", maxj);
158 if (LANCZOS_CONVERGENCE_MODE == 1) {
159 printf(" assigntol %d\n", assigntol);
160 }
161 }
162
163 /* Make a float copy of vwsqrt */
164 if (vwsqrt == NULL) {
165 vwsqrt_float = NULL;
166 }
167 else {
168 vwsqrt_float = mkvec_float(0, n);
169 double_to_float(vwsqrt_float, 1, n, vwsqrt);
170 }
171
172 /* Initialize space. */
173 vecran_float(r, 1, n);
174 if (vwsqrt_float == NULL) {
175 orthog1_float(r, 1, n);
176 }
177 else {
178 orthogvec_float(r, 1, n, vwsqrt_float);
179 }
180 beta[0] = norm_float(r, 1, n);
181 q[0] = mkvec_float(1, n);
182 setvec_float(q[0], 1, n, 0.0);
183 setvec(bj, 1, maxj, DOUBLE_MAX);
184
185 /* Main Lanczos loop. */
186 j = 1;
187 lastpause = 0;
188 pausemode = 1;
189 left_ngood = 0;
190 right_ngood = 0;
191 left_goodlim = 0;
192 right_goodlim = 0;
193 converged = FALSE;
194 Sres_max = 0.0;
195 inc_bis_safety = FALSE;
196 ritzval_flag = 0;
197 memory_ok = TRUE;
198 firstpause = FALSE;
199 nopauses = TRUE;
200 init_time += lanc_seconds() - time;
201 while ((j <= maxj) && (!converged) && (ritzval_flag == 0) && memory_ok) {
202 time = lanc_seconds();
203
204 /* Allocate next Lanczos vector. If fail, back up to last pause. */
205 q[j] = mkvec_ret_float(1, n);
206 if (q[j] == NULL) {
207 memory_ok = FALSE;
208 if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) {
209 strout("WARNING: Lanczos out of memory; computing best approximation available.\n");
210 }
211 if (nopauses) {
212 bail("ERROR: Sorry, can't salvage Lanczos.", 1);
213 /* ... save yourselves, men. */
214 }
215 for (i = lastpause + 1; i <= j - 1; i++) {
216 frvec_float(q[i], 1);
217 }
218 j = lastpause;
219 }
220
221 vecscale_float(q[j], 1, n, (float)(1.0 / beta[j - 1]), r);
222 blas_time += lanc_seconds() - time;
223 time = lanc_seconds();
224 splarax_float(u, A, n, q[j], vwsqrt_float, workn);
225 splarax_time += lanc_seconds() - time;
226 time = lanc_seconds();
227 update_float(r, 1, n, u, (float)(-beta[j - 1]), q[j - 1]);
228 alpha[j] = dot_float(r, 1, n, q[j]);
229 update_float(r, 1, n, r, (float)(-alpha[j]), q[j]);
230 blas_time += lanc_seconds() - time;
231 time = lanc_seconds();
232 if (vwsqrt_float == NULL) {
233 orthog1_float(r, 1, n);
234 }
235 else {
236 orthogvec_float(r, 1, n, vwsqrt_float);
237 }
238 if ((j == (lastpause + 1)) || (j == (lastpause + 2))) {
239 sorthog_float(r, n, solist, ngood);
240 }
241 orthog_time += lanc_seconds() - time;
242 beta[j] = norm_float(r, 1, n);
243 time = lanc_seconds();
244 pause = lanpause_float(j, lastpause, interval, q, n, &pausemode, version, beta[j]);
245 pause_time += lanc_seconds() - time;
246 if (pause) {
247 nopauses = FALSE;
248 if (lastpause == 0) {
249 firstpause = TRUE;
250 }
251 else {
252 firstpause = FALSE;
253 }
254 lastpause = j;
255
256 /* Compute limits for checking Ritz pair convergence. */
257 if (version == 1) {
258 if (left_ngood + 2 > left_goodlim) {
259 left_goodlim = left_ngood + 2;
260 }
261 if (right_ngood + 3 > right_goodlim) {
262 right_goodlim = right_ngood + 3;
263 }
264 }
265 if (version == 2) {
266 if (left_ngood + 2 > left_goodlim) {
267 left_goodlim = left_ngood + 2;
268 }
269 right_goodlim = 0;
270 }
271
272 /* Special case: need at least d Ritz vals on left. */
273 left_goodlim = max(left_goodlim, d);
274
275 /* Special case: can't find more than j total Ritz vals. */
276 if (left_goodlim + right_goodlim > j) {
277 left_goodlim = min(left_goodlim, j);
278 right_goodlim = j - left_goodlim;
279 }
280
281 /* Find Ritz vals using faster of Sturm bisection or QL. */
282 time = lanc_seconds();
283 blas_time += lanc_seconds() - time;
284 time = lanc_seconds();
285 if (inc_bis_safety) {
286 bis_safety *= 10;
287 inc_bis_safety = FALSE;
288 }
289 ritzval_flag = get_ritzvals(alpha, beta, j, Anorm, workj, ritz, d, left_goodlim,
290 right_goodlim, eigtol, bis_safety);
291 ql_time += lanc_seconds() - time;
292
293 /* If get_ritzvals() fails, back up to last pause point and exit main loop. */
294 if (ritzval_flag != 0) {
295 if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) {
296 strout("ERROR: Lanczos failed in computing eigenvalues of T; computing");
297 strout(" best readily available approximation to eigenvector.\n");
298 }
299 if (firstpause) {
300 bail("ERROR: Sorry, can't salvage Lanczos.", 1);
301 /* ... save yourselves, men. */
302 }
303 for (i = lastpause + 1; i <= j; i++) {
304 frvec_float(q[i], 1);
305 }
306 j = lastpause;
307 get_ritzvals(alpha, beta, j, Anorm, workj, ritz, d, left_goodlim, right_goodlim, eigtol,
308 bis_safety);
309 }
310
311 /* Scan for minimum evals of tridiagonal. */
312 time = lanc_seconds();
313 scanmin(ritz, 1, j, &scanlist);
314 scan_time += lanc_seconds() - time;
315
316 /* Compute Ritz pair bounds at left end. */
317 time = lanc_seconds();
318 setvec(bj, 1, j, 0.0);
319 for (i = 1; i <= left_goodlim; i++) {
320 Sres = Tevec(alpha, beta - 1, j, ritz[i], s);
321 if (Sres > Sres_max) {
322 Sres_max = Sres;
323 }
324 if (Sres > SRESTOL) {
325 inc_bis_safety = TRUE;
326 }
327 bj[i] = s[j] * beta[j];
328 }
329
330 /* Compute Ritz pair bounds at right end. */
331 for (i = j; i > j - right_goodlim; i--) {
332 Sres = Tevec(alpha, beta - 1, j, ritz[i], s);
333 if (Sres > Sres_max) {
334 Sres_max = Sres;
335 }
336 if (Sres > SRESTOL) {
337 inc_bis_safety = TRUE;
338 }
339 bj[i] = s[j] * beta[j];
340 }
341 ritz_time += lanc_seconds() - time;
342
343 /* Show the portion of the spectrum checked for convergence. */
344 if (DEBUG_EVECS > 2) {
345 time = lanc_seconds();
346 printf("index Ritz vals bji bounds (j = %d)\n", j);
347 for (i = 1; i <= left_goodlim; i++) {
348 printf(" %3d", i);
349 doubleout(ritz[i], 1);
350 doubleout(bj[i], 1);
351 printf("\n");
352 }
353 printf("\n");
354 curlnk = scanlist;
355 while (curlnk != NULL) {
356 temp = curlnk->indx;
357 if ((temp > left_goodlim) && (temp < j - right_goodlim)) {
358 printf(" %3d", temp);
359 doubleout(ritz[temp], 1);
360 doubleout(bj[temp], 1);
361 printf("\n");
362 }
363 curlnk = curlnk->pntr;
364 }
365 printf("\n");
366 for (i = j - right_goodlim + 1; i <= j; i++) {
367 printf(" %3d", i);
368 doubleout(ritz[i], 1);
369 doubleout(bj[i], 1);
370 printf("\n");
371 }
372 printf(" -------------------\n");
373 printf(" goodtol: %19.16f\n\n", goodtol);
374 debug_time += lanc_seconds() - time;
375 }
376
377 /* Check for convergence. */
378 time = lanc_seconds();
379 if (LANCZOS_CONVERGENCE_MODE != 1 || d > 1) {
380 /* check convergence of residual bound */
381 converged = TRUE;
382 if (j < d) {
383 converged = FALSE;
384 }
385 else {
386 curlnk = scanlist;
387 while (curlnk != NULL) {
388 if (bj[curlnk->indx] > bji_tol) {
389 converged = FALSE;
390 }
391 curlnk = curlnk->pntr;
392 }
393 }
394 }
395 if (LANCZOS_CONVERGENCE_MODE == 1 && d == 1) {
396 /* check change in partition */
397 if (firstpause) {
398 converged = TRUE;
399 if (j < d) {
400 converged = FALSE;
401 }
402 else {
403 curlnk = scanlist;
404 while (curlnk != NULL) {
405 if (bj[curlnk->indx] > bji_tol) {
406 converged = FALSE;
407 }
408 curlnk = curlnk->pntr;
409 }
410 }
411 if (!converged) {
412 /* compute current approx. to eigenvectors */
413 i = d;
414 curlnk = scanlist;
415 while (curlnk != NULL) {
416 lambda[i] = curlnk->val;
417 bound[i] = bj[curlnk->indx];
418 index[i] = curlnk->indx;
419 curlnk = curlnk->pntr;
420 i--;
421 }
422 for (i = 1; i <= d; i++) {
423 Sres = Tevec(alpha, beta - 1, j, lambda[i], s);
424 if (Sres > Sres_max) {
425 Sres_max = Sres;
426 }
427 if (Sres > SRESTOL) {
428 inc_bis_safety = TRUE;
429 }
430 setvec(y[i], 1, n, 0.0);
431 for (k = 1; k <= j; k++) {
432 scadd_mixed(y[i], 1, n, s[k], q[k]);
433 }
434 }
435 assign(A, y, n, d, cube_or_mesh, nsets, vwsqrt, assignment, active, mediantype, goal,
436 vwgt_max);
437 }
438 }
439 else {
440 /* copy assignment to old_assignment */
441 assgn_pntr = assignment;
442 old_assgn_pntr = old_assignment;
443 for (i = n + 1; i; i--) {
444 *old_assgn_pntr++ = *assgn_pntr++;
445 }
446
447 /* compute current approx. to eigenvectors */
448 i = d;
449 curlnk = scanlist;
450 while (curlnk != NULL) {
451 lambda[i] = curlnk->val;
452 bound[i] = bj[curlnk->indx];
453 index[i] = curlnk->indx;
454 curlnk = curlnk->pntr;
455 i--;
456 }
457 for (i = 1; i <= d; i++) {
458 Sres = Tevec(alpha, beta - 1, j, lambda[i], s);
459 if (Sres > Sres_max) {
460 Sres_max = Sres;
461 }
462 if (Sres > SRESTOL) {
463 inc_bis_safety = TRUE;
464 }
465 setvec(y[i], 1, n, 0.0);
466 for (k = 1; k <= j; k++) {
467 scadd_mixed(y[i], 1, n, s[k], q[k]);
468 }
469 }
470
471 /* write new assignment */
472 assign(A, y, n, d, cube_or_mesh, nsets, vwsqrt, assignment, active, mediantype, goal,
473 vwgt_max);
474
475 assigndiff = 0;
476 assgn_pntr = assignment;
477 old_assgn_pntr = old_assignment;
478 for (i = n + 1; i; i--) {
479 if (*old_assgn_pntr++ != *assgn_pntr++) {
480 assigndiff++;
481 }
482 }
483 assigndiff = min(assigndiff, n - assigndiff);
484 if (DEBUG_EVECS > 1) {
485 printf(" j %d, change from last assignment %d\n\n", j, assigndiff);
486 }
487
488 if (assigndiff <= assigntol) {
489 converged = TRUE;
490 }
491 else {
492 converged = FALSE;
493 }
494 }
495 }
496 scan_time += lanc_seconds() - time;
497
498 /* Show current estimates of evals and bounds (for help in tuning) */
499 if (DEBUG_EVECS > 2 && !converged) {
500 time = lanc_seconds();
501 /* Collect eigenvalue and bound information for display, return. */
502 i = d;
503 curlnk = scanlist;
504 while (curlnk != NULL) {
505 lambda[i] = curlnk->val;
506 bound[i] = bj[curlnk->indx];
507 index[i] = curlnk->indx;
508 curlnk = curlnk->pntr;
509 i--;
510 }
511
512 /* Compute eigenvectors and display associated info. */
513 printf("j %4d; lambda Ares est. Ares index\n", j);
514 for (i = 1; i <= d; i++) {
515 Sres = Tevec(alpha, beta - 1, j, lambda[i], s);
516 if (Sres > Sres_max) {
517 Sres_max = Sres;
518 }
519 if (Sres > SRESTOL) {
520 inc_bis_safety = TRUE;
521 }
522 setvec(y[i], 1, n, 0.0);
523 for (k = 1; k <= j; k++) {
524 scadd_mixed(y[i], 1, n, s[k], q[k]);
525 }
526 float_to_double(u_double, 1, n, u);
527 Ares[i] = checkeig(workn_double, A, y[i], n, lambda[i], vwsqrt, u_double);
528 printf("%2d.", i);
529 doubleout(lambda[i], 1);
530 doubleout(bound[i], 1);
531 doubleout(Ares[i], 1);
532 printf(" %3d\n", index[i]);
533 }
534 printf("\n");
535 debug_time += lanc_seconds() - time;
536 }
537
538 if (!converged) {
539 ngood = 0;
540 left_ngood = 0; /* for setting left_goodlim on next loop */
541 right_ngood = 0; /* for setting right_goodlim on next loop */
542
543 /* Compute converged Ritz pairs on left end */
544 time = lanc_seconds();
545 for (i = 1; i <= left_goodlim; i++) {
546 if (bj[i] <= goodtol) {
547 ngood += 1;
548 left_ngood += 1;
549 if (ngood > maxngood) {
550 maxngood = ngood;
551 solist[ngood] = makeorthlnk_float();
552 (solist[ngood])->vec = mkvec_float(1, n);
553 }
554 (solist[ngood])->index = i;
555 Sres = Tevec(alpha, beta - 1, j, ritz[i], s);
556 if (Sres > Sres_max) {
557 Sres_max = Sres;
558 }
559 if (Sres > SRESTOL) {
560 inc_bis_safety = TRUE;
561 }
562 setvec_float((solist[ngood])->vec, 1, n, 0.0);
563 for (k = 1; k <= j; k++) {
564 scadd_float((solist[ngood])->vec, 1, n, (float)(s[k]), q[k]);
565 }
566 }
567 }
568
569 /* Compute converged Ritz pairs on right end */
570 for (i = j; i > j - right_goodlim; i--) {
571 if (bj[i] <= goodtol) {
572 ngood += 1;
573 right_ngood += 1;
574 if (ngood > maxngood) {
575 maxngood = ngood;
576 solist[ngood] = makeorthlnk_float();
577 (solist[ngood])->vec = mkvec_float(1, n);
578 }
579 (solist[ngood])->index = i;
580 Sres = Tevec(alpha, beta - 1, j, ritz[i], s);
581 if (Sres > Sres_max) {
582 Sres_max = Sres;
583 }
584 if (Sres > SRESTOL) {
585 inc_bis_safety = TRUE;
586 }
587 setvec_float((solist[ngood])->vec, 1, n, 0.0);
588 for (k = 1; k <= j; k++) {
589 scadd_float((solist[ngood])->vec, 1, n, (float)(s[k]), q[k]);
590 }
591 }
592 }
593 ritz_time += lanc_seconds() - time;
594
595 if (DEBUG_EVECS > 2) {
596 time = lanc_seconds();
597 printf(" j %3d; goodlim lft %2d, rgt %2d; list ", j, left_goodlim, right_goodlim);
598 solistout_float(solist, ngood, j);
599 printf("---------------------end of iteration---------------------\n\n");
600 debug_time += lanc_seconds() - time;
601 }
602 }
603 }
604 j++;
605 }
606 j--;
607
608 /* Collect eigenvalue and bound information. Only compute and display info for
609 the eigpairs actually used in the partitioning since don't want to spend the
610 time or space to compute the null-space of the Laplacian. */
611 time = lanc_seconds();
612 i = d;
613 curlnk = scanlist;
614 while (curlnk != NULL) {
615 lambda[i] = curlnk->val;
616 bound[i] = bj[curlnk->indx];
617 index[i] = curlnk->indx;
618 curlnk = curlnk->pntr;
619 i--;
620 }
621 scan_time += lanc_seconds() - time;
622
623 /* Compute eigenvectors. */
624 time = lanc_seconds();
625 for (i = 1; i <= d; i++) {
626 Sres = Tevec(alpha, beta - 1, j, lambda[i], s);
627 if (Sres > Sres_max) {
628 Sres_max = Sres;
629 }
630 setvec(y[i], 1, n, 0.0);
631 for (k = 1; k <= j; k++) {
632 scadd_mixed(y[i], 1, n, s[k], q[k]);
633 }
634 }
635 evec_time += lanc_seconds() - time;
636
637 time = lanc_seconds();
638 float_to_double(u_double, 1, n, u);
639 warnings(workn_double, A, y, n, lambda, vwsqrt, Ares, bound, index, d, j, maxj, Sres_max, eigtol,
640 u_double, Anorm, Output_File);
641 debug_time += lanc_seconds() - time;
642
643 /* free up memory */
644 time = lanc_seconds();
645 frvec_float(u, 1);
646 frvec(u_double, 1);
647 frvec_float(r, 1);
648 frvec_float(workn, 1);
649 frvec(workn_double, 1);
650 frvec(Ares, 0);
651 sfree(index);
652 frvec(alpha, 1);
653 frvec(beta, 0);
654 frvec(ritz, 1);
655 frvec(s, 1);
656 frvec(bj, 1);
657 frvec(workj, 0);
658 for (i = 0; i <= j; i++) {
659 frvec_float(q[i], 1);
660 }
661 sfree(q);
662 if (vwsqrt_float != NULL) {
663 frvec_float(vwsqrt_float, 0);
664 }
665 while (scanlist != NULL) {
666 curlnk = scanlist->pntr;
667 sfree(scanlist);
668 scanlist = curlnk;
669 }
670 for (i = 1; i <= maxngood; i++) {
671 frvec_float((solist[i])->vec, 1);
672 sfree(solist[i]);
673 }
674 sfree(solist);
675 if (LANCZOS_CONVERGENCE_MODE == 1) {
676 sfree(old_assignment);
677 }
678 init_time += lanc_seconds() - time;
679 }