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.
118 lines
3.5 KiB
118 lines
3.5 KiB
#pragma once |
|
#ifndef UTILS_H |
|
#define UTILS_H |
|
#include "define_inc.h" |
|
#include <stdio.h> |
|
#include <time.h> |
|
#include "darknet.h" |
|
#include "list.h" |
|
|
|
#ifndef clip3 |
|
#define clip3(a, b, c) fmax(fmin(b, c), a) |
|
#endif |
|
|
|
/* set debug level */ |
|
#define AMBA_DATA_PROCESS_DEBUG_ENABLE 0 // Disable it for real applicaton, enable it when debug |
|
#define AMBA_DATA_PROCESS_DEBUG_LEVEL (L_INFO) |
|
|
|
typedef enum amba_ssd_debug_level_s |
|
{ |
|
AMBA_DATA_PROCESS_DEBUG_LEVEL_ERROR = 0, |
|
AMBA_DATA_PROCESS_DEBUG_LEVEL_WARNING = 1, |
|
AMBA_DATA_PROCESS_DEBUG_LEVEL_INFO = 2, |
|
AMBA_DATA_PROCESS_DEBUG_LEVEL_DEBUG = 3, |
|
} amba_ssd_debug_level_t; |
|
|
|
#define L_ERROR AMBA_DATA_PROCESS_DEBUG_LEVEL_ERROR |
|
#define L_WARNING AMBA_DATA_PROCESS_DEBUG_LEVEL_WARNING |
|
#define L_INFO AMBA_DATA_PROCESS_DEBUG_LEVEL_INFO |
|
#define L_DEBUG AMBA_DATA_PROCESS_DEBUG_LEVEL_DEBUG |
|
|
|
#if (AMBA_DATA_PROCESS_DEBUG_ENABLE == 1) |
|
#define DPRINT(level, ...) \ |
|
do {\ |
|
if ((level) <= AMBA_DATA_PROCESS_DEBUG_LEVEL) {\ |
|
printf(__VA_ARGS__);\ |
|
}\ |
|
} while(0) |
|
#else |
|
#define DPRINT(level, ...) |
|
#endif |
|
|
|
#define TIME(a) \ |
|
do { \ |
|
double start = what_time_is_it_now(); \ |
|
a; \ |
|
printf("%s took: %f seconds\n", #a, what_time_is_it_now() - start); \ |
|
} while (0) |
|
|
|
#define SECRET_NUM -1234 |
|
#define TWO_PI 6.2831853071795864769252866f |
|
|
|
double what_time_is_it_now(); |
|
void shuffle(void *arr, size_t n, size_t size); |
|
void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections); |
|
void free_ptrs(void **ptrs, int n); |
|
int alphanum_to_int(char c); |
|
char int_to_alphanum(int i); |
|
int read_int(int fd); |
|
void write_int(int fd, int n); |
|
void read_all(int fd, char *buffer, size_t bytes); |
|
void write_all(int fd, char *buffer, size_t bytes); |
|
int read_all_fail(int fd, char *buffer, size_t bytes); |
|
int write_all_fail(int fd, char *buffer, size_t bytes); |
|
void find_replace(char *str, char *orig, char *rep, char *output); |
|
void malloc_error(); |
|
void file_error(char *s); |
|
void strip(char *s); |
|
void strip_char(char *s, char bad); |
|
//list *split_str(char *s, char delim); |
|
char *fgetl(FILE *fp); |
|
|
|
|
|
int count_fields(char *line); |
|
float *parse_fields(char *line, int n); |
|
void translate_array(float *a, int n, float s); |
|
float constrain(float min, float max, float a); |
|
int constrain_int(int a, int min, int max); |
|
float rand_scale(float s); |
|
int rand_int(int min, int max); |
|
void mean_arrays(float **a, int n, int els, float *avg); |
|
float dist_array(float *a, float *b, int n, int sub); |
|
float **one_hot_encode(float *a, int n, int k); |
|
float sec(clock_t clocks); |
|
void print_statistics(float *a, int n); |
|
int int_index(int *a, int val, int n); |
|
|
|
|
|
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); |
|
char *find_char_arg(int argc, char **argv, char *arg, char *def); |
|
|
|
void find_replace(char *str, char *orig, char *rep, char *output); |
|
void free_ptrs(void **ptrs, int n); |
|
char *fgetl(FILE *fp); |
|
void strip(char *s); |
|
float sec(clock_t clocks); |
|
|
|
void top_k(float *a, int n, int k, int *index); |
|
int *read_map(char *filename); |
|
void error(const char *s); |
|
int max_index(float *a, int n); |
|
int sample_array(float *a, int n); |
|
|
|
float mse_array(float *a, int n); |
|
float variance_array(float *a, int n); |
|
float mag_array(float *a, int n); |
|
void scale_array(float *a, int n, float s); |
|
float mean_array(float *a, int n); |
|
float sum_array(float *a, int n); |
|
void normalize_array(float *a, int n); |
|
|
|
//size_t rand_size_t(); |
|
float rand_normal(); |
|
float rand_uniform(float min, float max); |
|
|
|
#endif |
|
|
|
|