Commit 5177c24a authored by Brice Videau's avatar Brice Videau

Refactoring.

parent c4fbf826
......@@ -93,6 +93,7 @@ module CCS
:CCS_INVALID_TYPE,
:CCS_INVALID_SCALE,
:CCS_INVALID_DISTRIBUTION,
:CCS_INVALID_EXPRESSION,
:CCS_INVALID_HYPERPARAMETER,
:CCS_INVALID_CONFIGURATION,
:CCS_INVALID_NAME,
......
......@@ -49,6 +49,7 @@ enum ccs_error_e {
CCS_INVALID_TYPE,
CCS_INVALID_SCALE,
CCS_INVALID_DISTRIBUTION,
CCS_INVALID_EXPRESSION,
CCS_INVALID_HYPERPARAMETER,
CCS_INVALID_CONFIGURATION,
CCS_INVALID_NAME,
......
......@@ -47,8 +47,7 @@ ccs_object_get_type(ccs_object_t object,
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
if (!obj)
return -CCS_INVALID_OBJECT;
if (!type_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(type_ret);
*type_ret = obj->type;
return CCS_SUCCESS;
}
......@@ -59,8 +58,7 @@ ccs_object_get_refcount(ccs_object_t object,
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
if (!obj)
return -CCS_INVALID_OBJECT;
if (!refcount_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(refcount_ret);
*refcount_ret = obj->refcount;
return CCS_SUCCESS;
}
......@@ -22,6 +22,23 @@ _ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) {
}
}
#define CCS_CHECK_OBJ(o, t) do { \
if (unlikely(!(o) || \
!((_ccs_object_template_t *)(o))->data || \
((_ccs_object_template_t *)(o))->obj.type != (t))) \
return -CCS_INVALID_OBJECT; \
} while (0)
#define CCS_CHECK_PTR(p) do { \
if (unlikely(!(p))) \
return -CCS_INVALID_VALUE; \
} while (0)
#define CCS_CHECK_ARY(c, a) do { \
if (unlikely((c > 0) && !(a))) \
return -CCS_INVALID_VALUE; \
} while (0)
struct _ccs_object_ops_s {
ccs_result_t (*del)(ccs_object_t object);
};
......@@ -36,6 +53,12 @@ struct _ccs_object_internal_s {
typedef struct _ccs_object_internal_s _ccs_object_internal_t;
struct _ccs_object_template_s {
_ccs_object_internal_t obj;
void *data;
};
typedef struct _ccs_object_template_s _ccs_object_template_t;
static inline __attribute__((always_inline)) void
_ccs_object_init(_ccs_object_internal_t *o,
ccs_object_type_t t,
......
......@@ -24,12 +24,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space,
ccs_datum_t *values,
void *user_data,
ccs_configuration_t *configuration_ret) {
if (!configuration_ret)
return -CCS_INVALID_VALUE;
if (num_values && !values)
return -CCS_INVALID_VALUE;
if (!num_values && values)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(configuration_ret);
CCS_CHECK_ARY(num_values, values);
ccs_result_t err;
size_t num;
err = ccs_configuration_space_get_num_hyperparameters(configuration_space, &num);
......@@ -63,10 +59,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space,
ccs_result_t
ccs_configuration_get_configuration_space(ccs_configuration_t configuration,
ccs_configuration_space_t *configuration_space_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!configuration_space_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(configuration_space_ret);
*configuration_space_ret = configuration->data->configuration_space;
return CCS_SUCCESS;
}
......@@ -74,10 +68,8 @@ ccs_configuration_get_configuration_space(ccs_configuration_t configurati
ccs_result_t
ccs_configuration_get_user_data(ccs_configuration_t configuration,
void **user_data_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!user_data_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(user_data_ret);
*user_data_ret = configuration->data->user_data;
return CCS_SUCCESS;
}
......@@ -86,10 +78,8 @@ ccs_result_t
ccs_configuration_get_value(ccs_configuration_t configuration,
size_t index,
ccs_datum_t *value_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!value_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(value_ret);
if (index >= configuration->data->num_values)
return -CCS_OUT_OF_BOUNDS;
*value_ret = configuration->data->values[index];
......@@ -100,8 +90,7 @@ ccs_result_t
ccs_configuration_set_value(ccs_configuration_t configuration,
size_t index,
ccs_datum_t value) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
if (index >= configuration->data->num_values)
return -CCS_OUT_OF_BOUNDS;
configuration->data->values[index] = value;
......@@ -113,14 +102,10 @@ ccs_configuration_get_values(ccs_configuration_t configuration,
size_t num_values,
ccs_datum_t *values,
size_t *num_values_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_ARY(num_values, values);
if (!num_values_ret && !values)
return -CCS_INVALID_VALUE;
if (num_values && !values)
return -CCS_INVALID_VALUE;
if (!num_values && values)
return -CCS_INVALID_VALUE;
size_t num = configuration->data->num_values;
if (values) {
if (num_values < num)
......@@ -140,10 +125,8 @@ ccs_result_t
ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
const char *name,
ccs_datum_t *value_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!name)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(name);
size_t index;
ccs_result_t err;
err = ccs_configuration_space_get_hyperparameter_index_by_name(
......@@ -156,8 +139,7 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
ccs_result_t
ccs_configuration_check(ccs_configuration_t configuration) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return ccs_configuration_space_check_configuration(
configuration->data->configuration_space, configuration);
}
......@@ -165,10 +147,8 @@ ccs_configuration_check(ccs_configuration_t configuration) {
ccs_result_t
ccs_configuration_hash(ccs_configuration_t configuration,
ccs_hash_t *hash_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!hash_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(hash_ret);
_ccs_configuration_data_t *data = configuration->data;
ccs_hash_t h, ht;
HASH_JEN(&(data->configuration_space), sizeof(data->configuration_space), h);
......@@ -186,12 +166,9 @@ ccs_result_t
ccs_configuration_cmp(ccs_configuration_t configuration,
ccs_configuration_t other_configuration,
int *cmp_ret) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
if (!other_configuration || !other_configuration->data)
return -CCS_INVALID_OBJECT;
if (!cmp_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
CCS_CHECK_OBJ(other_configuration, CCS_CONFIGURATION);
CCS_CHECK_PTR(cmp_ret);
if (configuration == other_configuration) {
*cmp_ret = 0;
return CCS_SUCCESS;
......
......@@ -94,8 +94,8 @@ ccs_result_t
ccs_create_configuration_space(const char *name,
void *user_data,
ccs_configuration_space_t *configuration_space_ret) {
if (!name || !configuration_space_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(name);
CCS_CHECK_PTR(configuration_space_ret);
uintptr_t mem = (uintptr_t)calloc(1, sizeof(struct _ccs_configuration_space_s) + sizeof(struct _ccs_configuration_space_data_s) + strlen(name) + 1);
if (!mem)
return -CCS_OUT_OF_MEMORY;
......@@ -133,10 +133,8 @@ arrays:
ccs_result_t
ccs_configuration_space_get_name(ccs_configuration_space_t configuration_space,
const char **name_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!name_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(name_ret);
*name_ret = configuration_space->data->name;
return CCS_SUCCESS;
}
......@@ -144,10 +142,8 @@ ccs_configuration_space_get_name(ccs_configuration_space_t configuration_space
ccs_result_t
ccs_configuration_space_get_user_data(ccs_configuration_space_t configuration_space,
void **user_data_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!user_data_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(user_data_ret);
*user_data_ret = configuration_space->data->user_data;
return CCS_SUCCESS;
}
......@@ -155,8 +151,8 @@ ccs_configuration_space_get_user_data(ccs_configuration_space_t configuration_
ccs_result_t
ccs_configuration_space_set_rng(ccs_configuration_space_t configuration_space,
ccs_rng_t rng) {
if (!configuration_space || !configuration_space->data || !rng)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(rng, CCS_RNG);
ccs_result_t err;
err = ccs_release_object(configuration_space->data->rng);
if(err)
......@@ -168,10 +164,8 @@ ccs_configuration_space_set_rng(ccs_configuration_space_t configuration_space,
ccs_result_t
ccs_configuration_space_get_rng(ccs_configuration_space_t configuration_space,
ccs_rng_t *rng_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!rng_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(rng_ret);
*rng_ret = configuration_space->data->rng;
return CCS_SUCCESS;
}
......@@ -191,8 +185,8 @@ ccs_result_t
ccs_configuration_space_add_hyperparameter(ccs_configuration_space_t configuration_space,
ccs_hyperparameter_t hyperparameter,
ccs_distribution_t distribution) {
if (!configuration_space || !configuration_space->data || !hyperparameter)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(hyperparameter, CCS_HYPERPARAMETER);
ccs_result_t err;
const char *name;
size_t sz_name;
......@@ -292,10 +286,8 @@ ccs_configuration_space_add_hyperparameters(ccs_configuration_space_t configura
size_t num_hyperparameters,
ccs_hyperparameter_t *hyperparameters,
ccs_distribution_t *distributions) {
if (!configuration_space)
return -CCS_INVALID_OBJECT;
if (num_hyperparameters > 0 && !hyperparameters)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_hyperparameters, hyperparameters);
for (size_t i = 0; i < num_hyperparameters; i++) {
ccs_distribution_t distribution = NULL;
if (distributions)
......@@ -313,10 +305,8 @@ ccs_configuration_space_add_hyperparameters(ccs_configuration_space_t configura
ccs_result_t
ccs_configuration_space_get_num_hyperparameters(ccs_configuration_space_t configuration_space,
size_t *num_hyperparameters_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!num_hyperparameters_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(num_hyperparameters_ret);
*num_hyperparameters_ret = utarray_len(configuration_space->data->hyperparameters);
return CCS_SUCCESS;
}
......@@ -325,10 +315,8 @@ ccs_result_t
ccs_configuration_space_get_hyperparameter(ccs_configuration_space_t configuration_space,
size_t index,
ccs_hyperparameter_t *hyperparameter_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!hyperparameter_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(hyperparameter_ret);
_ccs_hyperparameter_wrapper_t *wrapper = (_ccs_hyperparameter_wrapper_t*)
utarray_eltptr(configuration_space->data->hyperparameters, (unsigned int)index);
if (!wrapper)
......@@ -342,10 +330,9 @@ ccs_configuration_space_get_hyperparameter_by_name(
ccs_configuration_space_t configuration_space,
const char * name,
ccs_hyperparameter_t *hyperparameter_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!hyperparameter_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(name);
CCS_CHECK_PTR(hyperparameter_ret);
_ccs_hyperparameter_wrapper_t *wrapper;
size_t sz_name;
sz_name = strlen(name);
......@@ -362,10 +349,9 @@ ccs_configuration_space_get_hyperparameter_index_by_name(
ccs_configuration_space_t configuration_space,
const char *name,
size_t *index_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!index_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(name);
CCS_CHECK_PTR(index_ret);
_ccs_hyperparameter_wrapper_t *wrapper;
size_t sz_name;
sz_name = strlen(name);
......@@ -382,12 +368,9 @@ ccs_configuration_space_get_hyperparameter_index(
ccs_configuration_space_t configuration_space,
ccs_hyperparameter_t hyperparameter,
size_t *index_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!hyperparameter)
return -CCS_INVALID_HYPERPARAMETER;
if (!index_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(hyperparameter, CCS_HYPERPARAMETER);
CCS_CHECK_PTR(index_ret);
_ccs_hyperparameter_wrapper_t *wrapper;
HASH_FIND(hh_handle, configuration_space->data->handle_hash,
&hyperparameter, sizeof(ccs_hyperparameter_t), wrapper);
......@@ -403,10 +386,9 @@ ccs_configuration_space_get_hyperparameter_indexes(
size_t num_hyperparameters,
ccs_hyperparameter_t *hyperparameters,
size_t *indexes) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_hyperparameters && (!hyperparameters || !indexes ))
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_hyperparameters, hyperparameters);
CCS_CHECK_ARY(num_hyperparameters, indexes);
_ccs_hyperparameter_wrapper_t *wrapper;
for(size_t i = 0; i < num_hyperparameters; i++) {
HASH_FIND(hh_handle, configuration_space->data->handle_hash,
......@@ -424,12 +406,8 @@ ccs_configuration_space_get_hyperparameters(
size_t num_hyperparameters,
ccs_hyperparameter_t *hyperparameters,
size_t *num_hyperparameters_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_hyperparameters && !hyperparameters)
return -CCS_INVALID_VALUE;
if (hyperparameters && !num_hyperparameters)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_hyperparameters, hyperparameters);
if (!num_hyperparameters_ret && !hyperparameters)
return -CCS_INVALID_VALUE;
UT_array *array = configuration_space->data->hyperparameters;
......@@ -488,10 +466,8 @@ _set_actives(ccs_configuration_space_t configuration_space,
ccs_result_t
ccs_configuration_space_get_default_configuration(ccs_configuration_space_t configuration_space,
ccs_configuration_t *configuration_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!configuration_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(configuration_ret);
ccs_result_t err;
ccs_configuration_t config;
err = ccs_create_configuration(configuration_space, 0, NULL, NULL, &config);
......@@ -603,10 +579,8 @@ _check_configuration(ccs_configuration_space_t configuration_space,
ccs_result_t
ccs_configuration_space_check_configuration(ccs_configuration_space_t configuration_space,
ccs_configuration_t configuration) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
if (configuration->data->configuration_space != configuration_space)
return -CCS_INVALID_CONFIGURATION;
if (!configuration_space->data->graph_ok) {
......@@ -624,10 +598,8 @@ ccs_result_t
ccs_configuration_space_check_configuration_values(ccs_configuration_space_t configuration_space,
size_t num_values,
ccs_datum_t *values) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!values)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_values, values);
if (!configuration_space->data->graph_ok) {
ccs_result_t err;
err = _generate_constraints(configuration_space);
......@@ -667,10 +639,8 @@ _sample(ccs_configuration_space_t configuration_space,
ccs_result_t
ccs_configuration_space_sample(ccs_configuration_space_t configuration_space,
ccs_configuration_t *configuration_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!configuration_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(configuration_ret);
ccs_result_t err;
ccs_configuration_t config;
if (!configuration_space->data->graph_ok) {
......@@ -703,10 +673,8 @@ ccs_result_t
ccs_configuration_space_samples(ccs_configuration_space_t configuration_space,
size_t num_configurations,
ccs_configuration_t *configurations) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_configurations && !configurations)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_configurations, configurations);
if (!num_configurations)
return CCS_SUCCESS;
ccs_result_t err;
......@@ -948,8 +916,8 @@ ccs_result_t
ccs_configuration_space_set_condition(ccs_configuration_space_t configuration_space,
size_t hyperparameter_index,
ccs_expression_t expression) {
if (!configuration_space || !configuration_space->data || !expression)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
_ccs_hyperparameter_wrapper_t *wrapper = (_ccs_hyperparameter_wrapper_t*)
utarray_eltptr(configuration_space->data->hyperparameters,
(unsigned int)hyperparameter_index);
......@@ -977,10 +945,8 @@ ccs_result_t
ccs_configuration_space_get_condition(ccs_configuration_space_t configuration_space,
size_t hyperparameter_index,
ccs_expression_t *expression_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!expression_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(expression_ret);
_ccs_hyperparameter_wrapper_t *wrapper = (_ccs_hyperparameter_wrapper_t*)
utarray_eltptr(configuration_space->data->hyperparameters,
(unsigned int)hyperparameter_index);
......@@ -995,10 +961,8 @@ ccs_configuration_space_get_conditions(ccs_configuration_space_t configuration_
size_t num_expressions,
ccs_expression_t *expressions,
size_t *num_expressions_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_expressions && !expressions)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_expressions, expressions);
if (!expressions && !num_expressions_ret)
return -CCS_INVALID_VALUE;
UT_array *array = configuration_space->data->hyperparameters;
......@@ -1025,8 +989,8 @@ ccs_configuration_space_get_conditions(ccs_configuration_space_t configuration_
ccs_result_t
ccs_configuration_space_add_forbidden_clause(ccs_configuration_space_t configuration_space,
ccs_expression_t expression) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
ccs_result_t err;
err = ccs_expression_check_context(expression,
(ccs_context_t)configuration_space);
......@@ -1061,10 +1025,8 @@ ccs_result_t
ccs_configuration_space_add_forbidden_clauses(ccs_configuration_space_t configuration_space,
size_t num_expressions,
ccs_expression_t *expressions) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_expressions && !expressions)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_expressions, expressions);
for (size_t i = 0; i < num_expressions; i++) {
ccs_result_t err;
err = ccs_configuration_space_add_forbidden_clause(configuration_space,
......@@ -1079,10 +1041,8 @@ ccs_result_t
ccs_configuration_space_get_forbidden_clause(ccs_configuration_space_t configuration_space,
size_t index,
ccs_expression_t *expression_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (!expression_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_PTR(expression_ret);
ccs_expression_t *p_expr = (ccs_expression_t*)
utarray_eltptr(configuration_space->data->forbidden_clauses,
(unsigned int)index);
......@@ -1097,10 +1057,8 @@ ccs_configuration_space_get_forbidden_clauses(ccs_configuration_space_t configu
size_t num_expressions,
ccs_expression_t *expressions,
size_t *num_expressions_ret) {
if (!configuration_space || !configuration_space->data)
return -CCS_INVALID_OBJECT;
if (num_expressions && !expressions)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(configuration_space, CCS_CONFIGURATION_SPACE);
CCS_CHECK_ARY(num_expressions, expressions);
if (!expressions && !num_expressions_ret)
return -CCS_INVALID_VALUE;
UT_array *array = configuration_space->data->forbidden_clauses;
......
......@@ -10,10 +10,8 @@ ccs_distribution_get_ops(ccs_distribution_t distribution) {
ccs_result_t
ccs_distribution_get_type(ccs_distribution_t distribution,
ccs_distribution_type_t *type_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!type_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(type_ret);
*type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->type;
return CCS_SUCCESS;
}
......@@ -21,10 +19,8 @@ ccs_distribution_get_type(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_get_data_type(ccs_distribution_t distribution,
ccs_numeric_type_t *data_type_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!data_type_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(data_type_ret);
*data_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->data_type;
return CCS_SUCCESS;
}
......@@ -32,10 +28,8 @@ ccs_distribution_get_data_type(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_get_dimension(ccs_distribution_t distribution,
size_t *dimension_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!dimension_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(dimension_ret);
*dimension_ret = 1;
return CCS_SUCCESS;
}
......@@ -44,10 +38,8 @@ ccs_distribution_get_dimension(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_get_scale_type(ccs_distribution_t distribution,
ccs_scale_type_t *scale_type_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!scale_type_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(scale_type_ret);
*scale_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->scale_type;
return CCS_SUCCESS;
}
......@@ -55,10 +47,8 @@ ccs_distribution_get_scale_type(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_get_quantization(ccs_distribution_t distribution,
ccs_numeric_t *quantization_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!quantization_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(quantization_ret);
*quantization_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->quantization;
return CCS_SUCCESS;
}
......@@ -66,10 +56,8 @@ ccs_distribution_get_quantization(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_get_bounds(ccs_distribution_t distribution,
ccs_interval_t *interval_ret) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!interval_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(interval_ret);
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution);
return ops->get_bounds(distribution->data, interval_ret);
}
......@@ -78,10 +66,11 @@ ccs_result_t
ccs_distribution_check_oversampling(ccs_distribution_t distribution,
ccs_interval_t *interval,
ccs_bool_t *oversampling_ret) {
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(interval);
CCS_CHECK_PTR(oversampling_ret);
ccs_result_t err;
ccs_interval_t d_interval;
if (!interval || !oversampling_ret)
return -CCS_INVALID_VALUE;
err = ccs_distribution_get_bounds(distribution, &d_interval);
if (err)
......@@ -104,13 +93,11 @@ ccs_distribution_check_oversampling(ccs_distribution_t distribution,
ccs_result_t
ccs_distribution_sample(ccs_distribution_t distribution,
ccs_rng_t rng,
ccs_numeric_t *value) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!value)
return -CCS_INVALID_VALUE;
ccs_numeric_t *value_ret) {
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(value_ret);
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution);
return ops->samples(distribution->data, rng, 1, value);
return ops->samples(distribution->data, rng, 1, value_ret);
}
ccs_result_t
......@@ -118,10 +105,10 @@ ccs_distribution_samples(ccs_distribution_t distribution,
ccs_rng_t rng,
size_t num_values,
ccs_numeric_t *values) {
if (!distribution || !distribution->data)
return -CCS_INVALID_OBJECT;
if (!num_values || !values)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
if (!num_values)
return CCS_SUCCESS;
CCS_CHECK_ARY(num_values, values);
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution);
return ops->samples(distribution->data, rng, num_values, values);
}
......
......@@ -214,8 +214,7 @@ ccs_create_normal_distribution(ccs_numeric_type_t data_type,
ccs_scale_type_t scale_type,
ccs_numeric_t quantization,
ccs_distribution_t *distribution_ret) {
if (!distribution_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(distribution_ret);
if (data_type != CCS_NUM_FLOAT && data_type != CCS_NUM_INTEGER)
return -CCS_INVALID_TYPE;
if (scale_type != CCS_LINEAR && scale_type != CCS_LOGARITHMIC)
......@@ -253,9 +252,8 @@ extern ccs_result_t
ccs_normal_distribution_get_parameters(ccs_distribution_t distribution,
ccs_float_t *mu,
ccs_float_t *sigma) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION)
return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_NORMAL)
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_NORMAL)
return -CCS_INVALID_OBJECT;
if (!mu && !sigma)
return -CCS_INVALID_VALUE;
......
......@@ -6,7 +6,7 @@
struct _ccs_distribution_roulette_data_s {
_ccs_distribution_common_data_t common_data;
ccs_int_t num_areas;
size_t num_areas;
ccs_float_t *areas;
};
typedef struct _ccs_distribution_roulette_data_s _ccs_distribution_roulette_data_t;
......@@ -40,7 +40,7 @@ _ccs_distribution_roulette_get_bounds(_ccs_distribution_data_t *data,
interval_ret->type = CCS_NUM_INTEGER;
interval_ret->lower = CCSI(INT64_C(0));
interval_ret->upper = CCSI(d->num_areas);
interval_ret->upper = CCSI((ccs_int_t)(d->num_areas));
interval_ret->lower_included = CCS_TRUE;
interval_ret->upper_included = CCS_FALSE;
return CCS_SUCCESS;
......@@ -83,7 +83,9 @@ ccs_result_t
ccs_create_roulette_distribution(size_t num_areas,
ccs_float_t *areas,
ccs_distribution_t *distribution_ret) {
if (!distribution_ret || !areas || !num_areas || num_areas > INT64_MAX)
CCS_CHECK_ARY(num_areas, areas);
CCS_CHECK_PTR(distribution_ret);
if (!num_areas || num_areas > INT64_MAX)
return -CCS_INVALID_VALUE;
ccs_float_t sum = 0.0;
......@@ -130,12 +132,10 @@ ccs_create_roulette_distribution(size_t num_areas,
ccs_result_t
ccs_roulette_distribution_get_num_areas(ccs_distribution_t distribution,
size_t *num_areas_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION)
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_PTR(num_areas_ret);
if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT;