From 6470f0318b1f741d53afb576f596df5fd617a9c2 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sun, 28 Jun 2020 15:18:52 -0400 Subject: [PATCH] fixed documentations --- .../binary_trees/threaded_binary_trees.c | 4 +-- machine_learning/adaline_learning.c | 11 +++--- machine_learning/kohonen_som_topology.c | 15 ++++---- machine_learning/kohonen_som_trace.c | 36 +++++++++---------- misc/cartesian_to_polar.c | 2 +- misc/factorial_large_number.c | 10 +++--- numerical_methods/durand_kerner_roots.c | 6 ++-- numerical_methods/newton_raphson_root.c | 2 +- numerical_methods/qr_eigen_values.c | 3 +- project_euler/problem_13/sol1.c | 2 +- project_euler/problem_14/sol1.c | 2 +- project_euler/problem_15/sol1.c | 2 +- project_euler/problem_19/sol1.c | 23 ++++++------ project_euler/problem_20/sol1.c | 22 ++++++------ project_euler/problem_21/sol1.c | 6 ++-- project_euler/problem_22/sol1.c | 4 +-- project_euler/problem_23/sol1.c | 12 +++---- project_euler/problem_23/sol2.c | 18 +++++----- project_euler/problem_25/sol1.c | 2 +- sorting/shell_sort2.c | 4 +-- 20 files changed, 92 insertions(+), 94 deletions(-) diff --git a/data_structures/binary_trees/threaded_binary_trees.c b/data_structures/binary_trees/threaded_binary_trees.c index b9ff2560..6ef5f728 100644 --- a/data_structures/binary_trees/threaded_binary_trees.c +++ b/data_structures/binary_trees/threaded_binary_trees.c @@ -22,7 +22,7 @@ /** * Node, the basic data structure of the tree - **/ + */ typedef struct Node { int data; /**< stores the number */ @@ -34,7 +34,7 @@ typedef struct Node * creates a new node * param[in] data value to be inserted * \returns a pointer to the new node - **/ + */ node *create_node(int data) { node *ptr = (node *)malloc(sizeof(node)); diff --git a/machine_learning/adaline_learning.c b/machine_learning/adaline_learning.c index 341d7de2..bfbdbe9d 100644 --- a/machine_learning/adaline_learning.c +++ b/machine_learning/adaline_learning.c @@ -30,17 +30,18 @@ #include #include -#define MAX_ITER 500 // INT_MAX ///< Maximum number of iterations to learn +/** Maximum number of iterations to learn */ +#define MAX_ITER 500 // INT_MAX /** structure to hold adaline model parameters */ struct adaline { - double eta; ///< learning rate of the algorithm - double *weights; ///< weights of the neural network - int num_weights; ///< number of weights of the neural network + double eta; /**< learning rate of the algorithm */ + double *weights; /**< weights of the neural network */ + int num_weights; /**< number of weights of the neural network */ }; -#define ACCURACY 1e-5 ///< convergence accuracy \f$=1\times10^{-5}\f$ +#define ACCURACY 1e-5 /**< convergence accuracy \f$=1\times10^{-5}\f$ */ /** * Default constructor diff --git a/machine_learning/kohonen_som_topology.c b/machine_learning/kohonen_som_topology.c index 3820d713..4af9c9c8 100644 --- a/machine_learning/kohonen_som_topology.c +++ b/machine_learning/kohonen_som_topology.c @@ -28,14 +28,12 @@ #endif #ifndef max -#define max(a, b) \ - (((a) > (b)) ? (a) : (b)) /**< shorthand for maximum value \ - */ +/** shorthand for maximum value */ +#define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min -#define min(a, b) \ - (((a) < (b)) ? (a) : (b)) /**< shorthand for minimum value \ - */ +/** shorthand for minimum value */ +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif /** to store info regarding 3D arrays */ @@ -193,8 +191,8 @@ int save_u_matrix(const char *fname, struct array_3d *W) * \param[in] X matrix to search * \param[in] N number of points in the vector * \param[out] val minimum value found - * \param[out] idx_x x-index where minimum value was found - * \param[out] idx_y y-index where minimum value was found + * \param[out] x_idx x-index where minimum value was found + * \param[out] y_idx y-index where minimum value was found */ void get_min_2d(double **X, int N, double *val, int *x_idx, int *y_idx) { @@ -300,7 +298,6 @@ double update_weights(const double *X, struct array_3d *W, double **D, * * \param[in] X data set * \param[in,out] W weights matrix - * \param[in] D temporary vector to store distances * \param[in] num_samples number of output points * \param[in] num_features number of features per input sample * \param[in] num_out number of output points diff --git a/machine_learning/kohonen_som_trace.c b/machine_learning/kohonen_som_trace.c index 3569f974..68c3bb18 100644 --- a/machine_learning/kohonen_som_trace.c +++ b/machine_learning/kohonen_som_trace.c @@ -5,6 +5,7 @@ * * \author [Krishna Vedala](https://github.com/kvedala) * + * \details * This example implements a powerful self organizing map algorithm. * The algorithm creates a connected network of weights that closely * follows the given data points. This this creates a chain of nodes that @@ -16,23 +17,22 @@ #include #include #include -#ifdef _OPENMP // check if OpenMP based parallellization is available +#ifdef _OPENMP // check if OpenMP based parallelization is available #include #endif #ifndef max -#define max(a, b) \ - (((a) > (b)) ? (a) : (b)) /**< shorthand for maximum value \ - */ +/** shorthand for maximum value */ +#define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min -#define min(a, b) \ - (((a) < (b)) ? (a) : (b)) /**< shorthand for minimum value \ - */ +/** shorthand for minimum value */ +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif /** - * Helper function to generate a random number in a given interval. + * \brief Helper function to generate a random number in a given interval. + * \details * \n Steps: * 1. `r1 = rand() % 100` gets a random number between 0 and 99 * 2. `r2 = r1 / 100` converts random number to be between 0 and 0.99 @@ -41,22 +41,23 @@ * y = (b - a) \times \frac{\text{(random number between 0 and RAND_MAX)} \; * \text{mod}\; 100}{100} + a \f] * - * \param[in] a lower limit - * \param[in] b upper limit + * \param a lower limit + * \param b upper limit * \returns random number in the range \f$[a,b)\f$ */ double _random(double a, double b) { - return ((b - a) * (rand() % 100) / 100.f) + a; + int r = rand() % 100; + return ((b - a) * r / 100.f) + a; } /** * Save a given n-dimensional data martix to file. * - * \param[in] fname filename to save in (gets overwriten without confirmation) - * \param[in] X matrix to save - * \param[in] num_points rows in the matrix = number of points - * \param[in] num_features columns in the matrix = dimensions of points + * \param [in] fname filename to save in (gets overwriten without confirmation) + * \param [in] X matrix to save + * \param [in] num_points rows in the matrix = number of points + * \param [in] num_features columns in the matrix = dimensions of points * \returns 0 if all ok * \returns -1 if file creation failed */ @@ -89,7 +90,7 @@ int save_nd_data(const char *fname, double **X, int num_points, /** * Get minimum value and index of the value in a vector - * \param[in] x vector to search + * \param[in] X vector to search * \param[in] N number of points in the vector * \param[out] val minimum value found * \param[out] idx index where minimum value was found @@ -111,7 +112,7 @@ void get_min_1d(double const *X, int N, double *val, int *idx) /** * Update weights of the SOM using Kohonen algorithm * - * \param[in] X data point + * \param[in] x data point * \param[in,out] W weights matrix * \param[in,out] D temporary vector to store distances * \param[in] num_out number of output points @@ -164,7 +165,6 @@ void update_weights(double const *x, double *const *W, double *D, int num_out, * * \param[in] X data set * \param[in,out] W weights matrix - * \param[in] D temporary vector to store distances * \param[in] num_samples number of output points * \param[in] num_features number of features per input sample * \param[in] num_out number of output points diff --git a/misc/cartesian_to_polar.c b/misc/cartesian_to_polar.c index f7c4f3e2..e7b02128 100644 --- a/misc/cartesian_to_polar.c +++ b/misc/cartesian_to_polar.c @@ -6,7 +6,7 @@ const double pi = 3.141592653589793238462643383279502884; /** give as arguments to the executable two x and y coordinates outputs a polar coordinate -**/ +*/ int main() { double x, y; diff --git a/misc/factorial_large_number.c b/misc/factorial_large_number.c index 09634c3b..c3939b38 100644 --- a/misc/factorial_large_number.c +++ b/misc/factorial_large_number.c @@ -10,7 +10,7 @@ /** * dynamically large number - **/ + */ typedef struct _large_num { char *digits; /**< array to store individual digits */ @@ -20,7 +20,7 @@ typedef struct _large_num /** * create a new large number * \returns pointer to a large number - **/ + */ large_num *new_number(void) { large_num *new_num = (large_num *)malloc(sizeof(large_num)); @@ -33,7 +33,7 @@ large_num *new_number(void) /** * delete all memory allocated for large number * \param[in] num pointer to large_num to delete - **/ + */ void delete_number(large_num *num) { free(num->digits); @@ -44,7 +44,7 @@ void delete_number(large_num *num) * add a digit to the large number * \param[in,out] num * \param[in] value value of the digit to insert - **/ + */ void add_digit(large_num *num, unsigned int value) { if (value > 9) @@ -62,7 +62,7 @@ void add_digit(large_num *num, unsigned int value) /** * multiply large number with another integer and * store the result in the same large number - **/ + */ void multiply(large_num *num, unsigned long n) { int i; diff --git a/numerical_methods/durand_kerner_roots.c b/numerical_methods/durand_kerner_roots.c index 8b032aa7..f29158c4 100644 --- a/numerical_methods/durand_kerner_roots.c +++ b/numerical_methods/durand_kerner_roots.c @@ -46,7 +46,7 @@ * \param[in] degree degree of polynomial * \param[in] x point at which to evaluate the polynomial * \returns \f$f(x)\f$ - **/ + */ long double complex poly_function(double *coeffs, unsigned int degree, long double complex x) { @@ -91,7 +91,7 @@ char check_termination(long double delta) /*** * the comandline inputs are taken as coeffiecients of a polynomial - **/ + */ int main(int argc, char **argv) { double *coeffs = NULL; @@ -130,7 +130,7 @@ int main(int argc, char **argv) #if defined(DEBUG) || !defined(NDEBUG) /** * store intermediate values to a CSV file - **/ + */ FILE *log_file = fopen("durand_kerner.log.csv", "wt"); if (!log_file) { diff --git a/numerical_methods/newton_raphson_root.c b/numerical_methods/newton_raphson_root.c index 7f071db9..952b2b49 100644 --- a/numerical_methods/newton_raphson_root.c +++ b/numerical_methods/newton_raphson_root.c @@ -4,7 +4,7 @@ * Newton-Raphson interpolation algorithm. * * \author [Krishna Vedala](https://github.com/kvedala) - **/ + */ #include /* requires minimum of C99 */ #include diff --git a/numerical_methods/qr_eigen_values.c b/numerical_methods/qr_eigen_values.c index 0b0d1bf0..24d643d4 100644 --- a/numerical_methods/qr_eigen_values.c +++ b/numerical_methods/qr_eigen_values.c @@ -10,6 +10,7 @@ #include #include #include + #include "qr_decompose.h" #ifdef _OPENMP #include @@ -95,7 +96,7 @@ double **mat_mul(double **A, double **B, double **OUT, int R1, int C1, int R2, * \note The matrix \f$A\f$ gets modified * * \param[in,out] A matrix to compute eigen values for - * \param[out] eig_vals resultant vector containing computed eigen values + * \param[out] eigen_vals resultant vector containing computed eigen values * \param[in] mat_size matrix size * \param[in] debug_print 1 to print intermediate Q & R matrices, 0 for not to * \returns time for computation in seconds diff --git a/project_euler/problem_13/sol1.c b/project_euler/problem_13/sol1.c index e5c1fd90..e55f19d4 100644 --- a/project_euler/problem_13/sol1.c +++ b/project_euler/problem_13/sol1.c @@ -40,7 +40,7 @@ int get_number(FILE *fp, char *buffer, uint8_t *out_int) /** * Function to add arbitraty length decimal integers stored in an array. * a + b = c = new b - **/ + */ int add_numbers(uint8_t *a, uint8_t *b, uint8_t N) { int carry = 0; diff --git a/project_euler/problem_14/sol1.c b/project_euler/problem_14/sol1.c index cfb2422f..f999dcbf 100644 --- a/project_euler/problem_14/sol1.c +++ b/project_euler/problem_14/sol1.c @@ -23,7 +23,7 @@ /** * Computes the length of collatz sequence for a given * starting number - **/ + */ long long collatz(long long start_num) { long long length = 1; diff --git a/project_euler/problem_15/sol1.c b/project_euler/problem_15/sol1.c index c0dd1c79..5cf3184e 100644 --- a/project_euler/problem_15/sol1.c +++ b/project_euler/problem_15/sol1.c @@ -13,7 +13,7 @@ * and N right options, without preference for order. * Hence, the path can be be traced in N out of 2N number of ways. * This is the same as binomial coeeficient. - **/ + */ unsigned long long number_of_paths(int N) { unsigned long long path = 1; diff --git a/project_euler/problem_19/sol1.c b/project_euler/problem_19/sol1.c index 90ea0f04..f7854d79 100644 --- a/project_euler/problem_19/sol1.c +++ b/project_euler/problem_19/sol1.c @@ -10,7 +10,7 @@ * Month is identified by an integer -\n * > 0 = Jan and 11 = December\n * For February, adjust for leap year outside the function. - **/ + */ char get_month_days(short month) { if (month == 1) /* February has 28 days. Adjust leap year in the loop */ @@ -37,7 +37,7 @@ char get_month_days(short month) /** * return 1 if input year is a leap year * otherwise, return 0 - **/ + */ char is_leap_year(short year) { if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) @@ -79,10 +79,10 @@ int main(int argc, char **argv) const short start_year = 1901; const short end_year = 2000; - /** + /* * Let us identify days i.e., Sunday thru Saturday with integers - 0 thru 6 - *respectively Jan 1 1901 was a Tuesday - **/ + * respectively Jan 1 1901 was a Tuesday + */ char start_day = 2; for (int year = start_year; year <= end_year; year++) @@ -90,9 +90,10 @@ int main(int argc, char **argv) char is_leap = is_leap_year(year); for (char month = 0; month < 12; month++) { - /** + /* * These two for-loops count the start of day for the next month. - * Hence, we have to skip the last December count */ + * Hence, we have to skip the last December count + */ if (year == end_year && month == 11) continue; @@ -109,11 +110,11 @@ int main(int argc, char **argv) } #endif - /** Main Algorithm: + /* Main Algorithm: * every week has 7 days hence, the start of next day would be - *modulo 7 add to this, the current start date and ensure the result - *is still modulo 7! - **/ + * modulo 7 add to this, the current start date and ensure the + * result is still modulo 7! + */ start_day = ((days % 7) + start_day) % 7; /* If start-day is a Sunday, increment counter */ diff --git a/project_euler/problem_20/sol1.c b/project_euler/problem_20/sol1.c index 1c6e9e1f..a78e014d 100644 --- a/project_euler/problem_20/sol1.c +++ b/project_euler/problem_20/sol1.c @@ -3,7 +3,7 @@ * \brief [Problem 20](https://projecteuler.net/problem=20) solution * \author [Krishna Vedala](https://github.com/kvedala) * - * Implementation uses a custom `big_int` structure that can store arbitrarilty + * Implementation uses a custom `big_int` structure that can store arbitrarily * large integer numbers. */ #include @@ -13,12 +13,12 @@ /** * store arbitratily large integer values * as a linked list of digits. - **/ + */ typedef struct _big_int { - char value; /** tens place (single digit) */ - struct _big_int *next_digit; /** hundreds place */ - struct _big_int *prev_digit; /** units place */ + char value; /**< tens place (single digit) */ + struct _big_int *next_digit; /**< hundreds place */ + struct _big_int *prev_digit; /**< units place */ } big_int; #ifdef DEBUG @@ -33,7 +33,7 @@ void print_digit(const big_int *my_int) /** * Function that allocates memory to add another * digit at the MSB - **/ + */ big_int *add_digit(big_int *digit, char value) { if (digit == NULL) @@ -72,7 +72,7 @@ big_int *add_digit(big_int *digit, char value) /** * Function to remove digits preceeding the * current digit. - **/ + */ char remove_digits(big_int *digit, int N) { if (digit == NULL) @@ -133,10 +133,10 @@ int main(int argc, char **argv) ptr->value = tmp; if (i == N) - /** + /* * sum digits on the last iteration * this avoid having another loop over all digits - **/ + */ sum_digits += tmp; if (ptr->next_digit) @@ -158,9 +158,9 @@ int main(int argc, char **argv) printf("%d! = ", N); #endif - /** Notice that in the loop above, we make sure that at the end of the loop, + /* Notice that in the loop above, we make sure that at the end of the loop, * ptr is pointing to the last digit. Thus we can avoid using another loop. - **/ + */ // ptr = &my_int; // /* move ptr to the MSB digit */ // while (ptr->next_digit) diff --git a/project_euler/problem_21/sol1.c b/project_euler/problem_21/sol1.c index d5b77145..aac5b453 100644 --- a/project_euler/problem_21/sol1.c +++ b/project_euler/problem_21/sol1.c @@ -9,7 +9,7 @@ /** * function to return the sum of proper divisors of N - **/ + */ unsigned long sum_of_divisors(unsigned int N) { unsigned long sum = 1 + N; /* 1 and itself are always a divisor */ @@ -40,12 +40,12 @@ int main(int argc, char **argv) if (argc == 2) MAX_N = atoi(argv[1]); - /**< + /* * We use an array of flags to check if a number at the index was: * not-processed = 0 * is amicable = 1 * not amicable = -1 - **/ + */ char *flags = (char *)calloc(MAX_N, sizeof(char)); clock_t start_time = clock(); diff --git a/project_euler/problem_22/sol1.c b/project_euler/problem_22/sol1.c index dbb44d56..f7df5f2d 100644 --- a/project_euler/problem_22/sol1.c +++ b/project_euler/problem_22/sol1.c @@ -16,7 +16,7 @@ /** * Alphabetical sorting using 'shell sort' algorithm - **/ + */ void shell_sort(char data[][MAX_NAME_LEN], int LEN) { const int gaps[] = {701, 301, 132, 57, 23, 10, 4, 1}; @@ -44,7 +44,7 @@ void shell_sort(char data[][MAX_NAME_LEN], int LEN) /** * Alphabetical sorting using 'lazy sort' algorithm - **/ + */ void lazy_sort(char data[][MAX_NAME_LEN], int LEN) { int i, j; diff --git a/project_euler/problem_23/sol1.c b/project_euler/problem_23/sol1.c index c2f3d1bc..e469659e 100644 --- a/project_euler/problem_23/sol1.c +++ b/project_euler/problem_23/sol1.c @@ -17,7 +17,7 @@ unsigned long MAX_N = 28123; /**< upper limit of numbers to check */ * -1 if N is deficient * 1 if N is abundant * 0 if N is perfect - **/ + */ char get_perfect_number(unsigned long N) { unsigned long sum = 1; @@ -43,7 +43,7 @@ char get_perfect_number(unsigned long N) /** * Is the given number an abundant number (1) or not (0) - **/ + */ unsigned long is_abundant(unsigned long N) { return get_perfect_number(N) == 1 ? 1 : 0; @@ -51,7 +51,7 @@ unsigned long is_abundant(unsigned long N) /** * Find the next abundant number after N and not including N - **/ + */ unsigned long get_next_abundant(unsigned long N) { unsigned long i; @@ -65,13 +65,13 @@ unsigned long get_next_abundant(unsigned long N) * of two abundant numbers. * \returns 1 - if yes * \returns 0 - if not - **/ + */ char is_sum_of_abundant(unsigned long N) { - /** optimized logic: + /* optimized logic: * i + j = N where both i and j should be abundant * hence we can simply check for j = N - i as we loop through i - **/ + */ for (unsigned long i = get_next_abundant(1); i <= (N >> 1); i = get_next_abundant(i)) if (is_abundant(N - i)) diff --git a/project_euler/problem_23/sol2.c b/project_euler/problem_23/sol2.c index a149010d..bc56089a 100644 --- a/project_euler/problem_23/sol2.c +++ b/project_euler/problem_23/sol2.c @@ -22,14 +22,14 @@ long MAX_N = 28123; /**< Limit of numbers to check */ * Using a whole byte to store a binary info would be redundant. * We will use each byte to represent 8 numbers by relying on bits. * This saves memory required by 1/8 - **/ + */ char *abundant_flags = NULL; /** * \returns -1 if N is deficient * \returns 1 if N is abundant * \returns 0 if N is perfect - **/ + */ char get_perfect_number(unsigned long N) { unsigned long sum = 1; @@ -55,7 +55,7 @@ char get_perfect_number(unsigned long N) /** * Is the given number an abundant number (1) or not (0) - **/ + */ char is_abundant(unsigned long N) { // return abundant_flags[N >> 3] & (1 << N % 8) ? 1 : 0; @@ -66,7 +66,7 @@ char is_abundant(unsigned long N) /** * Find the next abundant number after N and not including N - **/ + */ unsigned long get_next_abundant(unsigned long N) { unsigned long i; @@ -81,13 +81,13 @@ unsigned long get_next_abundant(unsigned long N) * of two abundant numbers. * \returns 1 - if yes * \returns 0 - if not - **/ + */ char is_sum_of_abundant(unsigned long N) { - /** optimized logic: + /* optimized logic: * i + j = N where both i and j should be abundant * hence we can simply check for j = N - i as we loop through i - **/ + */ for (unsigned long i = get_next_abundant(1); i <= (N >> 1); i = get_next_abundant(i)) if (is_abundant(N - i)) @@ -107,9 +107,9 @@ int main(int argc, char **argv) if (argc == 2) MAX_N = strtoul(argv[1], NULL, 10); - /** byte array to store flags to identify abundant numbers + /* byte array to store flags to identify abundant numbers * the flags are identified by bits - **/ + */ abundant_flags = (char *)calloc(MAX_N >> 3, 1); if (!abundant_flags) { diff --git a/project_euler/problem_25/sol1.c b/project_euler/problem_25/sol1.c index 30bd697b..9c7c2254 100644 --- a/project_euler/problem_25/sol1.c +++ b/project_euler/problem_25/sol1.c @@ -15,7 +15,7 @@ /** * Function to add arbitraty length decimal integers stored in an array.\n * a + b = c = new b - **/ + */ unsigned int add_numbers(unsigned char *a, unsigned char *b, unsigned char *c, int N) { diff --git a/sorting/shell_sort2.c b/sorting/shell_sort2.c index bf471592..362a7075 100644 --- a/sorting/shell_sort2.c +++ b/sorting/shell_sort2.c @@ -8,8 +8,6 @@ #include #include -#define ARRAY_LEN(x) (sizeof(x) / sizeof((x)[0])) - /** Helper function to print array values */ void show_data(int *arr, long len) { @@ -29,7 +27,7 @@ inline void swap(int *a, int *b) /** * Optimized algorithm - takes half the time as other - **/ + */ void shell_sort(int *array, long LEN) { const int gaps[] = {701, 301, 132, 57, 23, 10, 4, 1};