Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020, 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 FALSE, TRUE
10 #include <math.h>
11 #include <stdio.h> // for printf
12
13 /* Determine whether to pause in Lanczos */
14 int lanpause(int j, /* current step */
15 int lastpause, /* when last paused */
16 int interval, /* interval between pauses */
17 double **q, /* the Lanczos vectors */
18 int n, /* length of Lanczos vectors */
19 int *pausemode, /* which pausing criterion to use */
20 int version, /* which version of sel. orth. we are using */
21 double beta /* current off-diagonal value */
22 )
23 {
24 extern int DEBUG_EVECS; /* debugging level for eigen computation */
25 extern double DOUBLE_EPSILON; /* machine precision */
26 double paige_dot; /* q[j]^T q[1] */
27 double paigetol; /* pause if paigedot > paigetol */
28
29 /* Check orthogonality of last Lanczos vector against previous ones */
30 if (DEBUG_EVECS > 3) {
31 checkorth(q, n, j);
32 }
33
34 /* periodic reorthogonalization */
35 if (version == 1 || version == 2) {
36 if ((j - lastpause) == interval || beta < 1000 * DOUBLE_EPSILON) {
37 return (TRUE);
38 }
39
40 return (FALSE);
41 }
42
43 /* Run until orthogonality with first Lanczos vector deteriorates, then switch
44 switch to periodic reorthog. */
45 if (version == 3) {
46 paigetol = 1.0e-3;
47 if (*pausemode == 1) {
48 paige_dot = fabs(dot(q[1], 1, n, q[j]));
49 if ((paige_dot > paigetol && j > 1) || beta < 1000 * DOUBLE_EPSILON) {
50 if (DEBUG_EVECS > 1) {
51 printf(" Pausing on step %3d with Paige prod. = %g\n", j, paige_dot);
52 }
53 *pausemode = 2;
54 return (TRUE);
55 }
56
57 return (FALSE);
58 }
59 if (*pausemode == 2) {
60 if ((j - lastpause) == interval || beta < 1000 * DOUBLE_EPSILON) {
61 return (TRUE);
62 }
63
64 return (FALSE);
65 }
66 }
67
68 /* shouldn't ever get this far, but alint really wants a return value */
69 return (FALSE);
70 }
71
72 int lanpause_float(int j, /* current step */
73 int lastpause, /* when last paused */
74 int interval, /* interval between pauses */
75 float **q, /* the Lanczos vectors */
76 int n, /* length of Lanczos vectors */
77 int *pausemode, /* which pausing criterion to use */
78 int version, /* which version of sel. orth. we are using */
79 double beta /* current off-diagonal value */
80 )
81 {
82 extern int DEBUG_EVECS; /* debugging level for eigen computation */
83 extern double DOUBLE_EPSILON; /* machine precision */
84 double paige_dot; /* q[j]^T q[1] */
85 double paigetol; /* pause if paigedot > paigetol */
86
87 /* Check orthogonality of last Lanczos vector against previous ones */
88 if (DEBUG_EVECS > 3) {
89 checkorth_float(q, n, j);
90 }
91
92 /* periodic reorthogonalization */
93 if (version == 1 || version == 2) {
94 if ((j - lastpause) == interval || beta < 1000 * DOUBLE_EPSILON) {
95 return (TRUE);
96 }
97
98 return (FALSE);
99 }
100
101 /* Run until orthogonality with first Lanczos vector deteriorates, then switch
102 switch to periodic reorthog. */
103 if (version == 3) {
104 paigetol = 1.0e-3;
105 if (*pausemode == 1) {
106 paige_dot = fabs(dot_float(q[1], 1, n, q[j]));
107 if ((paige_dot > paigetol && j > 1) || beta < 1000 * DOUBLE_EPSILON) {
108 if (DEBUG_EVECS > 1) {
109 printf(" Pausing on step %3d with Paige prod. = %g\n", j, paige_dot);
110 }
111 *pausemode = 2;
112 return (TRUE);
113 }
114
115 return (FALSE);
116 }
117 if (*pausemode == 2) {
118 if ((j - lastpause) == interval || beta < 1000 * DOUBLE_EPSILON) {
119 return (TRUE);
120 }
121
122 return (FALSE);
123 }
124 }
125
126 /* shouldn't ever get this far, but alint really wants a return value */
127 return (FALSE);
128 }