2013-11-13 22:50:38 +04:00
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
#include <stdio.h>
|
2014-10-22 01:49:18 +04:00
|
|
|
#include <time.h>
|
2013-11-13 22:50:38 +04:00
|
|
|
#include "list.h"
|
|
|
|
|
2015-07-17 23:18:05 +03:00
|
|
|
#define SECRET_NUM -1234
|
2016-08-11 21:54:24 +03:00
|
|
|
#define TWO_PI 6.2831853071795864769252866
|
2015-07-17 23:18:05 +03:00
|
|
|
|
2015-09-05 03:52:44 +03:00
|
|
|
void shuffle(void *arr, size_t n, size_t size);
|
|
|
|
void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections);
|
2015-09-01 21:21:01 +03:00
|
|
|
void free_ptrs(void **ptrs, int n);
|
2015-03-06 21:49:03 +03:00
|
|
|
char *basecfg(char *cfgfile);
|
2015-02-24 05:52:05 +03:00
|
|
|
int alphanum_to_int(char c);
|
|
|
|
char int_to_alphanum(int i);
|
2016-05-07 02:25:16 +03:00
|
|
|
int read_int(int fd);
|
|
|
|
void write_int(int fd, int n);
|
2015-02-07 05:53:53 +03:00
|
|
|
void read_all(int fd, char *buffer, size_t bytes);
|
|
|
|
void write_all(int fd, char *buffer, size_t bytes);
|
2016-05-07 02:25:16 +03:00
|
|
|
int read_all_fail(int fd, char *buffer, size_t bytes);
|
|
|
|
int write_all_fail(int fd, char *buffer, size_t bytes);
|
2014-11-19 00:51:04 +03:00
|
|
|
char *find_replace(char *str, char *orig, char *rep);
|
2015-01-23 03:38:24 +03:00
|
|
|
void error(const char *s);
|
2013-11-13 22:50:38 +04:00
|
|
|
void malloc_error();
|
|
|
|
void file_error(char *s);
|
|
|
|
void strip(char *s);
|
|
|
|
void strip_char(char *s, char bad);
|
2014-11-19 00:51:04 +03:00
|
|
|
void top_k(float *a, int n, int k, int *index);
|
2013-11-13 22:50:38 +04:00
|
|
|
list *split_str(char *s, char delim);
|
|
|
|
char *fgetl(FILE *fp);
|
|
|
|
list *parse_csv_line(char *line);
|
|
|
|
char *copy_string(char *s);
|
|
|
|
int count_fields(char *line);
|
2014-01-29 04:28:42 +04:00
|
|
|
float *parse_fields(char *line, int n);
|
|
|
|
void normalize_array(float *a, int n);
|
|
|
|
void scale_array(float *a, int n, float s);
|
|
|
|
void translate_array(float *a, int n, float s);
|
|
|
|
int max_index(float *a, int n);
|
2015-03-24 23:20:56 +03:00
|
|
|
float constrain(float min, float max, float a);
|
2016-06-03 01:25:24 +03:00
|
|
|
int constrain_int(int a, int min, int max);
|
2015-01-28 00:31:06 +03:00
|
|
|
float mse_array(float *a, int n);
|
2014-01-29 04:28:42 +04:00
|
|
|
float rand_normal();
|
2016-05-07 02:25:16 +03:00
|
|
|
size_t rand_size_t();
|
2016-01-19 02:40:14 +03:00
|
|
|
float rand_uniform(float min, float max);
|
2016-03-01 00:54:12 +03:00
|
|
|
int rand_int(int min, int max);
|
2014-08-11 23:52:07 +04:00
|
|
|
float sum_array(float *a, int n);
|
2014-01-29 04:28:42 +04:00
|
|
|
float mean_array(float *a, int n);
|
2015-12-01 02:04:09 +03:00
|
|
|
void mean_arrays(float **a, int n, int els, float *avg);
|
2014-01-29 04:28:42 +04:00
|
|
|
float variance_array(float *a, int n);
|
2015-02-04 23:41:20 +03:00
|
|
|
float mag_array(float *a, int n);
|
2016-06-03 01:25:24 +03:00
|
|
|
float dist_array(float *a, float *b, int n, int sub);
|
2014-01-29 04:28:42 +04:00
|
|
|
float **one_hot_encode(float *a, int n, int k);
|
2014-10-22 01:49:18 +04:00
|
|
|
float sec(clock_t clocks);
|
2015-07-08 10:36:43 +03:00
|
|
|
int find_int_arg(int argc, char **argv, char *arg, int def);
|
|
|
|
float find_float_arg(int argc, char **argv, char *arg, float def);
|
|
|
|
int find_arg(int argc, char* argv[], char *arg);
|
2015-07-10 01:22:14 +03:00
|
|
|
char *find_char_arg(int argc, char **argv, char *arg, char *def);
|
2016-05-07 02:25:16 +03:00
|
|
|
int sample_array(float *a, int n);
|
2015-04-24 20:27:50 +03:00
|
|
|
|
2013-11-13 22:50:38 +04:00
|
|
|
#endif
|
|
|
|
|