Commit a20553b2 authored by Brice Videau's avatar Brice Videau
Browse files

Added a check on configurations.

parent 80f82b8c
......@@ -38,6 +38,7 @@ enum ccs_error_e {
CCS_INVALID_SCALE,
CCS_INVALID_DISTRIBUTION,
CCS_INVALID_HYPERPARAMETER,
CCS_INVALID_CONFIGURATION,
CCS_INVALID_NAME,
CCS_TYPE_NOT_COMPARABLE,
CCS_INVALID_BOUNDS,
......
......@@ -45,6 +45,9 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
const char *name,
ccs_datum_t *value_ret);
extern ccs_error_t
ccs_configuration_check(ccs_configuration_t configuration);
#ifdef __cplusplus
}
#endif
......
......@@ -153,3 +153,10 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
}
ccs_error_t
ccs_configuration_check(ccs_configuration_t configuration) {
if (!configuration || !configuration->data)
return -CCS_INVALID_OBJECT;
return ccs_configuration_space_check_configuration(
configuration->data->configuration_space, configuration);
}
#include "cconfigspace_internal.h"
#include "configuration_space_internal.h"
#include "configuration_internal.h"
static inline _ccs_configuration_space_ops_t *
ccs_configuration_space_get_ops(ccs_configuration_space_t configuration_space) {
......@@ -369,4 +370,32 @@ error:
return err;
}
ccs_error_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;
if (configuration->data->configuration_space != configuration_space)
return -CCS_INVALID_CONFIGURATION;
size_t index = 0;
UT_array *array = configuration_space->data->hyperparameters;
if (configuration->data->num_values != utarray_len(array))
return -CCS_INVALID_CONFIGURATION;
_ccs_hyperparameter_wrapper_t *wrapper = NULL;
ccs_datum_t *values = configuration->data->values;
while ( (wrapper = (_ccs_hyperparameter_wrapper_t *)utarray_next(array, wrapper)) ) {
ccs_bool_t res;
ccs_error_t err;
err = ccs_hyperparameter_check_value(wrapper->hyperparameter,
values[index++], &res);
if (unlikely(err))
return err;
if (res == CCS_FALSE)
return -CCS_INVALID_CONFIGURATION;
}
return CCS_SUCCESS;
}
......@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t type;
ccs_datum_t default_value;
ccs_error_t err;
ccs_bool_t check;
const char *name;
void * user_data;
ccs_distribution_t distribution;
......@@ -60,6 +61,18 @@ void test_create() {
assert( interval.upper.i == 4 );
assert( interval.upper_included == CCS_FALSE );
for(size_t i = 0; i < num_possible_values; i++) {
err = ccs_hyperparameter_check_value(hyperparameter, possible_values[i],
&check);
assert( err == CCS_SUCCESS );
assert( check == CCS_TRUE );
}
default_value.type = CCS_FLOAT;
err = ccs_hyperparameter_check_value(hyperparameter, default_value, &check);
assert( err == CCS_SUCCESS );
assert( check == CCS_FALSE );
err = ccs_release_object(distribution);
assert( err == CCS_SUCCESS );
err = ccs_release_object(hyperparameter);
......
......@@ -94,6 +94,9 @@ void check_configuration(ccs_configuration_space_t configuration_space,
err = ccs_configuration_space_get_default_configuration(
configuration_space, &configuration);
assert( err == CCS_SUCCESS );
err = ccs_configuration_check(configuration);
assert( err == CCS_SUCCESS );
for (size_t i = 0; i < sz; i++) {
ccs_datum_t datum;
ccs_datum_t hdatum;
......
......@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t type;
ccs_datum_t default_value;
ccs_error_t err;
ccs_bool_t check;
const char *name;
void * user_data;
ccs_distribution_t distribution;
......@@ -54,6 +55,15 @@ void test_create() {
assert( interval.upper.f == 5.0 );
assert( interval.upper_included == CCS_FALSE );
err = ccs_hyperparameter_check_value(hyperparameter, default_value, &check);
assert( err == CCS_SUCCESS );
assert( check == CCS_TRUE );
default_value.value.f = 6.0;
err = ccs_hyperparameter_check_value(hyperparameter, default_value, &check);
assert( err == CCS_SUCCESS );
assert( check == CCS_FALSE );
err = ccs_release_object(distribution);
assert( err == CCS_SUCCESS );
err = ccs_release_object(hyperparameter);
......
......@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t type;
ccs_datum_t default_value;
ccs_error_t err;
ccs_bool_t check;
const char *name;
void * user_data;
ccs_distribution_t distribution;
......@@ -61,6 +62,18 @@ void test_create() {
assert( interval.upper.i == 4 );
assert( interval.upper_included == CCS_FALSE );
for(size_t i = 0; i < num_possible_values; i++) {
err = ccs_hyperparameter_check_value(hyperparameter, possible_values[i],
&check);
assert( err == CCS_SUCCESS );
assert( check == CCS_TRUE );
}
default_value.type = CCS_FLOAT;
err = ccs_hyperparameter_check_value(hyperparameter, default_value, &check);
assert( err == CCS_SUCCESS );
assert( check == CCS_FALSE );
err = ccs_release_object(distribution);
assert( err == CCS_SUCCESS );
err = ccs_release_object(hyperparameter);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment