Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020 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 min
10 #include <math.h> // for fabs, log10
11 #include <stdio.h> // for printf
12
13 /* Check orthogonality of vector set */
14 void checkorth(double **mat, int n, int dim)
15 {
16 int i, j; /* loop indices */
17 double measure; /* Froebenius norm */
18 double prod; /* value of dot product */
19 double worst; /* greatest off-diagonal dot product */
20 int lim; /* index of last vec to check against */
21 int screenlim; /* value of lim that will fit on screen */
22 int option; /* which option to use */
23
24 double dot(double *vec1, int beg, int end, double *vec2); /* standard dot product routine */
25
26 /* The T/F argument in the conditionals is just a convenient option: */
27
28 screenlim = 20;
29 option = 3;
30
31 /* Check orthogonality over whole set. */
32 if (option == 1) {
33 printf("Orthogonality check:\n");
34 for (i = 1; i <= dim; i++) {
35 printf("%2d)", i);
36 for (j = 1; j <= i; j++) {
37 prod = dot(mat[i], 1, n, mat[j]);
38 /* printf(" %g ",prod); */
39 /* printf(" %4.2e ",prod); */
40 /* printf(" %4.2e ",fabs(prod)); */
41 printf(" %2d", -(int)log10(prod));
42 }
43 printf("\n");
44 }
45 }
46
47 if (option == 2) {
48 printf("Frobenius orthogonality measure:");
49 measure = 0;
50 for (i = 1; i <= dim; i++) {
51 for (j = i; j <= dim; j++) {
52 prod = dot(mat[i], 1, n, mat[j]);
53 if (i == j) {
54 measure += fabs(1.0 - prod);
55 }
56 else {
57 measure += 2.0 * fabs(prod);
58 }
59 }
60 }
61 printf("%g \n", measure);
62 }
63
64 /* Check orthogonality against last vector. Allows you to build up orthogonality
65 matrix much faster if previous columns stay the same when add a new column,
66 but may interact with other debug output to give a confusing presentation. */
67 if (option == 3) {
68 printf("%3d) ", dim);
69 lim = min(dim, screenlim);
70 worst = 0;
71 for (i = 1; i <= dim; i++) {
72 prod = dot(mat[i], 1, n, mat[dim]);
73 if (i <= lim) {
74 printf(" %2d", -(int)log10(fabs(prod)));
75 }
76 if ((i != dim) && (fabs(prod) > fabs(worst))) {
77 worst = prod;
78 }
79 }
80 printf(" worst %4.2e\n", worst);
81 }
82 }
83
84 /* Check orthogonality of vector set */
85 void checkorth_float(float **mat, int n, int dim)
86 {
87 int i, j; /* loop indices */
88 double measure; /* Froebenius norm */
89 double prod; /* value of dot product */
90 double worst; /* greatest off-diagonal dot product */
91 int lim; /* index of last vec to check against */
92 int screenlim; /* value of lim that will fit on screen */
93 int option; /* which option to use */
94
95 double dot_float(float *vec1, int beg, int end, float *vec2); /* standard dot product routine */
96
97 /* The T/F argument in the conditionals is just a convenient option: */
98
99 screenlim = 20;
100 option = 3;
101
102 /* Check orthogonality over whole set. */
103 if (option == 1) {
104 printf("Orthogonality check:\n");
105 for (i = 1; i <= dim; i++) {
106 printf("%2d)", i);
107 for (j = 1; j <= i; j++) {
108 prod = dot_float(mat[i], 1, n, mat[j]);
109 /* printf(" %g ",prod); */
110 /* printf(" %4.2e ",prod); */
111 /* printf(" %4.2e ",fabs(prod)); */
112 printf(" %2d", -(int)log10(prod));
113 }
114 printf("\n");
115 }
116 }
117
118 if (option == 2) {
119 printf("Frobenius orthogonality measure:");
120 measure = 0;
121 for (i = 1; i <= dim; i++) {
122 for (j = i; j <= dim; j++) {
123 prod = dot_float(mat[i], 1, n, mat[j]);
124 if (i == j) {
125 measure += fabs(1.0 - prod);
126 }
127 else {
128 measure += 2.0 * fabs(prod);
129 }
130 }
131 }
132 printf("%g \n", measure);
133 }
134
135 /* Check orthogonality against last vector. Allows you to build up orthogonality
136 matrix much faster if previous columns stay the same when add a new column,
137 but may interact with other debug output to give a confusing presentation. */
138 if (option == 3) {
139 printf("%3d) ", dim);
140 lim = min(dim, screenlim);
141 worst = 0;
142 for (i = 1; i <= dim; i++) {
143 prod = dot_float(mat[i], 1, n, mat[dim]);
144 if (i <= lim) {
145 printf(" %2d", -(int)log10(fabs(prod)));
146 }
147 if ((i != dim) && (fabs(prod) > fabs(worst))) {
148 worst = prod;
149 }
150 }
151 printf(" worst %4.2e\n", worst);
152 }
153 }