From 2f8c7039b244393d313b3e846a2cd8f21988f9e3 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 11 Jul 2020 02:24:26 +0000 Subject: [PATCH] Documentation for 81f4428569254f08b6c8959648e0837df3850350 --- d7/d50/qr__eigen__values_8c.html | 362 ++++++++++++----------- d7/dd8/c__atoi__str__to__integer_8c.html | 8 +- 2 files changed, 194 insertions(+), 176 deletions(-) diff --git a/d7/d50/qr__eigen__values_8c.html b/d7/d50/qr__eigen__values_8c.html index 8470f36b..2c27bfed 100644 --- a/d7/d50/qr__eigen__values_8c.html +++ b/d7/d50/qr__eigen__values_8c.html @@ -272,97 +272,113 @@ int 
Returns
time for computation in seconds
-
106 {
-
107  double **R = (double **)malloc(sizeof(double *) * mat_size);
-
108  double **Q = (double **)malloc(sizeof(double *) * mat_size);
-
109 
-
110  if (!eigen_vals)
-
111  {
-
112  perror("Output eigen value vector cannot be NULL!");
-
113  return -1;
-
114  }
-
115  else if (!Q || !R)
-
116  {
-
117  perror("Unable to allocate memory for Q & R!");
-
118  return -1;
-
119  }
-
120 
-
121  /* allocate dynamic memory for matrices */
-
122  for (int i = 0; i < mat_size; i++)
-
123  {
-
124  R[i] = (double *)malloc(sizeof(double) * mat_size);
-
125  Q[i] = (double *)malloc(sizeof(double) * mat_size);
-
126  if (!Q[i] || !R[i])
-
127  {
-
128  perror("Unable to allocate memory for Q & R.");
-
129  return -1;
-
130  }
-
131  }
-
132 
-
133  if (debug_print)
-
134  print_matrix(A, mat_size, mat_size);
-
135 
-
136  int rows = mat_size, columns = mat_size;
-
137  int counter = 0, num_eigs = rows - 1;
-
138  double last_eig = 0;
-
139 
-
140  clock_t t1 = clock();
-
141  while (num_eigs > 0) /* continue till all eigen values are found */
-
142  {
-
143  /* iterate with QR decomposition */
-
144  while (fabs(A[num_eigs][num_eigs - 1]) > EPSILON)
-
145  {
-
146  last_eig = A[num_eigs][num_eigs];
-
147  for (int i = 0; i < rows; i++) A[i][i] -= last_eig; /* A - cI */
-
148  qr_decompose(A, Q, R, rows, columns);
-
149 
-
150  if (debug_print)
-
151  {
-
152  print_matrix(A, rows, columns);
-
153  print_matrix(Q, rows, columns);
-
154  print_matrix(R, columns, columns);
-
155  printf("-------------------- %d ---------------------\n",
-
156  ++counter);
-
157  }
-
158 
-
159  mat_mul(R, Q, A, columns, columns, rows, columns);
-
160  for (int i = 0; i < rows; i++) A[i][i] += last_eig; /* A + cI */
-
161  }
-
162 
-
163  /* store the converged eigen value */
-
164  eigen_vals[num_eigs] = last_eig;
-
165 
-
166  if (debug_print)
-
167  {
-
168  printf("========================\n");
-
169  printf("Eigen value: % g,\n", last_eig);
-
170  printf("========================\n");
-
171  }
-
172 
-
173  num_eigs--;
-
174  rows--;
-
175  columns--;
-
176  }
-
177  eigen_vals[0] = A[0][0];
-
178  double dtime = (double)(clock() - t1) / CLOCKS_PER_SEC;
-
179 
-
180  if (debug_print)
-
181  {
-
182  print_matrix(R, mat_size, mat_size);
-
183  print_matrix(Q, mat_size, mat_size);
-
184  }
-
185 
-
186  /* cleanup dynamic memory */
-
187  for (int i = 0; i < mat_size; i++)
-
188  {
-
189  free(R[i]);
-
190  free(Q[i]);
-
191  }
-
192  free(R);
-
193  free(Q);
-
194 
-
195  return dtime;
-
196 }
+
108 {
+
109  if (!eigen_vals)
+
110  {
+
111  perror("Output eigen value vector cannot be NULL!");
+
112  return -1;
+
113  }
+
114  double **R = (double **)malloc(sizeof(double *) * mat_size);
+
115  double **Q = (double **)malloc(sizeof(double *) * mat_size);
+
116  if (!Q || !R)
+
117  {
+
118  perror("Unable to allocate memory for Q & R!");
+
119  if (Q)
+
120  {
+
121  free(Q);
+
122  }
+
123  if (R)
+
124  {
+
125  free(R);
+
126  }
+
127  return -1;
+
128  }
+
129 
+
130  /* allocate dynamic memory for matrices */
+
131  for (int i = 0; i < mat_size; i++)
+
132  {
+
133  R[i] = (double *)malloc(sizeof(double) * mat_size);
+
134  Q[i] = (double *)malloc(sizeof(double) * mat_size);
+
135  if (!Q[i] || !R[i])
+
136  {
+
137  perror("Unable to allocate memory for Q & R.");
+
138  for (; i >= 0; i--)
+
139  {
+
140  free(R[i]);
+
141  free(Q[i]);
+
142  }
+
143  free(Q);
+
144  free(R);
+
145  return -1;
+
146  }
+
147  }
+
148 
+
149  if (debug_print)
+
150  {
+
151  print_matrix(A, mat_size, mat_size);
+
152  }
+
153 
+
154  int rows = mat_size, columns = mat_size;
+
155  int counter = 0, num_eigs = rows - 1;
+
156  double last_eig = 0;
+
157 
+
158  clock_t t1 = clock();
+
159  while (num_eigs > 0) /* continue till all eigen values are found */
+
160  {
+
161  /* iterate with QR decomposition */
+
162  while (fabs(A[num_eigs][num_eigs - 1]) > EPSILON)
+
163  {
+
164  last_eig = A[num_eigs][num_eigs];
+
165  for (int i = 0; i < rows; i++) A[i][i] -= last_eig; /* A - cI */
+
166  qr_decompose(A, Q, R, rows, columns);
+
167 
+
168  if (debug_print)
+
169  {
+
170  print_matrix(A, rows, columns);
+
171  print_matrix(Q, rows, columns);
+
172  print_matrix(R, columns, columns);
+
173  printf("-------------------- %d ---------------------\n",
+
174  ++counter);
+
175  }
+
176 
+
177  mat_mul(R, Q, A, columns, columns, rows, columns);
+
178  for (int i = 0; i < rows; i++) A[i][i] += last_eig; /* A + cI */
+
179  }
+
180 
+
181  /* store the converged eigen value */
+
182  eigen_vals[num_eigs] = last_eig;
+
183 
+
184  if (debug_print)
+
185  {
+
186  printf("========================\n");
+
187  printf("Eigen value: % g,\n", last_eig);
+
188  printf("========================\n");
+
189  }
+
190 
+
191  num_eigs--;
+
192  rows--;
+
193  columns--;
+
194  }
+
195  eigen_vals[0] = A[0][0];
+
196  double dtime = (double)(clock() - t1) / CLOCKS_PER_SEC;
+
197 
+
198  if (debug_print)
+
199  {
+
200  print_matrix(R, mat_size, mat_size);
+
201  print_matrix(Q, mat_size, mat_size);
+
202  }
+
203 
+
204  /* cleanup dynamic memory */
+
205  for (int i = 0; i < mat_size; i++)
+
206  {
+
207  free(R[i]);
+
208  free(Q[i]);
+
209  }
+
210  free(R);
+
211  free(Q);
+
212 
+
213  return dtime;
+
214 }
Here is the call graph for this function:
@@ -458,13 +474,15 @@ Here is the call graph for this function:
70 #pragma omp for
71 #endif
72  for (i = 0; i < R1; i++)
-
73  for (int j = 0; j < C2; j++)
-
74  {
-
75  OUT[i][j] = 0.f;
-
76  for (int k = 0; k < C1; k++) OUT[i][j] += A[i][k] * B[k][j];
-
77  }
-
78  return OUT;
-
79 }
+
73  {
+
74  for (int j = 0; j < C2; j++)
+
75  {
+
76  OUT[i][j] = 0.f;
+
77  for (int k = 0; k < C1; k++) OUT[i][j] += A[i][k] * B[k][j];
+
78  }
+
79  }
+
80  return OUT;
+
81 }
@@ -488,40 +506,40 @@ Here is the call graph for this function: \[\begin{bmatrix} 5 & 7\\ 7 & 11 \end{bmatrix}\]

