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

Refactoring.

parent c4fbf826
...@@ -93,6 +93,7 @@ module CCS ...@@ -93,6 +93,7 @@ module CCS
:CCS_INVALID_TYPE, :CCS_INVALID_TYPE,
:CCS_INVALID_SCALE, :CCS_INVALID_SCALE,
:CCS_INVALID_DISTRIBUTION, :CCS_INVALID_DISTRIBUTION,
:CCS_INVALID_EXPRESSION,
:CCS_INVALID_HYPERPARAMETER, :CCS_INVALID_HYPERPARAMETER,
:CCS_INVALID_CONFIGURATION, :CCS_INVALID_CONFIGURATION,
:CCS_INVALID_NAME, :CCS_INVALID_NAME,
......
...@@ -49,6 +49,7 @@ enum ccs_error_e { ...@@ -49,6 +49,7 @@ enum ccs_error_e {
CCS_INVALID_TYPE, CCS_INVALID_TYPE,
CCS_INVALID_SCALE, CCS_INVALID_SCALE,
CCS_INVALID_DISTRIBUTION, CCS_INVALID_DISTRIBUTION,
CCS_INVALID_EXPRESSION,
CCS_INVALID_HYPERPARAMETER, CCS_INVALID_HYPERPARAMETER,
CCS_INVALID_CONFIGURATION, CCS_INVALID_CONFIGURATION,
CCS_INVALID_NAME, CCS_INVALID_NAME,
......
...@@ -47,8 +47,7 @@ ccs_object_get_type(ccs_object_t object, ...@@ -47,8 +47,7 @@ ccs_object_get_type(ccs_object_t object,
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object; _ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
if (!obj) if (!obj)
return -CCS_INVALID_OBJECT; return -CCS_INVALID_OBJECT;
if (!type_ret) CCS_CHECK_PTR(type_ret);
return -CCS_INVALID_VALUE;
*type_ret = obj->type; *type_ret = obj->type;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -59,8 +58,7 @@ ccs_object_get_refcount(ccs_object_t object, ...@@ -59,8 +58,7 @@ ccs_object_get_refcount(ccs_object_t object,
_ccs_object_internal_t *obj = (_ccs_object_internal_t *)object; _ccs_object_internal_t *obj = (_ccs_object_internal_t *)object;
if (!obj) if (!obj)
return -CCS_INVALID_OBJECT; return -CCS_INVALID_OBJECT;
if (!refcount_ret) CCS_CHECK_PTR(refcount_ret);
return -CCS_INVALID_VALUE;
*refcount_ret = obj->refcount; *refcount_ret = obj->refcount;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -22,6 +22,23 @@ _ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) { ...@@ -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 { struct _ccs_object_ops_s {
ccs_result_t (*del)(ccs_object_t object); ccs_result_t (*del)(ccs_object_t object);
}; };
...@@ -36,6 +53,12 @@ struct _ccs_object_internal_s { ...@@ -36,6 +53,12 @@ struct _ccs_object_internal_s {
typedef struct _ccs_object_internal_s _ccs_object_internal_t; 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 static inline __attribute__((always_inline)) void
_ccs_object_init(_ccs_object_internal_t *o, _ccs_object_init(_ccs_object_internal_t *o,
ccs_object_type_t t, ccs_object_type_t t,
......
...@@ -24,12 +24,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space, ...@@ -24,12 +24,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space,
ccs_datum_t *values, ccs_datum_t *values,
void *user_data, void *user_data,
ccs_configuration_t *configuration_ret) { ccs_configuration_t *configuration_ret) {
if (!configuration_ret) CCS_CHECK_PTR(configuration_ret);
return -CCS_INVALID_VALUE; CCS_CHECK_ARY(num_values, values);
if (num_values && !values)
return -CCS_INVALID_VALUE;
if (!num_values && values)
return -CCS_INVALID_VALUE;
ccs_result_t err; ccs_result_t err;
size_t num; size_t num;
err = ccs_configuration_space_get_num_hyperparameters(configuration_space, &num); err = ccs_configuration_space_get_num_hyperparameters(configuration_space, &num);
...@@ -63,10 +59,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space, ...@@ -63,10 +59,8 @@ ccs_create_configuration(ccs_configuration_space_t configuration_space,
ccs_result_t ccs_result_t
ccs_configuration_get_configuration_space(ccs_configuration_t configuration, ccs_configuration_get_configuration_space(ccs_configuration_t configuration,
ccs_configuration_space_t *configuration_space_ret) { ccs_configuration_space_t *configuration_space_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(configuration_space_ret);
if (!configuration_space_ret)
return -CCS_INVALID_VALUE;
*configuration_space_ret = configuration->data->configuration_space; *configuration_space_ret = configuration->data->configuration_space;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -74,10 +68,8 @@ ccs_configuration_get_configuration_space(ccs_configuration_t configurati ...@@ -74,10 +68,8 @@ ccs_configuration_get_configuration_space(ccs_configuration_t configurati
ccs_result_t ccs_result_t
ccs_configuration_get_user_data(ccs_configuration_t configuration, ccs_configuration_get_user_data(ccs_configuration_t configuration,
void **user_data_ret) { void **user_data_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(user_data_ret);
if (!user_data_ret)
return -CCS_INVALID_VALUE;
*user_data_ret = configuration->data->user_data; *user_data_ret = configuration->data->user_data;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -86,10 +78,8 @@ ccs_result_t ...@@ -86,10 +78,8 @@ ccs_result_t
ccs_configuration_get_value(ccs_configuration_t configuration, ccs_configuration_get_value(ccs_configuration_t configuration,
size_t index, size_t index,
ccs_datum_t *value_ret) { ccs_datum_t *value_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(value_ret);
if (!value_ret)
return -CCS_INVALID_VALUE;
if (index >= configuration->data->num_values) if (index >= configuration->data->num_values)
return -CCS_OUT_OF_BOUNDS; return -CCS_OUT_OF_BOUNDS;
*value_ret = configuration->data->values[index]; *value_ret = configuration->data->values[index];
...@@ -100,8 +90,7 @@ ccs_result_t ...@@ -100,8 +90,7 @@ ccs_result_t
ccs_configuration_set_value(ccs_configuration_t configuration, ccs_configuration_set_value(ccs_configuration_t configuration,
size_t index, size_t index,
ccs_datum_t value) { ccs_datum_t value) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT;
if (index >= configuration->data->num_values) if (index >= configuration->data->num_values)
return -CCS_OUT_OF_BOUNDS; return -CCS_OUT_OF_BOUNDS;
configuration->data->values[index] = value; configuration->data->values[index] = value;
...@@ -113,14 +102,10 @@ ccs_configuration_get_values(ccs_configuration_t configuration, ...@@ -113,14 +102,10 @@ ccs_configuration_get_values(ccs_configuration_t configuration,
size_t num_values, size_t num_values,
ccs_datum_t *values, ccs_datum_t *values,
size_t *num_values_ret) { size_t *num_values_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_ARY(num_values, values);
if (!num_values_ret && !values) if (!num_values_ret && !values)
return -CCS_INVALID_VALUE; 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; size_t num = configuration->data->num_values;
if (values) { if (values) {
if (num_values < num) if (num_values < num)
...@@ -140,10 +125,8 @@ ccs_result_t ...@@ -140,10 +125,8 @@ ccs_result_t
ccs_configuration_get_value_by_name(ccs_configuration_t configuration, ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
const char *name, const char *name,
ccs_datum_t *value_ret) { ccs_datum_t *value_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(name);
if (!name)
return -CCS_INVALID_VALUE;
size_t index; size_t index;
ccs_result_t err; ccs_result_t err;
err = ccs_configuration_space_get_hyperparameter_index_by_name( err = ccs_configuration_space_get_hyperparameter_index_by_name(
...@@ -156,8 +139,7 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration, ...@@ -156,8 +139,7 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
ccs_result_t ccs_result_t
ccs_configuration_check(ccs_configuration_t configuration) { ccs_configuration_check(ccs_configuration_t configuration) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT;
return ccs_configuration_space_check_configuration( return ccs_configuration_space_check_configuration(
configuration->data->configuration_space, configuration); configuration->data->configuration_space, configuration);
} }
...@@ -165,10 +147,8 @@ ccs_configuration_check(ccs_configuration_t configuration) { ...@@ -165,10 +147,8 @@ ccs_configuration_check(ccs_configuration_t configuration) {
ccs_result_t ccs_result_t
ccs_configuration_hash(ccs_configuration_t configuration, ccs_configuration_hash(ccs_configuration_t configuration,
ccs_hash_t *hash_ret) { ccs_hash_t *hash_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(hash_ret);
if (!hash_ret)
return -CCS_INVALID_VALUE;
_ccs_configuration_data_t *data = configuration->data; _ccs_configuration_data_t *data = configuration->data;
ccs_hash_t h, ht; ccs_hash_t h, ht;
HASH_JEN(&(data->configuration_space), sizeof(data->configuration_space), h); HASH_JEN(&(data->configuration_space), sizeof(data->configuration_space), h);
...@@ -186,12 +166,9 @@ ccs_result_t ...@@ -186,12 +166,9 @@ ccs_result_t
ccs_configuration_cmp(ccs_configuration_t configuration, ccs_configuration_cmp(ccs_configuration_t configuration,
ccs_configuration_t other_configuration, ccs_configuration_t other_configuration,
int *cmp_ret) { int *cmp_ret) {
if (!configuration || !configuration->data) CCS_CHECK_OBJ(configuration, CCS_CONFIGURATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_OBJ(other_configuration, CCS_CONFIGURATION);
if (!other_configuration || !other_configuration->data) CCS_CHECK_PTR(cmp_ret);
return -CCS_INVALID_OBJECT;
if (!cmp_ret)
return -CCS_INVALID_VALUE;
if (configuration == other_configuration) { if (configuration == other_configuration) {
*cmp_ret = 0; *cmp_ret = 0;
return CCS_SUCCESS; return CCS_SUCCESS;
......
This diff is collapsed.
...@@ -10,10 +10,8 @@ ccs_distribution_get_ops(ccs_distribution_t distribution) { ...@@ -10,10 +10,8 @@ ccs_distribution_get_ops(ccs_distribution_t distribution) {
ccs_result_t ccs_result_t
ccs_distribution_get_type(ccs_distribution_t distribution, ccs_distribution_get_type(ccs_distribution_t distribution,
ccs_distribution_type_t *type_ret) { ccs_distribution_type_t *type_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(type_ret);
if (!type_ret)
return -CCS_INVALID_VALUE;
*type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->type; *type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->type;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -21,10 +19,8 @@ ccs_distribution_get_type(ccs_distribution_t distribution, ...@@ -21,10 +19,8 @@ ccs_distribution_get_type(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_get_data_type(ccs_distribution_t distribution, ccs_distribution_get_data_type(ccs_distribution_t distribution,
ccs_numeric_type_t *data_type_ret) { ccs_numeric_type_t *data_type_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(data_type_ret);
if (!data_type_ret)
return -CCS_INVALID_VALUE;
*data_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->data_type; *data_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->data_type;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -32,10 +28,8 @@ ccs_distribution_get_data_type(ccs_distribution_t distribution, ...@@ -32,10 +28,8 @@ ccs_distribution_get_data_type(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_get_dimension(ccs_distribution_t distribution, ccs_distribution_get_dimension(ccs_distribution_t distribution,
size_t *dimension_ret) { size_t *dimension_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(dimension_ret);
if (!dimension_ret)
return -CCS_INVALID_VALUE;
*dimension_ret = 1; *dimension_ret = 1;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -44,10 +38,8 @@ ccs_distribution_get_dimension(ccs_distribution_t distribution, ...@@ -44,10 +38,8 @@ ccs_distribution_get_dimension(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_get_scale_type(ccs_distribution_t distribution, ccs_distribution_get_scale_type(ccs_distribution_t distribution,
ccs_scale_type_t *scale_type_ret) { ccs_scale_type_t *scale_type_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(scale_type_ret);
if (!scale_type_ret)
return -CCS_INVALID_VALUE;
*scale_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->scale_type; *scale_type_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->scale_type;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -55,10 +47,8 @@ ccs_distribution_get_scale_type(ccs_distribution_t distribution, ...@@ -55,10 +47,8 @@ ccs_distribution_get_scale_type(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_get_quantization(ccs_distribution_t distribution, ccs_distribution_get_quantization(ccs_distribution_t distribution,
ccs_numeric_t *quantization_ret) { ccs_numeric_t *quantization_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(quantization_ret);
if (!quantization_ret)
return -CCS_INVALID_VALUE;
*quantization_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->quantization; *quantization_ret = ((_ccs_distribution_common_data_t *)(distribution->data))->quantization;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -66,10 +56,8 @@ ccs_distribution_get_quantization(ccs_distribution_t distribution, ...@@ -66,10 +56,8 @@ ccs_distribution_get_quantization(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_get_bounds(ccs_distribution_t distribution, ccs_distribution_get_bounds(ccs_distribution_t distribution,
ccs_interval_t *interval_ret) { ccs_interval_t *interval_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(interval_ret);
if (!interval_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution); _ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution);
return ops->get_bounds(distribution->data, interval_ret); return ops->get_bounds(distribution->data, interval_ret);
} }
...@@ -78,10 +66,11 @@ ccs_result_t ...@@ -78,10 +66,11 @@ ccs_result_t
ccs_distribution_check_oversampling(ccs_distribution_t distribution, ccs_distribution_check_oversampling(ccs_distribution_t distribution,
ccs_interval_t *interval, ccs_interval_t *interval,
ccs_bool_t *oversampling_ret) { 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_result_t err;
ccs_interval_t d_interval; ccs_interval_t d_interval;
if (!interval || !oversampling_ret)
return -CCS_INVALID_VALUE;
err = ccs_distribution_get_bounds(distribution, &d_interval); err = ccs_distribution_get_bounds(distribution, &d_interval);
if (err) if (err)
...@@ -104,13 +93,11 @@ ccs_distribution_check_oversampling(ccs_distribution_t distribution, ...@@ -104,13 +93,11 @@ ccs_distribution_check_oversampling(ccs_distribution_t distribution,
ccs_result_t ccs_result_t
ccs_distribution_sample(ccs_distribution_t distribution, ccs_distribution_sample(ccs_distribution_t distribution,
ccs_rng_t rng, ccs_rng_t rng,
ccs_numeric_t *value) { ccs_numeric_t *value_ret) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(value_ret);
if (!value)
return -CCS_INVALID_VALUE;
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution); _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 ccs_result_t
...@@ -118,10 +105,10 @@ ccs_distribution_samples(ccs_distribution_t distribution, ...@@ -118,10 +105,10 @@ ccs_distribution_samples(ccs_distribution_t distribution,
ccs_rng_t rng, ccs_rng_t rng,
size_t num_values, size_t num_values,
ccs_numeric_t *values) { ccs_numeric_t *values) {
if (!distribution || !distribution->data) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; if (!num_values)
if (!num_values || !values) return CCS_SUCCESS;
return -CCS_INVALID_VALUE; CCS_CHECK_ARY(num_values, values);
_ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution); _ccs_distribution_ops_t *ops = ccs_distribution_get_ops(distribution);
return ops->samples(distribution->data, rng, num_values, values); return ops->samples(distribution->data, rng, num_values, values);
} }
......
...@@ -214,8 +214,7 @@ ccs_create_normal_distribution(ccs_numeric_type_t data_type, ...@@ -214,8 +214,7 @@ ccs_create_normal_distribution(ccs_numeric_type_t data_type,
ccs_scale_type_t scale_type, ccs_scale_type_t scale_type,
ccs_numeric_t quantization, ccs_numeric_t quantization,
ccs_distribution_t *distribution_ret) { ccs_distribution_t *distribution_ret) {
if (!distribution_ret) CCS_CHECK_PTR(distribution_ret);
return -CCS_INVALID_VALUE;
if (data_type != CCS_NUM_FLOAT && data_type != CCS_NUM_INTEGER) if (data_type != CCS_NUM_FLOAT && data_type != CCS_NUM_INTEGER)
return -CCS_INVALID_TYPE; return -CCS_INVALID_TYPE;
if (scale_type != CCS_LINEAR && scale_type != CCS_LOGARITHMIC) if (scale_type != CCS_LINEAR && scale_type != CCS_LOGARITHMIC)
...@@ -253,9 +252,8 @@ extern ccs_result_t ...@@ -253,9 +252,8 @@ extern ccs_result_t
ccs_normal_distribution_get_parameters(ccs_distribution_t distribution, ccs_normal_distribution_get_parameters(ccs_distribution_t distribution,
ccs_float_t *mu, ccs_float_t *mu,
ccs_float_t *sigma) { ccs_float_t *sigma) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_NORMAL)
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_NORMAL)
return -CCS_INVALID_OBJECT; return -CCS_INVALID_OBJECT;
if (!mu && !sigma) if (!mu && !sigma)
return -CCS_INVALID_VALUE; return -CCS_INVALID_VALUE;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
struct _ccs_distribution_roulette_data_s { struct _ccs_distribution_roulette_data_s {
_ccs_distribution_common_data_t common_data; _ccs_distribution_common_data_t common_data;
ccs_int_t num_areas; size_t num_areas;
ccs_float_t *areas; ccs_float_t *areas;
}; };
typedef struct _ccs_distribution_roulette_data_s _ccs_distribution_roulette_data_t; 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, ...@@ -40,7 +40,7 @@ _ccs_distribution_roulette_get_bounds(_ccs_distribution_data_t *data,
interval_ret->type = CCS_NUM_INTEGER; interval_ret->type = CCS_NUM_INTEGER;
interval_ret->lower = CCSI(INT64_C(0)); 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->lower_included = CCS_TRUE;
interval_ret->upper_included = CCS_FALSE; interval_ret->upper_included = CCS_FALSE;
return CCS_SUCCESS; return CCS_SUCCESS;
...@@ -83,7 +83,9 @@ ccs_result_t ...@@ -83,7 +83,9 @@ ccs_result_t
ccs_create_roulette_distribution(size_t num_areas, ccs_create_roulette_distribution(size_t num_areas,
ccs_float_t *areas, ccs_float_t *areas,
ccs_distribution_t *distribution_ret) { 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; return -CCS_INVALID_VALUE;
ccs_float_t sum = 0.0; ccs_float_t sum = 0.0;
...@@ -130,12 +132,10 @@ ccs_create_roulette_distribution(size_t num_areas, ...@@ -130,12 +132,10 @@ ccs_create_roulette_distribution(size_t num_areas,
ccs_result_t ccs_result_t
ccs_roulette_distribution_get_num_areas(ccs_distribution_t distribution, ccs_roulette_distribution_get_num_areas(ccs_distribution_t distribution,
size_t *num_areas_ret) { 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; return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT;
if (!num_areas_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data; _ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data;
*num_areas_ret = data->num_areas; *num_areas_ret = data->num_areas;
return CCS_SUCCESS; return CCS_SUCCESS;
...@@ -146,20 +146,20 @@ ccs_roulette_distribution_get_areas(ccs_distribution_t distribution, ...@@ -146,20 +146,20 @@ ccs_roulette_distribution_get_areas(ccs_distribution_t distribution,
size_t num_areas, size_t num_areas,
ccs_float_t *areas, ccs_float_t *areas,
size_t *num_areas_ret) { size_t *num_areas_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; CCS_CHECK_ARY(num_areas, areas);
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE) if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT; return -CCS_INVALID_OBJECT;
if (!areas && !num_areas_ret) if (!areas && !num_areas_ret)
return -CCS_INVALID_VALUE; return -CCS_INVALID_VALUE;
if (num_areas && !areas)
return -CCS_INVALID_VALUE;
_ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data; _ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data;
if (areas) { if (areas) {
if ((ccs_int_t)num_areas != data->num_areas) if (num_areas < data->num_areas)
return -CCS_INVALID_VALUE; return -CCS_INVALID_VALUE;
for (size_t i = 0; i < num_areas; i++) for (size_t i = 0; i < data->num_areas; i++)
areas[i] = data->areas[i+1] - data->areas[i]; areas[i] = data->areas[i+1] - data->areas[i];
for (size_t i = data->num_areas; i < num_areas; i++)
areas[i] = 0.0;
} }
if (num_areas_ret) if (num_areas_ret)
*num_areas_ret = data->num_areas; *num_areas_ret = data->num_areas;
......
...@@ -124,8 +124,7 @@ ccs_create_uniform_distribution(ccs_numeric_type_t data_type, ...@@ -124,8 +124,7 @@ ccs_create_uniform_distribution(ccs_numeric_type_t data_type,
ccs_scale_type_t scale_type, ccs_scale_type_t scale_type,
ccs_numeric_t quantization, ccs_numeric_t quantization,
ccs_distribution_t *distribution_ret) { ccs_distribution_t *distribution_ret) {
if (!distribution_ret) CCS_CHECK_PTR(distribution_ret);
return -CCS_INVALID_VALUE;
if (data_type != CCS_NUM_FLOAT && data_type != CCS_NUM_INTEGER) if (data_type != CCS_NUM_FLOAT && data_type != CCS_NUM_INTEGER)
return -CCS_INVALID_TYPE; return -CCS_INVALID_TYPE;
if (scale_type != CCS_LINEAR && scale_type != CCS_LOGARITHMIC) if (scale_type != CCS_LINEAR && scale_type != CCS_LOGARITHMIC)
...@@ -190,9 +189,8 @@ ccs_result_t ...@@ -190,9 +189,8 @@ ccs_result_t
ccs_uniform_distribution_get_parameters(ccs_distribution_t distribution, ccs_uniform_distribution_get_parameters(ccs_distribution_t distribution,
ccs_numeric_t *lower_ret, ccs_numeric_t *lower_ret,
ccs_numeric_t *upper_ret) { ccs_numeric_t *upper_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION) CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
return -CCS_INVALID_OBJECT; if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_UNIFORM)
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_UNIFORM)
return -CCS_INVALID_OBJECT; return -CCS_INVALID_OBJECT;
if (!lower_ret && !upper_ret) if (!lower_ret && !upper_ret)
return -CCS_INVALID_VALUE; return -CCS_INVALID_VALUE;
......
...@@ -26,12 +26,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space, ...@@ -26,12 +26,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space,
ccs_datum_t *values, ccs_datum_t *values,
void *user_data, void *user_data,
ccs_evaluation_t *evaluation_ret) { ccs_evaluation_t *evaluation_ret) {
if (!evaluation_ret) CCS_CHECK_PTR(evaluation_ret);
return -CCS_INVALID_VALUE; CCS_CHECK_ARY(num_values, values);
if (num_values && !values)
return -CCS_INVALID_VALUE;
if (!num_values && values)
return -CCS_INVALID_VALUE;
ccs_result_t err; ccs_result_t err;
size_t num; size_t num;
err = ccs_objective_space_get_num_hyperparameters(objective_space, &num); err = ccs_objective_space_get_num_hyperparameters(objective_space, &num);
...@@ -72,10 +68,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space, ...@@ -72,10 +68,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space,
ccs_result_t ccs_result_t
ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation, ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation,
ccs_objective_space_t *objective_space_ret) { ccs_objective_space_t *objective_space_ret) {
if (!evaluation || !evaluation->data) CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(objective_space_ret);
if (!objective_space_ret)
return -CCS_INVALID_VALUE;
*objective_space_ret = evaluation->data->objective_space; *objective_space_ret = evaluation->data->objective_space;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -83,10 +77,8 @@ ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation, ...@@ -83,10 +77,8 @@ ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation,
ccs_result_t ccs_result_t
ccs_evaluation_get_configuration(ccs_evaluation_t evaluation, ccs_evaluation_get_configuration(ccs_evaluation_t evaluation,
ccs_configuration_t *configuration_ret) { ccs_configuration_t *configuration_ret) {
if (!evaluation || !evaluation->data) CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(configuration_ret);
if (!configuration_ret)
return -CCS_INVALID_VALUE;
*configuration_ret = evaluation->data->configuration; *configuration_ret = evaluation->data->configuration;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -94,10 +86,8 @@ ccs_evaluation_get_configuration(ccs_evaluation_t evaluation, ...@@ -94,10 +86,8 @@ ccs_evaluation_get_configuration(ccs_evaluation_t evaluation,
ccs_result_t ccs_result_t
ccs_evaluation_get_user_data(ccs_evaluation_t evaluation, ccs_evaluation_get_user_data(ccs_evaluation_t evaluation,
void **user_data_ret) { void **user_data_ret) {
if (!evaluation || !evaluation->data) CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(user_data_ret);
if (!user_data_ret)
return -CCS_INVALID_VALUE;
*user_data_ret = evaluation->data->user_data; *user_data_ret = evaluation->data->user_data;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -105,10 +95,8 @@ ccs_evaluation_get_user_data(ccs_evaluation_t evaluation, ...@@ -105,10 +95,8 @@ ccs_evaluation_get_user_data(ccs_evaluation_t evaluation,
ccs_result_t ccs_result_t
ccs_evaluation_get_error(ccs_evaluation_t evaluation, ccs_evaluation_get_error(ccs_evaluation_t evaluation,
ccs_result_t *error_ret) { ccs_result_t *error_ret) {
if (!evaluation || !evaluation->data) CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
return -CCS_INVALID_OBJECT; CCS_CHECK_PTR(error_ret);
if (!error_ret)
return -CCS_INVALID_VALUE;
*error_ret = evaluation->data->error; *error_ret = evaluation->data->error;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -116,8 +104,7 @@ ccs_evaluation_get_error(ccs_evaluation_t evaluation, ...@@ -116,8 +104,7 @@ ccs_evaluation_get_error(ccs_evaluation_t evaluation,
ccs_result_t ccs_result_t
ccs_evaluation_set_error(ccs_evaluation_t evaluation, ccs_evaluation_set_error(ccs_evaluation_t evaluation,
ccs_result_t error) { ccs_result_t error) {
if (!evaluation || !evaluation->data) CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
return -CCS_INVALID_OBJECT;
evaluation->data->error = error; evaluation->data->error = error;
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -126,10 +113,8 @@ ccs_result_t ...@@ -126,10 +113,8 @@ ccs_result_t
ccs_evaluation_get_value(ccs_evaluation_t evaluation, ccs_evaluation_get_value(ccs_evaluation_t evaluation,
size_t index,