You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __CORTEX_UTILS_HEADERS__
  2. #define __CORTEX_UTILS_HEADERS__
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <vector>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include <assert.h>
  11. #ifdef __linux__
  12. #include <unistd.h>
  13. #else
  14. #include <io.h>
  15. #endif
  16. #include <float.h>
  17. #include <limits.h>
  18. #include <stdint.h>
  19. typedef std::vector<char *> cortexList;
  20. #if defined(_MSC_VER) && _MSC_VER < 1900
  21. #ifndef snprintf
  22. #define snprintf(buf,len, format,...) _snprintf_s(buf, len,len, format, __VA_ARGS__)
  23. #endif
  24. #endif
  25. #define TWO_PI (6.2831853071795864769252866f)
  26. void free_cortexList(cortexList * l);
  27. void normalize_array(float *a, int n);
  28. void top_k(float *a, int n, int k, int *index);
  29. int *read_intlist(char *gpu_list, int *ngpus, int d);
  30. double what_time_is_it_now( void );
  31. void shuffle(void *arr, size_t n, size_t size);
  32. void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections);
  33. void free_ptrs(void **ptrs, int n);
  34. int alphanum_to_int(char c);
  35. char int_to_alphanum(int i);
  36. int read_int(int fd);
  37. void write_int(int fd, int n);
  38. void read_all(int fd, char *buffer, size_t bytes);
  39. void write_all(int fd, char *buffer, size_t bytes);
  40. int read_all_fail(int fd, char *buffer, size_t bytes);
  41. int write_all_fail(int fd, char *buffer, size_t bytes);
  42. void find_replace(char *str, char *orig, char *rep, char *output);
  43. void malloc_error( void );
  44. void file_error(char *s);
  45. void strip(char *s);
  46. void strip_char(char *s, char bad);
  47. cortexList *split_str(char *s, char delim);
  48. char *fgetl(FILE *fp);
  49. cortexList *parse_csv_line(char *line);
  50. char *copy_string(char *s);
  51. int count_fields(char *line);
  52. float *parse_fields(char *line, int n);
  53. void scale_array(float *a, int n, float s);
  54. void translate_array(float *a, int n, float s);
  55. float constrain(float min, float max, float a);
  56. int constrain_int(int a, int min, int max);
  57. float rand_uniform(float min, float max);
  58. float rand_scale(float s);
  59. int rand_int(int min, int max);
  60. float sum_array(float *a, int n);
  61. float mag_array(float *a, int n);
  62. void mean_arrays(float **a, int n, int els, float *avg);
  63. float dist_array(float *a, float *b, int n, int sub);
  64. float **one_hot_encode(float *a, int n, int k);
  65. float sec(clock_t clocks);
  66. float rand_normal(void);
  67. uint32_t *read_map(char *filename);
  68. //void print_statistics(float *a, int n);
  69. #endif