00001 #ifndef UTILS_H 00002 #define UTILS_H 00003 #include <stdio.h> 00004 #include <time.h> 00005 #include "list.h" 00006 00007 #define SECRET_NUM -1234 00008 #define TWO_PI 6.2831853071795864769252866 00009 00010 int *read_map(char *filename); 00011 void shuffle(void *arr, size_t n, size_t size); 00012 void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections); 00013 void free_ptrs(void **ptrs, int n); 00014 char *basecfg(char *cfgfile); 00015 int alphanum_to_int(char c); 00016 char int_to_alphanum(int i); 00017 int read_int(int fd); 00018 void write_int(int fd, int n); 00019 void read_all(int fd, char *buffer, size_t bytes); 00020 void write_all(int fd, char *buffer, size_t bytes); 00021 int read_all_fail(int fd, char *buffer, size_t bytes); 00022 int write_all_fail(int fd, char *buffer, size_t bytes); 00023 void find_replace(char *str, char *orig, char *rep, char *output); 00024 void error(const char *s); 00025 void malloc_error(); 00026 void file_error(char *s); 00027 void strip(char *s); 00028 void strip_char(char *s, char bad); 00029 void top_k(float *a, int n, int k, int *index); 00030 list *split_str(char *s, char delim); 00031 char *fgetl(FILE *fp); 00032 list *parse_csv_line(char *line); 00033 char *copy_string(char *s); 00034 int count_fields(char *line); 00035 float *parse_fields(char *line, int n); 00036 void normalize_array(float *a, int n); 00037 void scale_array(float *a, int n, float s); 00038 void translate_array(float *a, int n, float s); 00039 int max_index(float *a, int n); 00040 float constrain(float min, float max, float a); 00041 int constrain_int(int a, int min, int max); 00042 float mse_array(float *a, int n); 00043 float rand_normal(); 00044 size_t rand_size_t(); 00045 float rand_uniform(float min, float max); 00046 float rand_scale(float s); 00047 int rand_int(int min, int max); 00048 float sum_array(float *a, int n); 00049 float mean_array(float *a, int n); 00050 void mean_arrays(float **a, int n, int els, float *avg); 00051 float variance_array(float *a, int n); 00052 float mag_array(float *a, int n); 00053 float dist_array(float *a, float *b, int n, int sub); 00054 float **one_hot_encode(float *a, int n, int k); 00055 float sec(clock_t clocks); 00056 int find_int_arg(int argc, char **argv, char *arg, int def); 00057 float find_float_arg(int argc, char **argv, char *arg, float def); 00058 int find_arg(int argc, char* argv[], char *arg); 00059 char *find_char_arg(int argc, char **argv, char *arg, char *def); 00060 int sample_array(float *a, int n); 00061 void print_statistics(float *a, int n); 00062 00063 #endif 00064