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;
......
This diff is collapsed.
......@@ -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;
if (!num_areas_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data;
*num_areas_ret = data->num_areas;
return CCS_SUCCESS;
......@@ -146,20 +146,20 @@ ccs_roulette_distribution_get_areas(ccs_distribution_t distribution,
size_t num_areas,
ccs_float_t *areas,
size_t *num_areas_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION)
return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
CCS_CHECK_ARY(num_areas, areas);
if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT;
if (!areas && !num_areas_ret)
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;
if (areas) {
if ((ccs_int_t)num_areas != data->num_areas)
if (num_areas < data->num_areas)
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];
for (size_t i = data->num_areas; i < num_areas; i++)
areas[i] = 0.0;
}
if (num_areas_ret)
*num_areas_ret = data->num_areas;
......
......@@ -124,8 +124,7 @@ ccs_create_uniform_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)
......@@ -190,9 +189,8 @@ ccs_result_t
ccs_uniform_distribution_get_parameters(ccs_distribution_t distribution,
ccs_numeric_t *lower_ret,
ccs_numeric_t *upper_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION)
return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_UNIFORM)
CCS_CHECK_OBJ(distribution, CCS_DISTRIBUTION);
if (((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_UNIFORM)
return -CCS_INVALID_OBJECT;
if (!lower_ret && !upper_ret)
return -CCS_INVALID_VALUE;
......
......@@ -26,12 +26,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space,
ccs_datum_t *values,
void *user_data,
ccs_evaluation_t *evaluation_ret) {
if (!evaluation_ret)
return -CCS_INVALID_VALUE;
if (num_values && !values)
return -CCS_INVALID_VALUE;
if (!num_values && values)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(evaluation_ret);
CCS_CHECK_ARY(num_values, values);
ccs_result_t err;
size_t num;
err = ccs_objective_space_get_num_hyperparameters(objective_space, &num);
......@@ -72,10 +68,8 @@ ccs_create_evaluation(ccs_objective_space_t objective_space,
ccs_result_t
ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation,
ccs_objective_space_t *objective_space_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!objective_space_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(objective_space_ret);
*objective_space_ret = evaluation->data->objective_space;
return CCS_SUCCESS;
}
......@@ -83,10 +77,8 @@ ccs_evaluation_get_objective_space(ccs_evaluation_t evaluation,
ccs_result_t
ccs_evaluation_get_configuration(ccs_evaluation_t evaluation,
ccs_configuration_t *configuration_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!configuration_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(configuration_ret);
*configuration_ret = evaluation->data->configuration;
return CCS_SUCCESS;
}
......@@ -94,10 +86,8 @@ ccs_evaluation_get_configuration(ccs_evaluation_t evaluation,
ccs_result_t
ccs_evaluation_get_user_data(ccs_evaluation_t evaluation,
void **user_data_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!user_data_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(user_data_ret);
*user_data_ret = evaluation->data->user_data;
return CCS_SUCCESS;
}
......@@ -105,10 +95,8 @@ ccs_evaluation_get_user_data(ccs_evaluation_t evaluation,
ccs_result_t
ccs_evaluation_get_error(ccs_evaluation_t evaluation,
ccs_result_t *error_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!error_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(error_ret);
*error_ret = evaluation->data->error;
return CCS_SUCCESS;
}
......@@ -116,8 +104,7 @@ ccs_evaluation_get_error(ccs_evaluation_t evaluation,
ccs_result_t
ccs_evaluation_set_error(ccs_evaluation_t evaluation,
ccs_result_t error) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
evaluation->data->error = error;
return CCS_SUCCESS;
}
......@@ -126,10 +113,8 @@ ccs_result_t
ccs_evaluation_get_value(ccs_evaluation_t evaluation,
size_t index,
ccs_datum_t *value_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!value_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(value_ret);
if (index >= evaluation->data->num_values)
return -CCS_OUT_OF_BOUNDS;
*value_ret = evaluation->data->values[index];
......@@ -140,8 +125,7 @@ ccs_result_t
ccs_evaluation_set_value(ccs_evaluation_t evaluation,
size_t index,
ccs_datum_t value) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
if (index >= evaluation->data->num_values)
return -CCS_OUT_OF_BOUNDS;
evaluation->data->values[index] = value;
......@@ -153,14 +137,10 @@ ccs_evaluation_get_values(ccs_evaluation_t evaluation,
size_t num_values,
ccs_datum_t *values,
size_t *num_values_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
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 = evaluation->data->num_values;
if (values) {
if (num_values < num)
......@@ -180,10 +160,8 @@ ccs_result_t
ccs_evaluation_get_value_by_name(ccs_evaluation_t evaluation,
const char *name,
ccs_datum_t *value_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (!name)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(name);
size_t index;
ccs_result_t err;
err = ccs_objective_space_get_hyperparameter_index_by_name(
......@@ -198,8 +176,8 @@ ccs_result_t
ccs_evaluation_get_objective_value(ccs_evaluation_t evaluation,
size_t index,
ccs_datum_t *value_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(value_ret);
ccs_expression_t expression;
ccs_objective_type_t type;
ccs_result_t err;
......@@ -217,10 +195,8 @@ ccs_evaluation_get_objective_values(ccs_evaluation_t evaluation,
size_t num_values,
ccs_datum_t *values,
size_t *num_values_ret) {
if (!evaluation || !evaluation->data)
return -CCS_INVALID_OBJECT;
if (num_values && !values)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_ARY(num_values, values);
if (!values && !num_values_ret)
return -CCS_INVALID_VALUE;
size_t count;
......@@ -268,14 +244,13 @@ ccs_result_t
ccs_evaluation_cmp(ccs_evaluation_t evaluation,
ccs_evaluation_t other_evaluation,
ccs_comparison_t *result_ret) {
if (!evaluation || !evaluation->data || evaluation->data->error)
return -CCS_INVALID_OBJECT;
if (!other_evaluation || !other_evaluation->data || other_evaluation->data->error)
CCS_CHECK_OBJ(evaluation, CCS_EVALUATION);
CCS_CHECK_OBJ(other_evaluation, CCS_EVALUATION);
CCS_CHECK_PTR(result_ret);
if(evaluation->data->error || other_evaluation->data->error)
return -CCS_INVALID_OBJECT;
if (evaluation->data->objective_space != other_evaluation->data->objective_space)
return -CCS_INVALID_OBJECT;
if (!result_ret)
return -CCS_INVALID_VALUE;
size_t count;
ccs_result_t err;
err = ccs_objective_space_get_objectives(evaluation->data->objective_space,
......
<
......@@ -979,8 +979,7 @@ ccs_create_literal(ccs_datum_t value,
ccs_expression_t *expression_ret) {
if (value.type < CCS_NONE || value.type > CCS_STRING)
return -CCS_INVALID_VALUE;
if (!expression_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_PTR(expression_ret);
size_t size_str = 0;
if (value.type == CCS_STRING && value.value.s) {
size_str = strlen(value.value.s) + 1;
......@@ -1018,10 +1017,8 @@ ccs_create_literal(ccs_datum_t value,
ccs_result_t
ccs_create_variable(ccs_hyperparameter_t hyperparameter,
ccs_expression_t *expression_ret) {
if (!hyperparameter)
return -CCS_INVALID_OBJECT;
if (!expression_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(hyperparameter, CCS_HYPERPARAMETER);
CCS_CHECK_PTR(expression_ret);
ccs_result_t err;
uintptr_t mem = (uintptr_t)calloc(1,
sizeof(struct _ccs_expression_s) +
......@@ -1053,12 +1050,10 @@ ccs_create_expression(ccs_expression_type_t type,
size_t num_nodes,
ccs_datum_t *nodes,
ccs_expression_t *expression_ret) {
CCS_CHECK_ARY(num_nodes, nodes);
CCS_CHECK_PTR(expression_ret);
if (type < CCS_OR || type > CCS_LIST)
return -CCS_INVALID_VALUE;
if (num_nodes && !nodes)
return -CCS_INVALID_VALUE;
if (!expression_ret)
return -CCS_INVALID_VALUE;
int arity = ccs_expression_arity[type];
if (arity >= 0 && num_nodes != (size_t)arity)
return -CCS_INVALID_VALUE;
......@@ -1149,22 +1144,18 @@ ccs_result_t
ccs_expression_eval(ccs_expression_t expression,
ccs_context_t context,
ccs_datum_t *values,
ccs_datum_t *result) {
if (!expression || !expression->data)
return -CCS_INVALID_OBJECT;
if (!result)
return -CCS_INVALID_VALUE;
ccs_datum_t *result_ret) {
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
CCS_CHECK_PTR(result_ret);
_ccs_expression_ops_t *ops = ccs_expression_get_ops(expression);
return ops->eval(expression->data, context, values, result);
return ops->eval(expression->data, context, values, result_ret);
}
ccs_result_t
ccs_expression_get_num_nodes(ccs_expression_t expression,
size_t *num_nodes_ret) {
if (!expression || !expression->data)
return -CCS_INVALID_OBJECT;
if (!num_nodes_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
CCS_CHECK_PTR(num_nodes_ret);
*num_nodes_ret = expression->data->num_nodes;
return CCS_SUCCESS;
}
......@@ -1174,10 +1165,8 @@ ccs_expression_get_nodes(ccs_expression_t expression,
size_t num_nodes,
ccs_expression_t *nodes,
size_t *num_nodes_ret) {
if (!expression || !expression->data)
return -CCS_INVALID_OBJECT;
if (num_nodes && !nodes)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
CCS_CHECK_ARY(num_nodes, nodes);
if (!num_nodes_ret && !nodes)
return -CCS_INVALID_VALUE;
size_t count = expression->data->num_nodes;
......@@ -1201,10 +1190,10 @@ ccs_expression_list_eval_node(ccs_expression_t expression,
ccs_datum_t *values,
size_t index,
ccs_datum_t *result) {
if (!expression || !expression->data)
return -CCS_INVALID_OBJECT;
if (!result)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
CCS_CHECK_PTR(result);
if (expression->data->type != CCS_LIST)
return -CCS_INVALID_EXPRESSION;
ccs_result_t err;
ccs_datum_t node;
if (index >= expression->data->num_nodes)
......@@ -1219,10 +1208,8 @@ ccs_expression_list_eval_node(ccs_expression_t expression,
ccs_result_t
ccs_expression_get_type(ccs_expression_t expression,
ccs_expression_type_t *type_ret) {
if (!expression || !expression->data)
return -CCS_INVALID_OBJECT;
if (!type_ret)
return -CCS_INVALID_VALUE;
CCS_CHECK_OBJ(expression, CCS_EXPRESSION);
CCS_CHECK_PTR(type_ret);
*type_ret = expression->data->type;