which are approximately, {15.56158, 0.384227}

-
207 {
-
208  int mat_size = 2;
-
209  double X[][2] = {{5, 7}, {7, 11}};
-
210  double y[] = {15.56158, 0.384227}; // corresponding y-values
-
211  double eig_vals[2];
-
212 
-
213  // The following steps are to convert a "double[][]" to "double **"
-
214  double **A = (double **)malloc(mat_size * sizeof(double *));
-
215  for (int i = 0; i < mat_size; i++) A[i] = X[i];
-
216 
-
217  printf("------- Test 1 -------\n");
-
218 
-
219  double dtime = eigen_values(A, eig_vals, mat_size, 0);
-
220 
-
221  for (int i = 0; i < mat_size; i++)
-
222  {
-
223  printf("%d/5 Checking for %.3g --> ", i + 1, y[i]);
-
224  char result = 0;
-
225  for (int j = 0; j < mat_size && !result; j++)
-
226  {
-
227  if (fabs(y[i] - eig_vals[j]) < 0.1)
-
228  {
-
229  result = 1;
-
230  printf("(%.3g) ", eig_vals[j]);
-
231  }
-
232  }
-
233 
-
234  // ensure that i^th expected eigen value was computed
-
235  assert(result != 0);
-
236  printf("found\n");
-
237  }
-
238  printf("Test 1 Passed in %.3g sec\n\n", dtime);
-
239  free(A);
-
240 }
+
225 {
+
226  int mat_size = 2;
+
227  double X[][2] = {{5, 7}, {7, 11}};
+
228  double y[] = {15.56158, 0.384227}; // corresponding y-values
+
229  double eig_vals[2] = {0, 0};
+
230 
+
231  // The following steps are to convert a "double[][]" to "double **"
+
232  double **A = (double **)malloc(mat_size * sizeof(double *));
+
233  for (int i = 0; i < mat_size; i++) A[i] = X[i];
+
234 
+
235  printf("------- Test 1 -------\n");
+
236 
+
237  double dtime = eigen_values(A, eig_vals, mat_size, 0);
+
238 
+
239  for (int i = 0; i < mat_size; i++)
+
240  {
+
241  printf("%d/5 Checking for %.3g --> ", i + 1, y[i]);
+
242  char result = 0;
+
243  for (int j = 0; j < mat_size && !result; j++)
+
244  {
+
245  if (fabs(y[i] - eig_vals[j]) < 0.1)
+
246  {
+
247  result = 1;
+
248  printf("(%.3g) ", eig_vals[j]);
+
249  }
+
250  }
+
251 
+
252  // ensure that i^th expected eigen value was computed
+
253  assert(result != 0);
+
254  printf("found\n");
+
255  }
+
256  printf("Test 1 Passed in %.3g sec\n\n", dtime);
+
257  free(A);
+
258 }
Here is the call graph for this function:
@@ -551,45 +569,45 @@ Here is the call graph for this function:
\[\begin{bmatrix} -4& 4& 2& 0& -3\\ 4& -4& 4& -3& -1\\ 2& 4& 4& 3& -3\\ 0& -3& 3& -1&-1\\ -3& -1& -3& -3& 0 \end{bmatrix}\]

which are approximately, {9.27648, -9.26948, 2.0181, -1.03516, -5.98994}

-
254 {
-
255  int mat_size = 5;
-
256  double X[][5] = {{-4, 4, 2, 0, -3},
-
257  {4, -4, 4, -3, -1},
-
258  {2, 4, 4, 3, -3},
-
259  {0, -3, 3, -1, -3},
-
260  {-3, -1, -3, -3, 0}};
-
261  double y[] = {9.27648, -9.26948, 2.0181, -1.03516,
-
262  -5.98994}; // corresponding y-values
-
263  double eig_vals[5];
-
264 
-
265  // The following steps are to convert a "double[][]" to "double **"
-
266  double **A = (double **)malloc(mat_size * sizeof(double *));
-
267  for (int i = 0; i < mat_size; i++) A[i] = X[i];
-
268 
-
269  printf("------- Test 2 -------\n");
-
270 
-
271  double dtime = eigen_values(A, eig_vals, mat_size, 0);
-
272 
-
273  for (int i = 0; i < mat_size; i++)
-
274  {
-
275  printf("%d/5 Checking for %.3g --> ", i + 1, y[i]);
-
276  char result = 0;
-
277  for (int j = 0; j < mat_size && !result; j++)
-
278  {
-
279  if (fabs(y[i] - eig_vals[j]) < 0.1)
-
280  {
-
281  result = 1;
-
282  printf("(%.3g) ", eig_vals[j]);
-
283  }
-
284  }
-
285 
-
286  // ensure that i^th expected eigen value was computed
-
287  assert(result != 0);
-
288  printf("found\n");
-
289  }
-
290  printf("Test 2 Passed in %.3g sec\n\n", dtime);
-
291  free(A);
-
292 }
+
272 {
+
273  int mat_size = 5;
+
274  double X[][5] = {{-4, 4, 2, 0, -3},
+
275  {4, -4, 4, -3, -1},
+
276  {2, 4, 4, 3, -3},
+
277  {0, -3, 3, -1, -3},
+
278  {-3, -1, -3, -3, 0}};
+
279  double y[] = {9.27648, -9.26948, 2.0181, -1.03516,
+
280  -5.98994}; // corresponding y-values
+
281  double eig_vals[5];
+
282 
+
283  // The following steps are to convert a "double[][]" to "double **"
+
284  double **A = (double **)malloc(mat_size * sizeof(double *));
+
285  for (int i = 0; i < mat_size; i++) A[i] = X[i];
+
286 
+
287  printf("------- Test 2 -------\n");
+
288 
+
289  double dtime = eigen_values(A, eig_vals, mat_size, 0);
+
290 
+
291  for (int i = 0; i < mat_size; i++)
+
292  {
+
293  printf("%d/5 Checking for %.3g --> ", i + 1, y[i]);
+
294  char result = 0;
+
295  for (int j = 0; j < mat_size && !result; j++)
+
296  {
+
297  if (fabs(y[i] - eig_vals[j]) < 0.1)
+
298  {
+
299  result = 1;
+
300  printf("(%.3g) ", eig_vals[j]);
+
301  }
+
302  }
+
303 
+
304  // ensure that i^th expected eigen value was computed
+
305  assert(result != 0);
+
306  printf("found\n");
+
307  }
+
308  printf("Test 2 Passed in %.3g sec\n\n", dtime);
+
309  free(A);
+
310 }
Here is the call graph for this function:
@@ -607,7 +625,7 @@ Here is the call graph for this function:
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition: qr_decompose.h:22
double ** mat_mul(double **A, double **B, double **OUT, int R1, int C1, int R2, int C2)
Perform multiplication of two matrices.
Definition: qr_eigen_values.c:59
#define LIMS
limit of range of matrix values
Definition: qr_eigen_values.c:19
-
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:104
+
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:106
int compare(const void *a, const void *b)
comparison function for use with internal qsort algorithm
Definition: sol1.c:19
void shell_sort(char data[][MAX_NAME_LEN], int LEN)
Alphabetical sorting using 'shell sort' algorithm.
Definition: sol1.c:20
long long int get_product(FILE *fp, long start_pos, int num_digits)
Compute the product of two numbers in a file.
Definition: sol1.c:16
-
int main(int argc, char **argv)
main function
Definition: qr_eigen_values.c:297
+
int main(int argc, char **argv)
main function
Definition: qr_eigen_values.c:315
#define MAX_L
chunk size of array allocation
Definition: sol1.c:18
Definition: prime_factoriziation.c:25
void modifiedBinarySearch(const int **mat, int n, int m, int x)
Function to perform binary search on the mid values of row to get the desired pair of rows where the ...
Definition: modified_binary_search.c:48
@@ -265,7 +265,7 @@ Here is the call graph for this function:
#define MAX_NAME_LEN
Maximum length of each name.
Definition: sol1.c:15
void bead_sort(int *a, size_t len)
This is where the sorting of the array takes place.
Definition: bead_sort.c:37
void stats_computer1(float x, float *mean, float *variance, float *std)
continuous mean and variance computance using first value as an approximation for the mean.
Definition: realtime_stats.c:24
-
void test2()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:253
+
void test2()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:271
char remove_digits(big_int *digit, int N)
Function to remove digits preceeding the current digit.
Definition: sol1.c:76
#define N
number of digits of the large number
Definition: sol1.c:109
char value
tens place (single digit)
Definition: sol1.c:19
@@ -277,7 +277,7 @@ Here is the call graph for this function:
Node::data
int data
stores the number
Definition: threaded_binary_trees.c:28
get_next_abundant
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol2.c:70
Node
Node, the basic data structure of the tree.
Definition: threaded_binary_trees.c:27
-
test1
void test1()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:206
+
test1
void test1()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:224
test_function
void test_function(const float *test_data, const int number_of_samples)
Test the algorithm implementation.
Definition: realtime_stats.c:92
MAX_DIGITS
#define MAX_DIGITS
maximum number of digits
Definition: sol1.c:13
sum_of_primes
unsigned long long sum_of_primes(unsigned long N)
Computes sum of prime numbers less than N.
Definition: sol1.c:21
@@ -332,7 +332,7 @@ Here is the call graph for this function:
merge_sort
void merge_sort(int *a, int n, int l, int r)
Merge sort algorithm implementation.
Definition: merge_sort.c:82
LIMS
#define LIMS
limit of range of matrix values
Definition: qr_eigen_values.c:19
binarysearch2
int binarysearch2(const int *arr, int l, int r, int x)
Iterative implementation.
Definition: binary_search.c:51
-
eigen_values
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:104
+
eigen_values
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:106
BEAD
#define BEAD(i, j)
Create easy access of elements from a 2D matrix stored in memory as a 1D array.
Definition: bead_sort.c:16
test_c_atoi
void test_c_atoi()
test the function implementation
Definition: c_atoi_str_to_integer.c:56
shell_sort
void shell_sort(int *array, long LEN)
Shell sort algorithm.
Definition: shell_sort2.c:41