base.h 4.4 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1
2
#ifndef _CCS_BASE_H
#define _CCS_BASE_H
3
4
#include <limits.h>
#include <math.h>
Brice Videau's avatar
Brice Videau committed
5

Brice Videau's avatar
Brice Videau committed
6
7
8
9
#ifdef __cplusplus
extern "C" {
#endif

10
11
12
#define likely(x)      __builtin_expect(!!(x), 1)
#define unlikely(x)    __builtin_expect(!!(x), 0)

13
14
typedef double  ccs_float_t;
typedef int64_t ccs_int_t;
15
16
17
18
19
20
21
22
typedef int32_t ccs_bool_t;

#define CCS_TRUE ((ccs_bool_t)(1))
#define CCS_FALSE ((ccs_bool_t)(0))

#define CCS_INT_MAX LLONG_MAX
#define CCS_INT_MIN LLONG_MIN
#define CCS_INFINITY INFINITY
23

Brice Videau's avatar
Brice Videau committed
24
typedef struct _ccs_rng_s                 *ccs_rng_t;
Brice Videau's avatar
Brice Videau committed
25
26
27
typedef struct _ccs_distribution_s        *ccs_distribution_t;
typedef struct _ccs_hyperparameter_s      *ccs_hyperparameter_t;
typedef struct _ccs_expression_s          *ccs_expression_t;
28
typedef struct _ccs_context_s             *ccs_context_t;
Brice Videau's avatar
Brice Videau committed
29
30
typedef struct _ccs_configuration_space_s *ccs_configuration_space_t;
typedef struct _ccs_configuration_s       *ccs_configuration_t;
31
32
33
typedef struct _ccs_objective_space_s     *ccs_objective_space_t;
typedef struct _ccs_result_s              *ccs_result_t;
typedef struct _ccs_tuner_s               *ccs_tuner_t;
Brice Videau's avatar
Brice Videau committed
34
35
36
37

enum ccs_error_e {
	CCS_SUCCESS,
	CCS_INVALID_OBJECT,
Brice Videau's avatar
Brice Videau committed
38
	CCS_INVALID_VALUE,
Brice Videau's avatar
Brice Videau committed
39
	CCS_INVALID_TYPE,
40
	CCS_INVALID_SCALE,
41
42
	CCS_INVALID_DISTRIBUTION,
	CCS_INVALID_HYPERPARAMETER,
43
	CCS_INVALID_CONFIGURATION,
44
	CCS_INVALID_NAME,
Brice Videau's avatar
Brice Videau committed
45
46
	CCS_INVALID_CONDITION,
	CCS_INVALID_GRAPH,
47
48
	CCS_TYPE_NOT_COMPARABLE,
	CCS_INVALID_BOUNDS,
49
	CCS_OUT_OF_BOUNDS,
50
	CCS_SAMPLING_UNSUCCESSFUL,
51
	CCS_INACTIVE_HYPERPARAMETER,
Brice Videau's avatar
Brice Videau committed
52
	CCS_ENOMEM,
53
	CCS_UNSUPPORTED_OPERATION,
Brice Videau's avatar
Brice Videau committed
54
55
56
57
	CCS_ERROR_MAX,
	CCS_ERROR_FORCE_32BIT = INT_MAX
};

Brice Videau's avatar
Brice Videau committed
58
typedef int ccs_error_t;
Brice Videau's avatar
Brice Videau committed
59
60

enum ccs_object_type_e {
Brice Videau's avatar
Brice Videau committed
61
	CCS_RNG,
Brice Videau's avatar
Brice Videau committed
62
63
64
65
66
67
68
69
70
71
72
73
	CCS_DISTRIBUTION,
	CCS_HYPERPARAMETER,
	CCS_EXPRESSION,
	CCS_CONFIGURATION_SPACE,
	CCS_CONFIGURATION,
	CCS_OBJECT_TYPE_MAX,
	CCS_OBJECT_TYPE_FORCE_32BIT = INT_MAX
};

typedef enum ccs_object_type_e ccs_object_type_t;

enum ccs_data_type_e {
74
	CCS_NONE,
75
	CCS_INACTIVE,
Brice Videau's avatar
Brice Videau committed
76
77
	CCS_INTEGER,
	CCS_FLOAT,
78
	CCS_BOOLEAN,
Brice Videau's avatar
Brice Videau committed
79
80
81
	CCS_STRING,
	CCS_OBJECT,
	CCS_DATA_TYPE_MAX,
82
	CCS_DATA_TYPE_FORCE_64BIT = INT64_MAX
Brice Videau's avatar
Brice Videau committed
83
84
85
86
};

typedef enum ccs_data_type_e ccs_data_type_t;

87
88
enum ccs_numeric_type_e {
	CCS_NUM_INTEGER = CCS_INTEGER,
89
90
91
	CCS_NUM_FLOAT = CCS_FLOAT,
	CCS_NUM_TYPE_MAX,
	CCS_NUM_TYPE_FORCE_64BIT = INT64_MAX
92
93
94
95
};

typedef enum ccs_numeric_type_e ccs_numeric_type_t;

Brice Videau's avatar
Brice Videau committed
96
typedef void * ccs_object_t;
Brice Videau's avatar
Brice Videau committed
97

98
99
100
union ccs_numeric_u {
	ccs_float_t   f;
	ccs_int_t     i;
Brice Videau's avatar
Brice Videau committed
101
102
103
104
105
106
107
#ifdef __cplusplus
	ccs_numeric_u() : i(0L) {}
	ccs_numeric_u(float v) : f((ccs_float_t)v) {}
	ccs_numeric_u(int v) : i((ccs_int_t)v) {}
	ccs_numeric_u(ccs_int_t v) : i(v) {}
	ccs_numeric_u(ccs_float_t v) : f(v) {}
#endif
108
109
110
};

typedef union ccs_numeric_u ccs_numeric_t;
Brice Videau's avatar
Brice Videau committed
111

Brice Videau's avatar
Brice Videau committed
112
113
114
115
#ifdef __cplusplus
#define CCSF(v) v
#define CCSI(v) v
#else
116
117
#define CCSF(v) ((ccs_numeric_t){ .f = v })
#define CCSI(v) ((ccs_numeric_t){ .i = v })
Brice Videau's avatar
Brice Videau committed
118
#endif
Brice Videau's avatar
Brice Videau committed
119

Brice Videau's avatar
Brice Videau committed
120
union ccs_value_u {
121
122
	ccs_float_t   f;
	ccs_int_t     i;
123
	const char   *s;
Brice Videau's avatar
Brice Videau committed
124
	ccs_object_t  o;
Brice Videau's avatar
Brice Videau committed
125
126
127
128
129
130
131
132
133
#ifdef __cplusplus
	ccs_value_u() : i(0L) {}
	ccs_value_u(float v) : f((ccs_float_t)v) {}
	ccs_value_u(int v) : i((ccs_int_t)v) {}
	ccs_value_u(ccs_float_t v) : f(v) {}
	ccs_value_u(ccs_int_t v) : i(v) {}
	ccs_value_u(char *v) : s(v) {}
	ccs_value_u(ccs_object_t v) : o(v) {}
#endif
Brice Videau's avatar
Brice Videau committed
134
135
136
137
};

typedef union ccs_value_u ccs_value_t;

138
struct ccs_datum_s {
Brice Videau's avatar
Brice Videau committed
139
140
141
142
	ccs_value_t value;
	ccs_data_type_t type;
};

143
typedef struct ccs_datum_s ccs_datum_t;
Brice Videau's avatar
Brice Videau committed
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
static inline ccs_datum_t
ccs_bool(ccs_bool_t v) {
	ccs_datum_t d;
	d.type = CCS_BOOLEAN;
	d.value.i = v;
	return d;
}

static inline ccs_datum_t
ccs_float(ccs_float_t v) {
	ccs_datum_t d;
	d.type = CCS_FLOAT;
	d.value.f = v;
	return d;
}

static inline ccs_datum_t
ccs_int(ccs_int_t v) {
	ccs_datum_t d;
	d.type = CCS_INTEGER;
	d.value.i = v;
	return d;
}

static inline ccs_datum_t
ccs_object(ccs_object_t v) {
	ccs_datum_t d;
	d.type = CCS_OBJECT;
	d.value.o = v;
	return d;
}

static inline ccs_datum_t
ccs_string(const char *v) {
	ccs_datum_t d;
	d.type = CCS_STRING;
	d.value.s = v;
	return d;
}

185
extern const ccs_datum_t ccs_none;
186
extern const ccs_datum_t ccs_inactive;
187
188

#define CCS_NONE_VAL {{0}, CCS_NONE}
189
#define CCS_INACTIVE_VAL {{0}, CCS_INACTIVE}
190

Brice Videau's avatar
Brice Videau committed
191
192
193
extern ccs_error_t
ccs_init();

Brice Videau's avatar
Brice Videau committed
194
extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
195
ccs_retain_object(ccs_object_t object);
Brice Videau's avatar
Brice Videau committed
196
197

extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
198
ccs_release_object(ccs_object_t object);
Brice Videau's avatar
Brice Videau committed
199
200

extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
201
202
ccs_object_get_type(ccs_object_t       object,
                    ccs_object_type_t *type_ret);
Brice Videau's avatar
Brice Videau committed
203
204

extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
205
206
ccs_object_get_refcount(ccs_object_t  object,
                        int32_t      *refcount_ret);
Brice Videau's avatar
Brice Videau committed
207

Brice Videau's avatar
Brice Videau committed
208
209
210
211
#ifdef __cplusplus
}
#endif

Brice Videau's avatar
Brice Videau committed
212
#endif //_CCS_BASE_H