aboutsummaryrefslogtreecommitdiff
path: root/include/util.h
blob: ec415ac768286d4f1c70a1a8d970f32114f81937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include "MSVMMaj.h"

#define Calloc(type, n) (type *)calloc((n), sizeof(type))
#define Malloc(type, n) (type *)malloc((n)*sizeof(type))
#define Memset(var, type, n) memset(var, 0, (n)*sizeof(type))
#define maximum(a, b) a > b ? a : b
#define minimum(a, b) a < b ? a : b

void read_data(struct Data *dataset, char *data_file);

void read_model(struct Model *model, char *model_filename);
void write_model(struct Model *model, char *output_filename);

void write_predictions(struct Data *data, long *predy, char *output_filename);

int check_argv(int argc, char **argv, char *str);
int check_argv_eq(int argc, char **argv, char *str);

void set_print_string_function(void (*print_func)(const char *));
void info(const char *fmt,...);

double rnd();

void matrix_set(double *M, long cols, long i, long j, double val);
void matrix_add(double *M, long cols, long i, long j, double val);
void matrix_mult(double *M, long cols, long i, long j, double val);
double matrix_get(double *M, long cols, long i, long j);

void matrix3_set(double *M, long N2, long N3, long i, long j, long k, double val);
double matrix3_get(double *M, long N2, long N3, long i, long j, long k);

void allocate_model(struct Model *model);
void free_model(struct Model *model);
void free_data(struct Data *data);

void print_matrix(double *M, long rows, long cols);