diff --git a/connectors/kokkos/ccs-kokkos-connector.cpp b/connectors/kokkos/ccs-kokkos-connector.cpp index 75031128..f7159497 100644 --- a/connectors/kokkos/ccs-kokkos-connector.cpp +++ b/connectors/kokkos/ccs-kokkos-connector.cpp @@ -458,12 +458,7 @@ extract_value( static std::map< size_t, - std::tuple< - struct timespec, - ccs_features_tuner_t, - ccs_features_t, - ccs_configuration_t, - bool> > + std::tuple > contexts; static int regionCounter = 0; @@ -509,13 +504,23 @@ kokkosp_request_values( ccs_expression_t expression; ccs_objective_type_t otype; + cs_parameters = new ccs_parameter_t[numContextVariables]; + for (size_t i = 0; i < numContextVariables; i++) + cs_parameters[i] = parameters[contextValues[i].type_id]; + + CCS_CHECK(ccs_create_feature_space( + ("fs (region: " + std::to_string(regionCounter) + ")").c_str(), + numContextVariables, cs_parameters, &fs)); + delete[] cs_parameters; + cs_parameters = new ccs_parameter_t[numTuningVariables]; for (size_t i = 0; i < numTuningVariables; i++) cs_parameters[i] = parameters[tuningValues[i].type_id]; CCS_CHECK(ccs_create_configuration_space( ("cs (region: " + std::to_string(regionCounter) + ")").c_str(), - numTuningVariables, cs_parameters, NULL, 0, NULL, NULL, &cs)); + numTuningVariables, cs_parameters, NULL, 0, NULL, fs, NULL, + &cs)); delete[] cs_parameters; #if CCS_DEBUG @@ -525,15 +530,6 @@ kokkosp_request_values( } #endif - cs_parameters = new ccs_parameter_t[numContextVariables]; - for (size_t i = 0; i < numContextVariables; i++) - cs_parameters[i] = parameters[contextValues[i].type_id]; - - CCS_CHECK(ccs_create_feature_space( - ("fs (region: " + std::to_string(regionCounter) + ")").c_str(), - numContextVariables, cs_parameters, &fs)); - delete[] cs_parameters; - ccs_int_t lower = 0; ccs_int_t upper = CCS_INT_MAX; ccs_int_t step = 0; @@ -553,7 +549,7 @@ kokkosp_request_values( ("random tuner (region: " + std::to_string(regionCounter) + ")") .c_str(), - fs, os, &tuner)); + os, &tuner)); CCS_CHECK(ccs_release_object(cs)); CCS_CHECK(ccs_release_object(fs)); CCS_CHECK(ccs_release_object(os)); @@ -602,7 +598,7 @@ kokkosp_request_values( else CCS_CHECK(ccs_features_tuner_suggest( tuner, feat, (ccs_search_configuration_t *)&configuration)); - + CCS_CHECK(ccs_release_object(feat)); CCS_CHECK(ccs_features_tuner_get_search_space( tuner, (ccs_search_space_t *)&configuration_space)); { @@ -628,8 +624,7 @@ kokkosp_request_values( #endif clock_gettime(CLOCK_MONOTONIC, &start); - contexts[contextId] = - std::make_tuple(start, tuner, feat, configuration, converged); + contexts[contextId] = std::make_tuple(start, tuner, configuration, converged); } extern "C" void @@ -643,7 +638,6 @@ kokkosp_end_context(size_t contextId) { struct timespec start, stop; ccs_features_tuner_t tuner; - ccs_features_t feat; ccs_configuration_t configuration; ccs_objective_space_t objective_space; bool converged; @@ -666,15 +660,14 @@ kokkosp_end_context(size_t contextId) auto context = ctx->second; start = std::get<0>(context); tuner = std::get<1>(context); - feat = std::get<2>(context); - configuration = std::get<3>(context); - converged = std::get<4>(context); + configuration = std::get<2>(context); + converged = std::get<3>(context); contexts.erase(contextId); if (!converged) { // do not report if not fencing and already converged. - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; // elapsed time in nanosecond - ccs_datum_t elapsed = ccs_int( + ccs_datum_t elapsed = ccs_int( ((ccs_int_t)(stop.tv_sec) - (ccs_int_t)(start.tv_sec)) * 1000000000 + (ccs_int_t)(stop.tv_nsec) - (ccs_int_t)(start.tv_nsec)); @@ -683,15 +676,14 @@ kokkosp_end_context(size_t contextId) CCS_CHECK(ccs_features_tuner_get_objective_space( tuner, &objective_space)); - CCS_CHECK(ccs_create_features_evaluation( + CCS_CHECK(ccs_create_evaluation( objective_space, (ccs_search_configuration_t)configuration, - feat, CCS_RESULT_SUCCESS, 1, &elapsed, &evaluation)); + CCS_RESULT_SUCCESS, 1, &elapsed, &evaluation)); CCS_CHECK(ccs_features_tuner_tell(tuner, 1, &evaluation)); CCS_CHECK(ccs_release_object(evaluation)); } - CCS_CHECK(ccs_release_object(feat)); CCS_CHECK(ccs_release_object(configuration)); #if CCS_PROFILE diff --git a/include/Makefile.am b/include/Makefile.am index 1af2ea09..d7ee4d48 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -18,7 +18,6 @@ include_ccs_HEADERS = \ cconfigspace/features.h \ cconfigspace/objective_space.h \ cconfigspace/evaluation.h \ - cconfigspace/features_evaluation.h \ cconfigspace/tuner.h \ cconfigspace/features_tuner.h \ cconfigspace/map.h \ diff --git a/include/cconfigspace.h b/include/cconfigspace.h index 5c58b9e5..f7d3c79a 100644 --- a/include/cconfigspace.h +++ b/include/cconfigspace.h @@ -20,7 +20,6 @@ #include "cconfigspace/features.h" #include "cconfigspace/objective_space.h" #include "cconfigspace/evaluation.h" -#include "cconfigspace/features_evaluation.h" #include "cconfigspace/tuner.h" #include "cconfigspace/features_tuner.h" #include "cconfigspace/map.h" diff --git a/include/cconfigspace/base.h b/include/cconfigspace/base.h index 2c98b1c7..5aebff92 100644 --- a/include/cconfigspace/base.h +++ b/include/cconfigspace/base.h @@ -141,10 +141,6 @@ typedef struct _ccs_objective_space_s *ccs_objective_space_t; * An opaque type defining a CCS evaluation. */ typedef struct _ccs_evaluation_s *ccs_evaluation_t; -/** - * An opaque type defining a CCS features evaluation. - */ -typedef struct _ccs_features_evaluation_s *ccs_features_evaluation_t; /** * An opaque type defining a CCS tuner. */ @@ -287,8 +283,6 @@ enum ccs_object_type_e { CCS_OBJECT_TYPE_FEATURE_SPACE, /** A set of features */ CCS_OBJECT_TYPE_FEATURES, - /** An evaluation of a configuration given specific features */ - CCS_OBJECT_TYPE_FEATURES_EVALUATION, /** A features aware tuner */ CCS_OBJECT_TYPE_FEATURES_TUNER, /** A key value store */ diff --git a/include/cconfigspace/configuration.h b/include/cconfigspace/configuration.h index 87dc5d3e..8fa0e0c6 100644 --- a/include/cconfigspace/configuration.h +++ b/include/cconfigspace/configuration.h @@ -16,6 +16,9 @@ extern "C" { * Create a new instance of a configuration on a given configuration space. If * no values are provided the values will be initialized to #CCS_DATA_TYPE_NONE. * @param[in] configuration_space + * @param[in] features an optional features to use. If NULL and a feature space + * was provided at \p configuration_space creation, the + * deafult features of the feature space will be used. * @param[in] num_values the number of provided values to initialize the * configuration * @param[in] values an optional array of values to initialize the configuration @@ -23,7 +26,10 @@ extern "C" { * newly created configuration * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space + * valid CCS configuration space; or if \p features is not NULL and is not a + * valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p configuration_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL; or * if \p values is NULL and \p num_values is greater than 0; or if the number of * values provided is not equal to the number of parameters in the configuration @@ -36,6 +42,7 @@ extern "C" { extern ccs_result_t ccs_create_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, size_t num_values, ccs_datum_t *values, ccs_configuration_t *configuration_ret); @@ -57,6 +64,24 @@ ccs_configuration_get_configuration_space( ccs_configuration_t configuration, ccs_configuration_space_t *configuration_space_ret); +/** + * Get the associated features. + * @param[in] configuration + * @param[out] features_ret a pointer to the variable that will contain the + * returned features or NULL if none is associated + * to the configuration. + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid + * CCS configuration + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_configuration_get_feature( + ccs_configuration_t configuration, + ccs_features_t *features_ret); + /** * Check that the configuration is a valid configuration for the configuration * space. diff --git a/include/cconfigspace/configuration_space.h b/include/cconfigspace/configuration_space.h index 2bb15c89..008f6e7a 100644 --- a/include/cconfigspace/configuration_space.h +++ b/include/cconfigspace/configuration_space.h @@ -8,9 +8,10 @@ extern "C" { /** * @file configuration_space.h * A configuration space is a context (see context.h) defining a search - * space on a set of parameters. Configuration space also offer as - * constraints system to describe conditional parameter activation as - * well as forbidden parameter configurations. + * space on a set of parameters. Optionally configuration space can be + * attached a feature space (see feature_space.h). Configuration space + * also offer as constraints system to describe conditional parameter + * activation as well as forbidden parameter configurations. */ /** @@ -27,6 +28,7 @@ extern "C" { * @param[in] forbidden_clauses an array o \p num_forbidden_clauses expressions * to add as forbidden clauses to the * configuration space + * @param[in] feature_space an optional CCS feature space object * @param[in] rng an optional CCS rng object * @param[out] configuration_space_ret a pointer to the variable that will hold * the newly created configuration space @@ -36,15 +38,16 @@ extern "C" { * num_parameters is NULL; or if \p forbidden_clauses is NULL and \p * num_forbidden_clauses is greater than 0 * @return #CCS_RESULT_ERROR_INVALID_OBJECT if a parameter is not a valid CCS - * parameter; or if an expression is not a valid CCS expression; or if \p - * rng is not NULL and is not a valid CCS rng + * parameter; or if an expression is not a valid CCS expression; or if \p rng + * is not NULL and is not a valid CCS rng; or it \p feature_space is not NULL + * and is not a valid CCS feature space * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if a parameter's type is * CCS_PARAMETER_TYPE_STRING; or if a parameter appears more than once in \p * parameters; or if two or more parameters share the same name; or if a * paramater is already part of another context; or if an expression references * a parameter that is not in the configuration space - * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding one of the provided - * forbidden clause would render the default configuration invalid + * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding one of the + * provided forbidden clause would render the default configuration invalid * @return #CCS_RESULT_ERROR_INVALID_GRAPH if the addition of the conditions * would cause the dependency graph to become invalid (cyclic) * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to @@ -60,6 +63,7 @@ ccs_create_configuration_space( ccs_expression_t *conditions, size_t num_forbidden_clauses, ccs_expression_t *forbidden_clauses, + ccs_feature_space_t feature_space, ccs_rng_t rng, ccs_configuration_space_t *configuration_space_ret); @@ -79,6 +83,23 @@ ccs_configuration_space_get_rng( ccs_configuration_space_t configuration_space, ccs_rng_t *rng_ret); +/** + * Get the feature space of the configuration space. + * @param[in] configuration_space + * @param[out] feature_space_ret a pointer to the variable that will contain + * the feature space + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a + * valid CCS configuration space + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p feature_space_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_configuration_space_get_feature_space( + ccs_configuration_space_t configuration_space, + ccs_feature_space_t *feature_space_ret); + /** * Get the active condition of a parameter in a configuration space given * it's index. @@ -213,11 +234,18 @@ ccs_configuration_space_check_configuration( /** * Get the default configuration of a configuration space * @param[in] configuration_space + * @param[in] features an optional features to use. If NULL and a feature space + * was provided at \p configuration_space creation, the + * deafult features of the feature space will be used. + * @param[in] rng an optional rng to use * @param[out] configuration_ret a pointer to the variable that will contain the * returned default configuration * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space + * valid CCS configuration space; or if \p features is not NULL and is not a + * valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p configuration_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to * allocate the new configuration @@ -227,6 +255,7 @@ ccs_configuration_space_check_configuration( extern ccs_result_t ccs_configuration_space_get_default_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, ccs_configuration_t *configuration_ret); /** @@ -236,13 +265,19 @@ ccs_configuration_space_get_default_configuration( * will have the #ccs_inactive value. Returned configuration is valid. * @param[in] configuration_space * @param[in] distribution_space an optional distribution space to use + * @param[in] features an optional features to use. If NULL and a feature space + * was provided at \p configuration_space creation, the + * deafult features of the feature space will be used. * @param[in] rng an optional rng to use * @param[out] configuration_ret a pointer to the variable that will contain the * returned configuration * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a * valid CCS configuration space; or if \p distribution_space is not a valid - * CCS distribution space; or if \p rng is not a valid CCS rng + * CCS distribution space; or if \p rng is not NULL and is not a valid CCS rng; + * or if \p features is not NULL and is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p configuration_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL * @return #CCS_RESULT_ERROR_SAMPLING_UNSUCCESSFUL if no valid configuration * could be sampled @@ -255,6 +290,7 @@ extern ccs_result_t ccs_configuration_space_sample( ccs_configuration_space_t configuration_space, ccs_distribution_space_t distribution_space, + ccs_features_t features, ccs_rng_t rng, ccs_configuration_t *configuration_ret); @@ -266,6 +302,8 @@ ccs_configuration_space_sample( * valid. * @param[in] configuration_space * @param[in] distribution_space an optional distribution space to use + * @param[in] features an optional features to use. Required if a feature space + * was provided at \p configuration_space creation. * @param[in] rng an optional rng to use * @param[in] num_configurations the number of requested configurations * @param[out] configurations an array of \p num_configurations that will @@ -273,7 +311,10 @@ ccs_configuration_space_sample( * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a * valid CCS configuration space; or if \p distribution_space is not a valid - * CCS distribution space; or if \p rng is not a valid CCS rng + * CCS distribution space; or if \p rng is not NULL and is not a valid CCS rng; + * or if \p features is not NULL and is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p configuration_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configurations is NULL and \p * num_configurations is greater than 0 * @return #CCS_RESULT_ERROR_SAMPLING_UNSUCCESSFUL if no or not enough valid @@ -289,6 +330,7 @@ extern ccs_result_t ccs_configuration_space_samples( ccs_configuration_space_t configuration_space, ccs_distribution_space_t distribution_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_configuration_t *configurations); diff --git a/include/cconfigspace/evaluation.h b/include/cconfigspace/evaluation.h index 81d4c470..9b695507 100644 --- a/include/cconfigspace/evaluation.h +++ b/include/cconfigspace/evaluation.h @@ -90,6 +90,40 @@ ccs_evaluation_get_objective_space( ccs_evaluation_t evaluation, ccs_objective_space_t *objective_space_ret); +/** + * Get the configuration associated with an evaluation. + * @param[in] evaluation + * @param[out] configuration_ret a pointer to the variable that will contain + * the configuration + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_configuration( + ccs_evaluation_t evaluation, + ccs_search_configuration_t *configuration_ret); + +/** + * Get the features associated with an evaluation. + * @param[in] evaluation + * @param[out] features_ret a pointer to the variable that will contain the + * features + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_features( + ccs_evaluation_t evaluation, + ccs_features_t *features_ret); + /** * Get the result code associated with an evaluation. * @param[in] evaluation @@ -206,23 +240,6 @@ ccs_evaluation_compare( ccs_evaluation_t other_evaluation, ccs_comparison_t *result_ret); -/** - * Get the configuration associated with an evaluation. - * @param[in] evaluation - * @param[out] configuration_ret a pointer to the variable that will contain - * the configuration - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_configuration( - ccs_evaluation_t evaluation, - ccs_search_configuration_t *configuration_ret); - #ifdef __cplusplus } #endif diff --git a/include/cconfigspace/feature_space.h b/include/cconfigspace/feature_space.h index 4b375920..423aee3f 100644 --- a/include/cconfigspace/feature_space.h +++ b/include/cconfigspace/feature_space.h @@ -37,6 +37,11 @@ ccs_create_feature_space( ccs_parameter_t *parameters, ccs_feature_space_t *feature_space_ret); +extern ccs_result_t +ccs_feature_space_get_default_features( + ccs_feature_space_t feature_space, + ccs_features_t *features_ret); + /** * Check that a features is a valid in a feature space. * @param[in] feature_space diff --git a/include/cconfigspace/features_evaluation.h b/include/cconfigspace/features_evaluation.h deleted file mode 100644 index 11cfa5dc..00000000 --- a/include/cconfigspace/features_evaluation.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _CCS_FEATURES_EVALUATION_H -#define _CCS_FEATURES_EVALUATION_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file features_evaluation.h - * A features evaluation is an evaluation (see evaluation.h) - * on a given set of features (see features.h). - */ - -/** - * Create a new instance of a features evaluation on a given objective_space for - * a given configuration and features. - * @param[in] objective_space the objective space to associate with the - * evaluation - * @param[in] configuration the configuration to associate with the evaluation - * @param[in] features the features to associate with the evaluation - * @param[in] result the result code associated with the evaluation - * @param[in] num_values the number of provided values to initialize the - * evaluation - * @param[in] values an optional array of values to initialize the evaluation - * @param[out] features_evaluation_ret a pointer to the variable that will hold - * the newly created evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p configuration is not a valid CCS - * search configuration; or the features is not a valid CCS features - * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if \p configuration search - * space is not the same as \p objective_space search space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features evaluation_ret is - * NULL; or if \p values is NULL and \p num_values is greater than 0; or if the - * number of values provided is not equal to the number of parameters in the - * objective space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to - * allocate the new evaluation - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_create_features_evaluation( - ccs_objective_space_t objective_space, - ccs_search_configuration_t configuration, - ccs_features_t features, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_features_evaluation_t *features_evaluation_ret); - -/** - * Get the features associated with a features evaluation. - * @param[in] features_evaluation - * @param[out] features_ret a pointer to the variable that will contain - * the features - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features_evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_features( - ccs_features_evaluation_t features_evaluation, - ccs_features_t *features_ret); - -#ifdef __cplusplus -} -#endif - -#endif //_CCS_FEATURES_EVALUATION_H diff --git a/include/cconfigspace/features_tuner.h b/include/cconfigspace/features_tuner.h index 81d0c510..ab1c98bf 100644 --- a/include/cconfigspace/features_tuner.h +++ b/include/cconfigspace/features_tuner.h @@ -10,8 +10,7 @@ extern "C" { * A CCS features tuner defines an ask and tell interface to optimize an * objective space (see objective_space.h) given a feature space (see * feature_space.h). The tuner will propose configurations (see - * configuration.h) and the user will return features evaluations (see - * features_evaluation.h). + * configuration.h) and the user will return evaluations (see evaluation.h). */ /** @@ -173,7 +172,7 @@ ccs_features_tuner_ask( * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluations is NULL and \p * num_evaluations is greater than 0 * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if an evaluation is not a valid - * features evaluation for the problem the features tuner is optimizing + * evaluation for the problem the features tuner is optimizing * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to * allocate internal data structures. * @remarks @@ -181,9 +180,9 @@ ccs_features_tuner_ask( */ extern ccs_result_t ccs_features_tuner_tell( - ccs_features_tuner_t features_tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations); + ccs_features_tuner_t features_tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations); /** * Ask a features tuner to suggest a good configuration given some features. @@ -237,11 +236,11 @@ ccs_features_tuner_suggest( */ extern ccs_result_t ccs_features_tuner_get_optima( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); /** * Ask a features tuner for the evaluation history. @@ -269,25 +268,23 @@ ccs_features_tuner_get_optima( */ extern ccs_result_t ccs_features_tuner_get_history( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); /** * Create a new random features tuner. The random features tuner should be * viewed as a baseline for evaluating features tuners, and as a tool for * developing interfaces. * @param[in] name the name of the features tuner - * @param[in] feature_space the feature space * @param[in] objective_space the objective space to potimize * @param[out] features_tuner_ret a pointer to the variable that will contain * the newly created features tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p feature_space is not a - * valid CCS feature space + * a valid CCS objective space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p features * tuner_ret is NULL * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to @@ -298,7 +295,6 @@ ccs_features_tuner_get_history( extern ccs_result_t ccs_create_random_features_tuner( const char *name, - ccs_feature_space_t feature_space, ccs_objective_space_t objective_space, ccs_features_tuner_t *features_tuner_ret); @@ -323,31 +319,31 @@ struct ccs_user_defined_features_tuner_vector_s { /** The features tuner tell interface see ccs_features_tuner_tell */ ccs_result_t (*tell)( - ccs_features_tuner_t features_tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations); + ccs_features_tuner_t features_tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations); /** * The features tuner get_optima interface see * ccs_features_tuner_get_optima */ ccs_result_t (*get_optima)( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); /** * The features tuner get_history interface see * ccs_features_tuner_get_history */ ccs_result_t (*get_history)( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); /** * The features tuner suggest interface see ccs_features_tuner_suggest, @@ -372,13 +368,13 @@ struct ccs_user_defined_features_tuner_vector_s { * case, the history will be set through the tell interface */ ccs_result_t (*deserialize_state)( - ccs_features_tuner_t features_tuner, - size_t size_history, - ccs_features_evaluation_t *history, - size_t num_optima, - ccs_features_evaluation_t *optima, - size_t state_size, - const void *state); + ccs_features_tuner_t features_tuner, + size_t size_history, + ccs_evaluation_t *history, + size_t num_optima, + ccs_evaluation_t *optima, + size_t state_size, + const void *state); }; /** @@ -390,7 +386,6 @@ typedef struct ccs_user_defined_features_tuner_vector_s /** * Create a new user defined features tuner. * @param[in] name the name of the features tuner - * @param[in] feature_space the feature space * @param[in] objective_space the objective space to optimize * @param[in] vector the vector of callbacks implementing the features tuner * interface @@ -400,8 +395,7 @@ typedef struct ccs_user_defined_features_tuner_vector_s * the newly created features tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p feature_space is not a - * valid CCS feature space + * a valid CCS objective space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * features_tuner_ret is NULL; or if \p vector is NULL; or if any interface * pointer except suggest is NULL @@ -413,7 +407,6 @@ typedef struct ccs_user_defined_features_tuner_vector_s extern ccs_result_t ccs_create_user_defined_features_tuner( const char *name, - ccs_feature_space_t feature_space, ccs_objective_space_t objective_space, ccs_user_defined_features_tuner_vector_t *vector, void *tuner_data, diff --git a/include/cconfigspace/tree_configuration.h b/include/cconfigspace/tree_configuration.h index 5215b482..2315efc2 100644 --- a/include/cconfigspace/tree_configuration.h +++ b/include/cconfigspace/tree_configuration.h @@ -15,6 +15,9 @@ extern "C" { * Create a new instance of a tree configuration on a given tree_space. * An empty position targets the root of the tree. * @param[in] tree_space + * @param[in] features an optional features to use. If NULL and a feature space + * was provided at \p configuration_space creation, the + * deafult features of the feature space will be used. * @param[in] position_size the number of entries in the \p position array * @param[in] position an array of indexes defining a location in the tree. * can be NULL if \p position_size is 0 @@ -22,7 +25,9 @@ extern "C" { * newly created tree configuration * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS - * tree space + * tree space; or if \p features is not NULL and is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p tree_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL; or * if \p position is NULL and \p position_size is greater than 0 * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to @@ -33,6 +38,7 @@ extern "C" { extern ccs_result_t ccs_create_tree_configuration( ccs_tree_space_t tree_space, + ccs_features_t features, size_t position_size, const size_t *position, ccs_tree_configuration_t *configuration_ret); @@ -54,6 +60,24 @@ ccs_tree_configuration_get_tree_space( ccs_tree_configuration_t configuration, ccs_tree_space_t *tree_space_ret); +/** + * Get the associated features. + * @param[in] configuration + * @param[out] features_ret a pointer to the variable that will contain the + * returned features or NULL if none is associated + * to the configuration. + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid + * CCS tree configuration + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_tree_configuration_get_feature( + ccs_tree_configuration_t configuration, + ccs_features_t *features_ret); + /** * Get the position of the configuration. * @param[in] configuration diff --git a/include/cconfigspace/tree_space.h b/include/cconfigspace/tree_space.h index 88519ae0..64bb3808 100644 --- a/include/cconfigspace/tree_space.h +++ b/include/cconfigspace/tree_space.h @@ -7,14 +7,16 @@ extern "C" { /** * @file tree_space.h - * A CCS tree space defines an search space over a tree. Tree spaces can be - * sampled to obtain tree configurations. Configurations con point to unknown - * children (if they exist). This is where static tree spaces and dynamic tree - * spaces differ: in a static tree space, the user is responsible for modifying - * the tree before evaluating these configuration values or node; in a dynamic - * tree space, when querying a configuration validity, node or values, a - * callback will be invoked to define the missing children on the configuration - * path. Sampling a dynamic tree space, by itself, does not modify the tree. + * A CCS tree space defines an search space over a tree. Optionally + * configuration space can be attached a feature space (see feature_space.h). + * Tree spaces can be sampled to obtain tree configurations. Configurations con + * point to unknown children (if they exist). This is where static tree spaces + * and dynamic tree spaces differ: in a static tree space, the user is + * responsible for modifying the tree before evaluating these configuration + * values or node; in a dynamic tree space, when querying a configuration + * validity, node or values, a callback will be invoked to define the missing + * children on the configuration path. Sampling a dynamic tree space, by + * itself, does not modify the tree. */ /** @@ -40,6 +42,7 @@ typedef enum ccs_tree_space_type_e ccs_tree_space_type_t; * Create a new static tree space. * @param[in] name pointer to a string that will be copied internally * @param[in] tree the tree defining the tree space + * @param[in] feature_space an optional CCS feature space object * @param[in] rng an optional CCS rng object * @param[out] tree_space_ret a pointer to the variable that will hold * the newly created tree space. @@ -47,7 +50,8 @@ typedef enum ccs_tree_space_type_e ccs_tree_space_type_t; * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tree_space_ret is NULL * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p rng is not NULL and is not a - * valid CCS rng + * valid CCS rng; or it \p feature_space is not NULL and is not a valid CCS + * feature space * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to * allocate the new tree space * @remarks @@ -55,10 +59,11 @@ typedef enum ccs_tree_space_type_e ccs_tree_space_type_t; */ extern ccs_result_t ccs_create_static_tree_space( - const char *name, - ccs_tree_t tree, - ccs_rng_t rng, - ccs_tree_space_t *tree_space_ret); + const char *name, + ccs_tree_t tree, + ccs_feature_space_t feature_space, + ccs_rng_t rng, + ccs_tree_space_t *tree_space_ret); /** * A structure that define the callbacks the user must provide to create a @@ -119,6 +124,7 @@ typedef struct ccs_dynamic_tree_space_vector_s ccs_dynamic_tree_space_vector_t; * Create a new static tree space. * @param[in] name pointer to a string that will be copied internally * @param[in] tree the tree defining the tree space + * @param[in] feature_space an optional CCS feature space object * @param[in] rng an optional CCS rng object * @param[in] vector the callback vector implementing the dynamic tree space * interface @@ -130,7 +136,8 @@ typedef struct ccs_dynamic_tree_space_vector_s ccs_dynamic_tree_space_vector_t; * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tree_space_ret is NULL; or if any non optional interface pointer is NULL * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p rng is not NULL and is not a - * valid CCS rng + * valid CCS rng; or it \p feature_space is not NULL and is not a valid CCS + * feature space * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to * allocate the new tree space * @remarks @@ -140,6 +147,7 @@ extern ccs_result_t ccs_create_dynamic_tree_space( const char *name, ccs_tree_t tree, + ccs_feature_space_t feature_space, ccs_rng_t rng, ccs_dynamic_tree_space_vector_t *vector, void *tree_space_data, @@ -191,6 +199,23 @@ ccs_tree_space_get_name(ccs_tree_space_t tree_space, const char **name_ret); extern ccs_result_t ccs_tree_space_get_rng(ccs_tree_space_t tree_space, ccs_rng_t *rng_ret); +/** + * Get the feature space of the tree space. + * @param[in] tree_space + * @param[out] feature_space_ret a pointer to the variable that will contain + * the feature space + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree_space is not a + * valid CCS tree space + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p feature_space_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_tree_space_get_feature_space( + ccs_tree_space_t tree_space, + ccs_feature_space_t *feature_space_ret); + /** * Get the tree of a tree space. * @param[in] tree_space @@ -314,12 +339,17 @@ ccs_tree_space_check_configuration( * sampled according to the weight and bias of the individual tree nodes. If * those are at their default values, the tree nodes are sampled uniformly. * @param[in] tree_space + * @param[in] features an optional features to use. Required if a feature space + * was provided at \p tree_space creation. * @param[in] rng an optional rng to use * @param[out] configuration_ret a pointer to the variable that will contain the * returned tree configuration * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS - * tree space; or if \p rng is not a valid CCS rng + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree_space is not a valid CCS + * tree space; or if \p rng is not a valid CCS rng; or if \p features is not + * NULL and is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p tree_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to * allocate the new configuration @@ -329,6 +359,7 @@ ccs_tree_space_check_configuration( extern ccs_result_t ccs_tree_space_sample( ccs_tree_space_t tree_space, + ccs_features_t features, ccs_rng_t rng, ccs_tree_configuration_t *configuration_ret); @@ -338,13 +369,18 @@ ccs_tree_space_sample( * nodes. If those are at their default values, the tree nodes are sampled * uniformely. * @param[in] tree_space + * @param[in] features an optional features to use. Required if a feature space + * was provided at \p tree_space creation. * @param[in] rng an optional rng to use * @param[in] num_configurations the number of requested configurations * @param[out] configurations an array of \p num_configurations that will * contain the requested configurations * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS - * tree space; or if \p rng is not a valid CCS rng + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree_space is not a valid CCS + * tree space; or if \p rng is not NULL and is not a valid CCS rng; or if \p + * features is not NULL and is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not + * the same as the feature space provided at \p tree_space creation. * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configurations is NULL and \p * num_configurations is greater than 0 * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to @@ -355,6 +391,7 @@ ccs_tree_space_sample( extern ccs_result_t ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations); @@ -364,9 +401,9 @@ ccs_tree_space_samples( * @param[in] tree_space * @param[out] tree_space_data_ret * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree_space is not a valid CCS * tree space - * @return #CCS_RESULT_ERROR_INVALID_TREE_SPACE if \p tree space is not a + * @return #CCS_RESULT_ERROR_INVALID_TREE_SPACE if \p tree_space is not a * dynamic tree space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p tree_space_data_ret is NULL * @remarks diff --git a/src/Makefile.am b/src/Makefile.am index 7f918247..1a713548 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -93,9 +93,6 @@ libcconfigspace_la_SOURCES = \ features.c \ features_internal.h \ features_deserialize.h \ - features_evaluation.c \ - features_evaluation_internal.h \ - features_evaluation_deserialize.h \ features_tuner.c \ features_tuner_internal.h \ features_tuner_deserialize.h \ diff --git a/src/binding_internal.h b/src/binding_internal.h index e42aef24..56d45615 100644 --- a/src/binding_internal.h +++ b/src/binding_internal.h @@ -110,8 +110,6 @@ _ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret) _ccs_binding_data_t *data = binding->data; ccs_hash_t h, ht; HASH_JEN(&(data->context), sizeof(data->context), h); - HASH_JEN(&(data->num_values), sizeof(data->num_values), ht); - h = _hash_combine(h, ht); for (size_t i = 0; i < data->num_values; i++) { ht = _hash_datum(data->values + i); h = _hash_combine(h, ht); @@ -137,11 +135,6 @@ _ccs_binding_cmp( 0; if (*cmp_ret) return CCS_RESULT_SUCCESS; - *cmp_ret = data->num_values < other_data->num_values ? -1 : - data->num_values > other_data->num_values ? 1 : - 0; - if (*cmp_ret) - return CCS_RESULT_SUCCESS; for (size_t i = 0; i < data->num_values; i++) { if ((*cmp_ret = _datum_cmp( data->values + i, other_data->values + i))) diff --git a/src/cconfigspace_deserialize.h b/src/cconfigspace_deserialize.h index cc67140e..fb06fd05 100644 --- a/src/cconfigspace_deserialize.h +++ b/src/cconfigspace_deserialize.h @@ -31,7 +31,6 @@ _ccs_object_deserialize_with_opts( #include "configuration_deserialize.h" #include "evaluation_deserialize.h" #include "features_deserialize.h" -#include "features_evaluation_deserialize.h" #include "tuner_deserialize.h" #include "features_tuner_deserialize.h" #include "map_deserialize.h" @@ -148,11 +147,6 @@ _ccs_object_deserialize_with_opts_type( (ccs_features_t *)object_ret, format, version, buffer_size, buffer, opts)); break; - case CCS_OBJECT_TYPE_FEATURES_EVALUATION: - CCS_VALIDATE(_ccs_features_evaluation_deserialize( - (ccs_features_evaluation_t *)object_ret, format, - version, buffer_size, buffer, opts)); - break; case CCS_OBJECT_TYPE_TUNER: CCS_VALIDATE(_ccs_tuner_deserialize( (ccs_tuner_t *)object_ret, format, version, buffer_size, diff --git a/src/cconfigspace_internal.h b/src/cconfigspace_internal.h index e2c0a137..cde8eb25 100644 --- a/src/cconfigspace_internal.h +++ b/src/cconfigspace_internal.h @@ -249,23 +249,12 @@ _ccs_do_nothing(void) CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS context '%s' == %p supplied", #c, c) -#define CCS_CHECK_EVALUATION(e) \ - CCS_REFUTE_MSG( \ - !CCS_OBJ_IS_VALID(e) || \ - !(CCS_OBJ_IS_TYPE(e, CCS_OBJECT_TYPE_EVALUATION) || \ - CCS_OBJ_IS_TYPE( \ - e, CCS_OBJECT_TYPE_FEATURES_EVALUATION)), \ - CCS_RESULT_ERROR_INVALID_OBJECT, \ - "Invalid CCS evaluation '%s' == %p supplied", #e, e) - #define CCS_CHECK_BINDING(b) \ CCS_REFUTE_MSG( \ !CCS_OBJ_IS_VALID(b) || \ !(CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_CONFIGURATION) || \ CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_EVALUATION) || \ - CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_FEATURES) || \ - CCS_OBJ_IS_TYPE( \ - b, CCS_OBJECT_TYPE_FEATURES_EVALUATION)), \ + CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_FEATURES)), \ CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS binding '%s' == %p supplied", #b, b) diff --git a/src/configuration.c b/src/configuration.c index 745be5be..f7adf148 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -1,13 +1,78 @@ #include "cconfigspace_internal.h" #include "configuration_internal.h" #include "configuration_space_internal.h" +#include "features_internal.h" #include static ccs_result_t _ccs_configuration_del(ccs_object_t object) { ccs_configuration_t configuration = (ccs_configuration_t)object; - ccs_release_object(configuration->data->configuration_space); + if (configuration->data->configuration_space) + ccs_release_object(configuration->data->configuration_space); + if (configuration->data->features) + ccs_release_object(configuration->data->features); + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_serialize_bin_size_ccs_configuration_data( + _ccs_configuration_data_t *data, + size_t *cum_size, + _ccs_object_serialize_options_t *opts) +{ + *cum_size += _ccs_serialize_bin_size_ccs_binding_data( + (_ccs_binding_data_t *)data); + *cum_size += _ccs_serialize_bin_size_ccs_bool(data->features != NULL); + if (data->features) + CCS_VALIDATE(data->features->obj.ops->serialize_size( + data->features, CCS_SERIALIZE_FORMAT_BINARY, cum_size, + opts)); + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_serialize_bin_ccs_configuration_data( + _ccs_configuration_data_t *data, + size_t *buffer_size, + char **buffer, + _ccs_object_serialize_options_t *opts) +{ + CCS_VALIDATE(_ccs_serialize_bin_ccs_binding_data( + (_ccs_binding_data_t *)data, buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_bool( + data->features != NULL, buffer_size, buffer)); + if (data->features) + CCS_VALIDATE(data->features->obj.ops->serialize( + data->features, CCS_SERIALIZE_FORMAT_BINARY, + buffer_size, buffer, opts)); + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_serialize_bin_size_ccs_configuration( + ccs_configuration_t configuration, + size_t *cum_size, + _ccs_object_serialize_options_t *opts) +{ + *cum_size += _ccs_serialize_bin_size_ccs_object_internal( + (_ccs_object_internal_t *)configuration); + CCS_VALIDATE(_ccs_serialize_bin_size_ccs_configuration_data( + configuration->data, cum_size, opts)); + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_serialize_bin_ccs_configuration( + ccs_configuration_t configuration, + size_t *buffer_size, + char **buffer, + _ccs_object_serialize_options_t *opts) +{ + CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( + (_ccs_object_internal_t *)configuration, buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_configuration_data( + configuration->data, buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } @@ -20,8 +85,8 @@ _ccs_configuration_serialize_size( { switch (format) { case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_binding( - (ccs_binding_t)object, cum_size)); + CCS_VALIDATE(_ccs_serialize_bin_size_ccs_configuration( + (ccs_configuration_t)object, cum_size, opts)); break; default: CCS_RAISE( @@ -43,8 +108,9 @@ _ccs_configuration_serialize( { switch (format) { case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_ccs_binding( - (ccs_binding_t)object, buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_configuration( + (ccs_configuration_t)object, buffer_size, buffer, + opts)); break; default: CCS_RAISE( @@ -59,7 +125,13 @@ _ccs_configuration_serialize( static ccs_result_t _ccs_configuration_hash(ccs_configuration_t configuration, ccs_hash_t *hash_ret) { - return _ccs_binding_hash((ccs_binding_t)configuration, hash_ret); + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash( + (ccs_binding_t)configuration->data->features, &h)); + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)configuration, &ht)); + h = _hash_combine(h, ht); + *hash_ret = h; + return CCS_RESULT_SUCCESS; } static ccs_result_t @@ -68,8 +140,16 @@ _ccs_configuration_cmp( ccs_configuration_t other, int *cmp_ret) { - return _ccs_binding_cmp( - (ccs_binding_t)configuration, (ccs_binding_t)other, cmp_ret); + if (configuration->data->features) { + CCS_VALIDATE(_ccs_binding_cmp( + (ccs_binding_t)configuration->data->features, + (ccs_binding_t)other->data->features, cmp_ret)); + if (*cmp_ret) + return CCS_RESULT_SUCCESS; + } + CCS_VALIDATE(_ccs_binding_cmp( + (ccs_binding_t)configuration, (ccs_binding_t)other, cmp_ret)); + return CCS_RESULT_SUCCESS; } static _ccs_configuration_ops_t _configuration_ops = { @@ -81,6 +161,7 @@ static _ccs_configuration_ops_t _configuration_ops = { ccs_result_t _ccs_create_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, size_t num_values, ccs_datum_t *values, ccs_configuration_t *configuration_ret) @@ -92,20 +173,32 @@ _ccs_create_configuration( sizeof(struct _ccs_configuration_data_s) + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(configuration_space), errmem); + uintptr_t mem_orig = mem; ccs_configuration_t config; config = (ccs_configuration_t)mem; + mem += sizeof(struct _ccs_configuration_s); _ccs_object_init( &(config->obj), CCS_OBJECT_TYPE_CONFIGURATION, (_ccs_object_ops_t *)&_configuration_ops); - config->data = (struct _ccs_configuration_data_s - *)(mem + sizeof(struct _ccs_configuration_s)); - config->data->num_values = num_parameters; + config->data = (struct _ccs_configuration_data_s *)mem; + mem += sizeof(struct _ccs_configuration_data_s); + config->data->num_values = num_parameters; + config->data->values = (ccs_datum_t *)mem; + mem += sizeof(ccs_datum_t) * num_parameters; + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(configuration_space), errinit); config->data->configuration_space = configuration_space; - config->data->values = - (ccs_datum_t - *)(mem + sizeof(struct _ccs_configuration_s) + sizeof(struct _ccs_configuration_data_s)); + if (features) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(features), errinit); + else if (configuration_space->data->feature_space) + CCS_VALIDATE_ERR_GOTO( + err, + ccs_feature_space_get_default_features( + configuration_space->data->feature_space, + &features), + errinit); + config->data->features = features; if (values) { memcpy(config->data->values, values, num_parameters * sizeof(ccs_datum_t)); @@ -123,27 +216,36 @@ _ccs_create_configuration( *configuration_ret = config; return CCS_RESULT_SUCCESS; errinit: + _ccs_configuration_del(config); _ccs_object_deinit(&(config->obj)); -errmem: - free((void *)mem); + free((void *)mem_orig); return err; } ccs_result_t ccs_create_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, size_t num_values, ccs_datum_t *values, ccs_configuration_t *configuration_ret) { CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != + configuration_space->data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } CCS_CHECK_PTR(configuration_ret); CCS_CHECK_ARY(num_values, values); size_t num_parameters = configuration_space->data->num_parameters; CCS_REFUTE( num_parameters != num_values, CCS_RESULT_ERROR_INVALID_VALUE); CCS_VALIDATE(_ccs_create_configuration( - configuration_space, num_values, values, configuration_ret)); + configuration_space, features, num_values, values, + configuration_ret)); return CCS_RESULT_SUCCESS; } @@ -153,9 +255,19 @@ ccs_configuration_get_configuration_space( ccs_configuration_space_t *configuration_space_ret) { CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_VALIDATE(_ccs_binding_get_context( - (ccs_binding_t)configuration, - (ccs_context_t *)configuration_space_ret)); + CCS_CHECK_PTR(configuration_space_ret); + *configuration_space_ret = configuration->data->configuration_space; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_configuration_get_feature( + ccs_configuration_t configuration, + ccs_features_t *features_ret) +{ + CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); + CCS_CHECK_PTR(features_ret); + *features_ret = configuration->data->features; return CCS_RESULT_SUCCESS; } diff --git a/src/configuration_deserialize.h b/src/configuration_deserialize.h index 55c0bfe8..8556b6e5 100644 --- a/src/configuration_deserialize.h +++ b/src/configuration_deserialize.h @@ -2,6 +2,33 @@ #define _CONFIGURATION_DESERIALIZE_H #include "configuration_internal.h" +struct _ccs_configuration_data_mock_s { + _ccs_binding_data_t base; + ccs_bool_t features_present; + ccs_features_t features; +}; +typedef struct _ccs_configuration_data_mock_s _ccs_configuration_data_mock_t; + +static inline ccs_result_t +_ccs_deserialize_bin_ccs_configuration_data( + _ccs_configuration_data_mock_t *data, + uint32_t version, + size_t *buffer_size, + const char **buffer, + _ccs_object_deserialize_options_t *opts) +{ + CCS_VALIDATE(_ccs_deserialize_bin_ccs_binding_data( + &data->base, version, buffer_size, buffer)); + CCS_VALIDATE(_ccs_deserialize_bin_ccs_bool( + &data->features_present, buffer_size, buffer)); + if (data->features_present) + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)&data->features, + CCS_OBJECT_TYPE_FEATURES, CCS_SERIALIZE_FORMAT_BINARY, + version, buffer_size, buffer, opts)); + return CCS_RESULT_SUCCESS; +} + static inline ccs_result_t _ccs_deserialize_bin_configuration( ccs_configuration_t *configuration_ret, @@ -11,28 +38,31 @@ _ccs_deserialize_bin_configuration( _ccs_object_deserialize_options_t *opts) { CCS_CHECK_OBJ(opts->handle_map, CCS_OBJECT_TYPE_MAP); - _ccs_object_internal_t obj; - ccs_object_t handle; - ccs_datum_t d; - ccs_configuration_space_t cs; - ccs_configuration_t configuration; - ccs_result_t res = CCS_RESULT_SUCCESS; + _ccs_object_deserialize_options_t new_opts = *opts; + _ccs_object_internal_t obj; + ccs_object_t handle; + ccs_datum_t d; + ccs_configuration_space_t cs; + ccs_configuration_t configuration; + ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( &obj, buffer_size, buffer, &handle)); CCS_REFUTE( obj.type != CCS_OBJECT_TYPE_CONFIGURATION, CCS_RESULT_ERROR_INVALID_TYPE); - _ccs_binding_data_t data = {NULL, 0, NULL}; + new_opts.map_values = CCS_FALSE; + _ccs_configuration_data_mock_t data = { + {NULL, 0, NULL}, CCS_FALSE, NULL}; CCS_VALIDATE_ERR_GOTO( res, - _ccs_deserialize_bin_ccs_binding_data( - &data, version, buffer_size, buffer), + _ccs_deserialize_bin_ccs_configuration_data( + &data, version, buffer_size, buffer, &new_opts), end); CCS_VALIDATE_ERR_GOTO( res, - ccs_map_get(opts->handle_map, ccs_object(data.context), &d), + ccs_map_get(opts->handle_map, ccs_object(data.base.context), &d), end); CCS_REFUTE_ERR_GOTO( res, d.type != CCS_DATA_TYPE_OBJECT, @@ -42,7 +72,8 @@ _ccs_deserialize_bin_configuration( CCS_VALIDATE_ERR_GOTO( res, ccs_create_configuration( - cs, data.num_values, data.values, &configuration), + cs, data.features, data.base.num_values, + data.base.values, &configuration), end); if (opts->map_values) @@ -58,8 +89,10 @@ _ccs_deserialize_bin_configuration( err_configuration: ccs_release_object(configuration); end: - if (data.values) - free(data.values); + if (data.features) + ccs_release_object(data.features); + if (data.base.values) + free(data.base.values); return res; } diff --git a/src/configuration_internal.h b/src/configuration_internal.h index 4f209b5b..275dcac7 100644 --- a/src/configuration_internal.h +++ b/src/configuration_internal.h @@ -27,11 +27,13 @@ struct _ccs_configuration_data_s { ccs_configuration_space_t configuration_space; size_t num_values; ccs_datum_t *values; + ccs_features_t features; }; ccs_result_t _ccs_create_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, size_t num_values, ccs_datum_t *values, ccs_configuration_t *configuration_ret); diff --git a/src/configuration_space.c b/src/configuration_space.c index 14dfaacc..46cc043b 100644 --- a/src/configuration_space.c +++ b/src/configuration_space.c @@ -2,8 +2,11 @@ #include "configuration_space_internal.h" #include "distribution_space_internal.h" #include "configuration_internal.h" +#include "feature_space_internal.h" +#include "features_internal.h" #include "distribution_internal.h" #include "expression_internal.h" +#include "parameter_internal.h" #include "rng_internal.h" #include "utlist.h" #include "utarray.h" @@ -36,13 +39,16 @@ _ccs_configuration_space_del(ccs_object_t object) if (data->forbidden_clauses[i]) ccs_release_object(data->forbidden_clauses[i]); - HASH_CLEAR(hh_name, configuration_space->data->name_hash); - HASH_CLEAR(hh_handle, configuration_space->data->handle_hash); - ccs_release_object(configuration_space->data->rng); - if (configuration_space->data->default_distribution_space) { + HASH_CLEAR(hh_name, data->name_hash); + HASH_CLEAR(hh_handle, data->handle_hash); + if (data->rng) + ccs_release_object(data->rng); + if (data->feature_space) + ccs_release_object(data->feature_space); + if (data->default_distribution_space) { _ccs_distribution_space_del_no_release( - configuration_space->data->default_distribution_space); - free(configuration_space->data->default_distribution_space); + data->default_distribution_space); + free(data->default_distribution_space); } return CCS_RESULT_SUCCESS; } @@ -66,6 +72,13 @@ _ccs_serialize_bin_size_ccs_configuration_space_data( *cum_size += _ccs_serialize_bin_size_size(condition_count); *cum_size += _ccs_serialize_bin_size_size(data->num_forbidden_clauses); + /* feature space */ + *cum_size += _ccs_serialize_bin_size_ccs_object(data->feature_space); + if (data->feature_space) + CCS_VALIDATE(data->feature_space->obj.ops->serialize_size( + data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, + cum_size, opts)); + /* rng */ CCS_VALIDATE(data->rng->obj.ops->serialize_size( data->rng, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); @@ -122,6 +135,14 @@ _ccs_serialize_bin_ccs_configuration_space_data( CCS_VALIDATE(_ccs_serialize_bin_size( data->num_forbidden_clauses, buffer_size, buffer)); + /* feature space */ + CCS_VALIDATE(_ccs_serialize_bin_ccs_object( + data->feature_space, buffer_size, buffer)); + if (data->feature_space) + CCS_VALIDATE(data->feature_space->obj.ops->serialize( + data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, + buffer_size, buffer, opts)); + /* rng */ CCS_VALIDATE(data->rng->obj.ops->serialize( data->rng, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, @@ -282,7 +303,7 @@ _ccs_configuration_space_add_forbidden_clauses( ccs_configuration_t default_config; ccs_result_t err = CCS_RESULT_SUCCESS; CCS_VALIDATE(ccs_configuration_space_get_default_configuration( - configuration_space, &default_config)); + configuration_space, NULL, &default_config)); for (size_t i = 0; i < num_expressions; i++) CCS_VALIDATE_ERR_GOTO( err, @@ -505,6 +526,7 @@ ccs_create_configuration_space( ccs_expression_t *conditions, size_t num_forbidden_clauses, ccs_expression_t *forbidden_clauses, + ccs_feature_space_t feature_space, ccs_rng_t rng, ccs_configuration_space_t *configuration_space_ret) { @@ -522,6 +544,8 @@ ccs_create_configuration_space( CCS_CHECK_ARY(num_forbidden_clauses, forbidden_clauses); for (size_t i = 0; i < num_forbidden_clauses; i++) CCS_CHECK_OBJ(forbidden_clauses[i], CCS_OBJECT_TYPE_EXPRESSION); + if (feature_space) + CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); @@ -538,11 +562,7 @@ ccs_create_configuration_space( sizeof(ccs_expression_t) * num_forbidden_clauses + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - uintptr_t mem_orig = mem; - if (rng) - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errmem); - else - CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); + uintptr_t mem_orig = mem; ccs_configuration_space_t config_space; config_space = (ccs_configuration_space_t)mem; @@ -569,7 +589,16 @@ ccs_create_configuration_space( config_space->data->name = (const char *)mem; config_space->data->num_parameters = num_parameters; config_space->data->num_forbidden_clauses = num_forbidden_clauses; - config_space->data->rng = rng; + if (rng) + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errparams); + else + CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errparams); + config_space->data->rng = rng; + if (feature_space) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(feature_space), errparams); + config_space->data->feature_space = feature_space; + strcpy((char *)(config_space->data->name), name); CCS_VALIDATE_ERR_GOTO( err, @@ -602,7 +631,6 @@ ccs_create_configuration_space( errparams: _ccs_configuration_space_del(config_space); _ccs_object_deinit(&(config_space->obj)); -errmem: free((void *)mem_orig); return err; } @@ -620,6 +648,17 @@ ccs_configuration_space_get_rng( return CCS_RESULT_SUCCESS; } +ccs_result_t +ccs_configuration_space_get_feature_space( + ccs_configuration_space_t configuration_space, + ccs_feature_space_t *feature_space_ret) +{ + CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + CCS_CHECK_PTR(feature_space_ret); + *feature_space_ret = configuration_space->data->feature_space; + return CCS_RESULT_SUCCESS; +} + static ccs_result_t _set_actives( ccs_configuration_space_t configuration_space, @@ -647,14 +686,22 @@ _set_actives( ccs_result_t ccs_configuration_space_get_default_configuration( ccs_configuration_space_t configuration_space, + ccs_features_t features, ccs_configuration_t *configuration_ret) { CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != + configuration_space->data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } CCS_CHECK_PTR(configuration_ret); ccs_result_t err; ccs_configuration_t config; CCS_VALIDATE(_ccs_create_configuration( - configuration_space, 0, NULL, &config)); + configuration_space, features, 0, NULL, &config)); ccs_parameter_t *parameters = configuration_space->data->parameters; ccs_datum_t *values = config->data->values; for (size_t i = 0; i < configuration_space->data->num_parameters; i++) @@ -808,6 +855,7 @@ static inline ccs_result_t _ccs_configuration_space_samples( ccs_configuration_space_t configuration_space, ccs_distribution_space_t distrib_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_configuration_t *configurations) @@ -837,7 +885,8 @@ _ccs_configuration_space_samples( CCS_VALIDATE_ERR_GOTO( err, _ccs_create_configuration( - configuration_space, 0, NULL, &config), + configuration_space, features, 0, NULL, + &config), end); CCS_VALIDATE_ERR_GOTO( err, @@ -868,6 +917,7 @@ ccs_result_t ccs_configuration_space_sample( ccs_configuration_space_t configuration_space, ccs_distribution_space_t distribution_space, + ccs_features_t features, ccs_rng_t rng, ccs_configuration_t *configuration_ret) { @@ -880,11 +930,18 @@ ccs_configuration_space_sample( configuration_space, CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE); } + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != + configuration_space->data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(configuration_ret); CCS_VALIDATE(_ccs_configuration_space_samples( - configuration_space, distribution_space, rng, 1, + configuration_space, distribution_space, features, rng, 1, configuration_ret)); return CCS_RESULT_SUCCESS; } @@ -893,6 +950,7 @@ ccs_result_t ccs_configuration_space_samples( ccs_configuration_space_t configuration_space, ccs_distribution_space_t distribution_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_configuration_t *configurations) @@ -906,13 +964,20 @@ ccs_configuration_space_samples( configuration_space, CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE); } + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != + configuration_space->data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_ARY(num_configurations, configurations); if (!num_configurations) return CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_configuration_space_samples( - configuration_space, distribution_space, rng, + configuration_space, distribution_space, features, rng, num_configurations, configurations)); return CCS_RESULT_SUCCESS; } diff --git a/src/configuration_space_deserialize.h b/src/configuration_space_deserialize.h index 45feb8ed..b06a941c 100644 --- a/src/configuration_space_deserialize.h +++ b/src/configuration_space_deserialize.h @@ -2,14 +2,16 @@ #define _CONFIGURATION_SPACE_DESERIALIZE_H struct _ccs_configuration_space_data_mock_s { - const char *name; - size_t num_parameters; - size_t num_conditions; - size_t num_forbidden_clauses; - ccs_rng_t rng; - ccs_parameter_t *parameters; - ccs_expression_t *conditions; - ccs_expression_t *forbidden_clauses; + const char *name; + size_t num_parameters; + size_t num_conditions; + size_t num_forbidden_clauses; + ccs_object_t feature_space_handle; + ccs_feature_space_t feature_space; + ccs_rng_t rng; + ccs_parameter_t *parameters; + ccs_expression_t *conditions; + ccs_expression_t *forbidden_clauses; }; typedef struct _ccs_configuration_space_data_mock_s _ccs_configuration_space_data_mock_t; @@ -32,6 +34,15 @@ _ccs_deserialize_bin_ccs_configuration_space_data( &data->num_conditions, buffer_size, buffer)); CCS_VALIDATE(_ccs_deserialize_bin_size( &data->num_forbidden_clauses, buffer_size, buffer)); + CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( + &data->feature_space_handle, buffer_size, buffer)); + if (data->feature_space_handle) { + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)&data->feature_space, + CCS_OBJECT_TYPE_FEATURE_SPACE, + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, + buffer, opts)); + } CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( (ccs_object_t *)&data->rng, CCS_OBJECT_TYPE_RNG, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, @@ -100,8 +111,8 @@ _ccs_deserialize_bin_configuration_space( new_opts.map_values = CCS_TRUE; CCS_VALIDATE(ccs_create_map(&new_opts.handle_map)); - _ccs_configuration_space_data_mock_t data = {NULL, 0, 0, 0, - NULL, NULL, NULL, NULL}; + _ccs_configuration_space_data_mock_t data = { + NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL}; CCS_VALIDATE_ERR_GOTO( res, _ccs_deserialize_bin_ccs_configuration_space_data( @@ -112,22 +123,33 @@ _ccs_deserialize_bin_configuration_space( ccs_create_configuration_space( data.name, data.num_parameters, data.parameters, data.conditions, data.num_forbidden_clauses, - data.forbidden_clauses, data.rng, + data.forbidden_clauses, data.feature_space, data.rng, configuration_space_ret), end); - if (opts && opts->map_values && opts->handle_map) + if (opts && opts->map_values && opts->handle_map) { + if (data.feature_space_handle) + CCS_VALIDATE_ERR_GOTO( + res, + _ccs_object_handle_check_add( + opts->handle_map, + data.feature_space_handle, + (ccs_object_t)data.feature_space), + err_configuration_space); CCS_VALIDATE_ERR_GOTO( res, _ccs_object_handle_check_add( opts->handle_map, handle, (ccs_object_t)*configuration_space_ret), err_configuration_space); + } goto end; err_configuration_space: ccs_release_object(*configuration_space_ret); *configuration_space_ret = NULL; end: + if (data.feature_space) + ccs_release_object(data.feature_space); if (data.rng) ccs_release_object(data.rng); if (data.parameters) diff --git a/src/configuration_space_internal.h b/src/configuration_space_internal.h index e3e751ea..245b73a0 100644 --- a/src/configuration_space_internal.h +++ b/src/configuration_space_internal.h @@ -32,6 +32,7 @@ struct _ccs_configuration_space_data_s { size_t num_forbidden_clauses; ccs_expression_t *forbidden_clauses; ccs_rng_t rng; + ccs_feature_space_t feature_space; ccs_distribution_space_t default_distribution_space; }; diff --git a/src/evaluation.c b/src/evaluation.c index 27ad82be..6220d434 100644 --- a/src/evaluation.c +++ b/src/evaluation.c @@ -125,6 +125,116 @@ _ccs_evaluation_serialize( return CCS_RESULT_SUCCESS; } +static ccs_result_t +_ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) +{ + _ccs_evaluation_data_t *data = evaluation->data; + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)evaluation, &h)); + CCS_VALIDATE(_ccs_search_configuration_hash(data->configuration, &ht)); + h = _hash_combine(h, ht); + HASH_JEN(&(data->result), sizeof(data->result), ht); + h = _hash_combine(h, ht); + *hash_ret = h; + return CCS_RESULT_SUCCESS; +} + +static ccs_result_t +_ccs_evaluation_cmp( + ccs_evaluation_t evaluation, + ccs_evaluation_t other, + int *cmp_ret) +{ + _ccs_evaluation_data_t *data = evaluation->data; + _ccs_evaluation_data_t *other_data = other->data; + *cmp_ret = data->result < other_data->result ? -1 : + data->result > other_data->result ? 1 : + 0; + if (*cmp_ret) + return CCS_RESULT_SUCCESS; + CCS_VALIDATE(_ccs_search_configuration_cmp( + data->configuration, other_data->configuration, cmp_ret)); + if (*cmp_ret) + return CCS_RESULT_SUCCESS; + CCS_VALIDATE(_ccs_binding_cmp( + (ccs_binding_t)evaluation, (ccs_binding_t)other, cmp_ret)); + return CCS_RESULT_SUCCESS; +} + +static int +_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) +{ + if (a->type == CCS_DATA_TYPE_FLOAT) { + return a->value.f < b->value.f ? -1 : + a->value.f > b->value.f ? 1 : + 0; + } else { + return a->value.i < b->value.i ? -1 : + a->value.i > b->value.i ? 1 : + 0; + } +} + +static ccs_result_t +_ccs_evaluation_compare( + ccs_evaluation_t evaluation, + ccs_evaluation_t other_evaluation, + ccs_comparison_t *result_ret) +{ + size_t count; + int eql; + ccs_features_t features, other_features; + CCS_VALIDATE(_ccs_search_configuration_get_features( + evaluation->data->configuration, &features)); + CCS_VALIDATE(_ccs_search_configuration_get_features( + other_evaluation->data->configuration, &other_features)); + if (features != other_features) { + CCS_VALIDATE(_ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)other_features, + &eql)); + if (0 != eql) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + } + CCS_VALIDATE(ccs_objective_space_get_objectives( + evaluation->data->objective_space, 0, NULL, NULL, &count)); + *result_ret = CCS_COMPARISON_EQUIVALENT; + for (size_t i = 0; i < count; i++) { + ccs_expression_t expression; + ccs_objective_type_t type; + ccs_datum_t values[2]; + int cmp; + + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, i, &expression, + &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, values)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&other_evaluation, + values + 1)); + if ((values[0].type != CCS_DATA_TYPE_INT && + values[0].type != CCS_DATA_TYPE_FLOAT) || + values[0].type != values[1].type) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + cmp = _numeric_compare(values, values + 1); + if (cmp) { + if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) + cmp = -cmp; + if (*result_ret == CCS_COMPARISON_EQUIVALENT) + *result_ret = (ccs_comparison_t)cmp; + else if (*result_ret != cmp) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + } + } + return CCS_RESULT_SUCCESS; +} + static _ccs_evaluation_ops_t _evaluation_ops = { {&_ccs_evaluation_del, &_ccs_evaluation_serialize_size, &_ccs_evaluation_serialize}, @@ -205,7 +315,7 @@ ccs_evaluation_get_objective_space( ccs_evaluation_t evaluation, ccs_objective_space_t *objective_space_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_CHECK_PTR(objective_space_ret); *objective_space_ret = evaluation->data->objective_space; return CCS_RESULT_SUCCESS; @@ -216,7 +326,7 @@ ccs_evaluation_get_result( ccs_evaluation_t evaluation, ccs_evaluation_result_t *result_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_CHECK_PTR(result_ret); *result_ret = evaluation->data->result; return CCS_RESULT_SUCCESS; @@ -227,16 +337,28 @@ ccs_evaluation_get_configuration( ccs_evaluation_t evaluation, ccs_search_configuration_t *configuration_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_CHECK_PTR(configuration_ret); *configuration_ret = evaluation->data->configuration; return CCS_RESULT_SUCCESS; } +ccs_result_t +ccs_evaluation_get_features( + ccs_evaluation_t evaluation, + ccs_features_t *features_ret) +{ + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); + CCS_CHECK_PTR(features_ret); + CCS_VALIDATE(_ccs_search_configuration_get_features( + evaluation->data->configuration, features_ret)); + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_VALIDATE(ccs_objective_space_check_evaluation( evaluation->data->objective_space, evaluation, is_valid_ret)); return CCS_RESULT_SUCCESS; @@ -248,7 +370,7 @@ ccs_evaluation_get_objective_value( size_t index, ccs_datum_t *value_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_CHECK_PTR(value_ret); ccs_expression_t expression; ccs_objective_type_t type; @@ -266,7 +388,7 @@ ccs_evaluation_get_objective_values( ccs_datum_t *values, size_t *num_values_ret) { - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_CHECK_ARY(num_values, values); CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); size_t count; @@ -299,8 +421,8 @@ ccs_evaluation_compare( ccs_evaluation_t other_evaluation, ccs_comparison_t *result_ret) { - CCS_CHECK_EVALUATION(evaluation); - CCS_CHECK_EVALUATION(other_evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); + CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_REFUTE( evaluation->obj.type != other_evaluation->obj.type, CCS_RESULT_ERROR_INVALID_OBJECT); diff --git a/src/evaluation_deserialize.h b/src/evaluation_deserialize.h index 11c3215b..1a89a248 100644 --- a/src/evaluation_deserialize.h +++ b/src/evaluation_deserialize.h @@ -44,6 +44,7 @@ _ccs_deserialize_bin_ccs_evaluation( ccs_object_t handle; ccs_datum_t d; ccs_objective_space_t os; + ccs_evaluation_t evaluation; ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( &obj, buffer_size, buffer, &handle)); @@ -73,7 +74,7 @@ _ccs_deserialize_bin_ccs_evaluation( res, ccs_create_evaluation( os, data.configuration, data.result, - data.base.num_values, data.base.values, evaluation_ret), + data.base.num_values, data.base.values, &evaluation), end); if (opts->map_values) @@ -81,13 +82,13 @@ _ccs_deserialize_bin_ccs_evaluation( res, _ccs_object_handle_check_add( opts->handle_map, handle, - (ccs_object_t)*evaluation_ret), + (ccs_object_t)evaluation), err_evaluation); + *evaluation_ret = evaluation; goto end; err_evaluation: - ccs_release_object(*evaluation_ret); - *evaluation_ret = NULL; + ccs_release_object(evaluation); end: if (data.configuration) ccs_release_object(data.configuration); diff --git a/src/evaluation_internal.h b/src/evaluation_internal.h index e15f01ef..5c9efdc5 100644 --- a/src/evaluation_internal.h +++ b/src/evaluation_internal.h @@ -36,99 +36,4 @@ struct _ccs_evaluation_data_s { ccs_search_configuration_t configuration; }; -static inline ccs_result_t -_ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) -{ - _ccs_evaluation_data_t *data = evaluation->data; - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)evaluation, &h)); - CCS_VALIDATE(_ccs_search_configuration_hash(data->configuration, &ht)); - h = _hash_combine(h, ht); - HASH_JEN(&(data->result), sizeof(data->result), ht); - h = _hash_combine(h, ht); - *hash_ret = h; - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_evaluation_cmp( - ccs_evaluation_t evaluation, - ccs_evaluation_t other, - int *cmp_ret) -{ - CCS_VALIDATE(_ccs_binding_cmp( - (ccs_binding_t)evaluation, (ccs_binding_t)other, cmp_ret)); - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - _ccs_evaluation_data_t *data = evaluation->data; - _ccs_evaluation_data_t *other_data = other->data; - *cmp_ret = data->result < other_data->result ? -1 : - data->result > other_data->result ? 1 : - 0; - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - CCS_VALIDATE(_ccs_search_configuration_cmp( - data->configuration, other_data->configuration, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - -static inline int -_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) -{ - if (a->type == CCS_DATA_TYPE_FLOAT) { - return a->value.f < b->value.f ? -1 : - a->value.f > b->value.f ? 1 : - 0; - } else { - return a->value.i < b->value.i ? -1 : - a->value.i > b->value.i ? 1 : - 0; - } -} - -static inline ccs_result_t -_ccs_evaluation_compare( - ccs_evaluation_t evaluation, - ccs_evaluation_t other_evaluation, - ccs_comparison_t *result_ret) -{ - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - *result_ret = CCS_COMPARISON_EQUIVALENT; - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - ccs_datum_t values[2]; - int cmp; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, &expression, - &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, values)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&other_evaluation, - values + 1)); - if ((values[0].type != CCS_DATA_TYPE_INT && - values[0].type != CCS_DATA_TYPE_FLOAT) || - values[0].type != values[1].type) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - cmp = _numeric_compare(values, values + 1); - if (cmp) { - if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) - cmp = -cmp; - if (*result_ret == CCS_COMPARISON_EQUIVALENT) - *result_ret = (ccs_comparison_t)cmp; - else if (*result_ret != cmp) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - } - } - return CCS_RESULT_SUCCESS; -} - #endif //_EVALUATION_INTERNAL_H diff --git a/src/feature_space.c b/src/feature_space.c index 0e1b90d3..b2d034e5 100644 --- a/src/feature_space.c +++ b/src/feature_space.c @@ -135,6 +135,31 @@ ccs_create_feature_space( return err; } +ccs_result_t +ccs_feature_space_get_default_features( + ccs_feature_space_t feature_space, + ccs_features_t *features_ret) +{ + CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); + CCS_CHECK_PTR(features_ret); + ccs_result_t err; + ccs_features_t features; + CCS_VALIDATE(_ccs_create_features(feature_space, 0, NULL, &features)); + ccs_parameter_t *parameters = feature_space->data->parameters; + ccs_datum_t *values = features->data->values; + for (size_t i = 0; i < feature_space->data->num_parameters; i++) + CCS_VALIDATE_ERR_GOTO( + err, + ccs_parameter_get_default_value( + parameters[i], values + i), + errc); + *features_ret = features; + return CCS_RESULT_SUCCESS; +errc: + ccs_release_object(features); + return err; +} + static inline ccs_result_t _check_features( ccs_feature_space_t feature_space, diff --git a/src/features.c b/src/features.c index 7cb6e973..81f2ddc8 100644 --- a/src/features.c +++ b/src/features.c @@ -8,7 +8,8 @@ static ccs_result_t _ccs_features_del(ccs_object_t object) { ccs_features_t features = (ccs_features_t)object; - ccs_release_object(features->data->feature_space); + if (features->data->feature_space) + ccs_release_object(features->data->feature_space); return CCS_RESULT_SUCCESS; } @@ -79,38 +80,33 @@ static _ccs_features_ops_t _features_ops = { &_ccs_features_cmp}; ccs_result_t -ccs_create_features( +_ccs_create_features( ccs_feature_space_t feature_space, size_t num_values, ccs_datum_t *values, ccs_features_t *features_ret) { - CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); - CCS_CHECK_PTR(features_ret); - CCS_CHECK_ARY(num_values, values); - ccs_result_t err; size_t num_parameters = feature_space->data->num_parameters; - CCS_REFUTE( - values && num_parameters != num_values, - CCS_RESULT_ERROR_INVALID_VALUE); - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_features_s) + - sizeof(struct _ccs_features_data_s) + - num_parameters * sizeof(ccs_datum_t)); + ccs_result_t err = CCS_RESULT_SUCCESS; + uintptr_t mem = (uintptr_t)calloc( + 1, sizeof(struct _ccs_features_s) + + sizeof(struct _ccs_features_data_s) + + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), errmem); + uintptr_t mem_orig = mem; ccs_features_t feat; feat = (ccs_features_t)mem; + mem += sizeof(struct _ccs_features_s); _ccs_object_init( &(feat->obj), CCS_OBJECT_TYPE_FEATURES, (_ccs_object_ops_t *)&_features_ops); - feat->data = (struct _ccs_features_data_s - *)(mem + sizeof(struct _ccs_features_s)); - feat->data->num_values = num_parameters; + feat->data = (struct _ccs_features_data_s *)mem; + mem += sizeof(struct _ccs_features_data_s); + feat->data->num_values = num_parameters; + feat->data->values = (ccs_datum_t *)mem; + mem += sizeof(ccs_datum_t) * num_parameters; + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), errinit); feat->data->feature_space = feature_space; - feat->data->values = - (ccs_datum_t - *)(mem + sizeof(struct _ccs_features_s) + sizeof(struct _ccs_features_data_s)); if (values) { memcpy(feat->data->values, values, num_parameters * sizeof(ccs_datum_t)); @@ -122,18 +118,35 @@ ccs_create_features( (ccs_context_t)feature_space, i, values[i], feat->data->values + i), - errfs); + errinit); } *features_ret = feat; return CCS_RESULT_SUCCESS; -errfs: +errinit: + _ccs_features_del(feat); _ccs_object_deinit(&(feat->obj)); - ccs_release_object(feature_space); -errmem: - free((void *)mem); + free((void *)mem_orig); return err; } +ccs_result_t +ccs_create_features( + ccs_feature_space_t feature_space, + size_t num_values, + ccs_datum_t *values, + ccs_features_t *features_ret) +{ + CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); + CCS_CHECK_PTR(features_ret); + CCS_CHECK_ARY(num_values, values); + size_t num_parameters = feature_space->data->num_parameters; + CCS_REFUTE( + num_parameters != num_values, CCS_RESULT_ERROR_INVALID_VALUE); + CCS_VALIDATE(_ccs_create_features( + feature_space, num_values, values, features_ret)); + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_features_get_feature_space( ccs_features_t features, diff --git a/src/features_evaluation.c b/src/features_evaluation.c deleted file mode 100644 index 8f92e46a..00000000 --- a/src/features_evaluation.c +++ /dev/null @@ -1,295 +0,0 @@ -#include "cconfigspace_internal.h" -#include "evaluation_internal.h" -#include "features_evaluation_internal.h" -#include "configuration_internal.h" -#include "features_internal.h" -#include "objective_space_internal.h" -#include - -static ccs_result_t -_ccs_features_evaluation_del(ccs_object_t object) -{ - ccs_features_evaluation_t evaluation = - (ccs_features_evaluation_t)object; - ccs_release_object(evaluation->data->objective_space); - ccs_release_object(evaluation->data->configuration); - ccs_release_object(evaluation->data->features); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_features_evaluation_data( - _ccs_features_evaluation_data_t *data, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - *cum_size += _ccs_serialize_bin_size_ccs_binding_data( - (_ccs_binding_data_t *)data); - CCS_VALIDATE(data->configuration->obj.ops->serialize_size( - data->configuration, CCS_SERIALIZE_FORMAT_BINARY, cum_size, - opts)); - CCS_VALIDATE(data->features->obj.ops->serialize_size( - data->features, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); - *cum_size += - _ccs_serialize_bin_size_ccs_evaluation_result(data->result); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_features_evaluation_data( - _ccs_features_evaluation_data_t *data, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_serialize_bin_ccs_binding_data( - (_ccs_binding_data_t *)data, buffer_size, buffer)); - CCS_VALIDATE(data->configuration->obj.ops->serialize( - data->configuration, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, - buffer, opts)); - CCS_VALIDATE(data->features->obj.ops->serialize( - data->features, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, - buffer, opts)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_evaluation_result( - data->result, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_features_evaluation( - ccs_features_evaluation_t features_evaluation, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - *cum_size += _ccs_serialize_bin_size_ccs_object_internal( - (_ccs_object_internal_t *)features_evaluation); - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_features_evaluation_data( - features_evaluation->data, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_features_evaluation( - ccs_features_evaluation_t features_evaluation, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( - (_ccs_object_internal_t *)features_evaluation, buffer_size, - buffer)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_features_evaluation_data( - features_evaluation->data, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_features_evaluation_serialize_size( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_features_evaluation( - (ccs_features_evaluation_t)object, cum_size, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data_size( - object, format, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_features_evaluation_serialize( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_ccs_features_evaluation( - (ccs_features_evaluation_t)object, buffer_size, buffer, - opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data( - object, format, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_features_evaluation_hash( - ccs_features_evaluation_t features_evaluation, - ccs_hash_t *hash_ret) -{ - _ccs_features_evaluation_data_t *data = features_evaluation->data; - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)features_evaluation, &h)); - CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->configuration, &ht)); - h = _hash_combine(h, ht); - CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->features, &ht)); - h = _hash_combine(h, ht); - HASH_JEN(&(data->result), sizeof(data->result), ht); - h = _hash_combine(h, ht); - *hash_ret = h; - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_features_evaluation_cmp( - ccs_features_evaluation_t features_evaluation, - ccs_features_evaluation_t other, - int *cmp_ret) -{ - CCS_VALIDATE(_ccs_binding_cmp( - (ccs_binding_t)features_evaluation, (ccs_binding_t)other, - cmp_ret)); - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - _ccs_features_evaluation_data_t *data = features_evaluation->data; - _ccs_features_evaluation_data_t *other_data = other->data; - *cmp_ret = data->result < other_data->result ? -1 : - data->result > other_data->result ? 1 : - 0; - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_binding_cmp( - (ccs_binding_t)data->configuration, - (ccs_binding_t)other_data->configuration, cmp_ret)); - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_binding_cmp( - (ccs_binding_t)data->features, - (ccs_binding_t)other_data->features, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_features_evaluation_compare( - ccs_features_evaluation_t evaluation, - ccs_features_evaluation_t other_evaluation, - ccs_comparison_t *result_ret) -{ - int eql; - CCS_VALIDATE(ccs_binding_cmp( - (ccs_binding_t)evaluation->data->features, - (ccs_binding_t)other_evaluation->data->features, &eql)); - if (0 != eql) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - CCS_VALIDATE(_ccs_evaluation_compare( - (ccs_evaluation_t)evaluation, - (ccs_evaluation_t)other_evaluation, result_ret)); - return CCS_RESULT_SUCCESS; -} - -static _ccs_features_evaluation_ops_t _features_evaluation_ops = { - {&_ccs_features_evaluation_del, - &_ccs_features_evaluation_serialize_size, - &_ccs_features_evaluation_serialize}, - &_ccs_features_evaluation_hash, - &_ccs_features_evaluation_cmp, - &_ccs_features_evaluation_compare}; - -ccs_result_t -ccs_create_features_evaluation( - ccs_objective_space_t objective_space, - ccs_search_configuration_t configuration, - ccs_features_t features, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_features_evaluation_t *evaluation_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_REFUTE( - objective_space->data->search_space != - configuration->data->space, - CCS_RESULT_ERROR_INVALID_CONFIGURATION); - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_CHECK_PTR(evaluation_ret); - CCS_CHECK_ARY(num_values, values); - size_t num_parameters = objective_space->data->num_parameters; - CCS_REFUTE( - values && num_parameters != num_values, - CCS_RESULT_ERROR_INVALID_VALUE); - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_features_evaluation_s) + - sizeof(struct _ccs_features_evaluation_data_s) + - num_parameters * sizeof(ccs_datum_t)); - CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - ccs_result_t err; - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(objective_space), errmemory); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(configuration), errospace); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(features), errconfig); - - ccs_features_evaluation_t eval; - eval = (ccs_features_evaluation_t)mem; - _ccs_object_init( - &(eval->obj), CCS_OBJECT_TYPE_FEATURES_EVALUATION, - (_ccs_object_ops_t *)&_features_evaluation_ops); - eval->data = - (struct _ccs_features_evaluation_data_s - *)(mem + sizeof(struct _ccs_features_evaluation_s)); - eval->data->num_values = num_parameters; - eval->data->objective_space = objective_space; - eval->data->configuration = configuration; - eval->data->features = features; - eval->data->result = result; - eval->data->values = - (ccs_datum_t - *)(mem + sizeof(struct _ccs_features_evaluation_s) + sizeof(struct _ccs_features_evaluation_data_s)); - if (values) { - memcpy(eval->data->values, values, - num_parameters * sizeof(ccs_datum_t)); - for (size_t i = 0; i < num_values; i++) { - if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) { - CCS_VALIDATE_ERR_GOTO( - err, - ccs_context_validate_value( - (ccs_context_t)objective_space, - i, values[i], - eval->data->values + i), - errfeat); - } - } - } - *evaluation_ret = eval; - return CCS_RESULT_SUCCESS; -errfeat: - _ccs_object_deinit(&(eval->obj)); - ccs_release_object(features); -errconfig: - ccs_release_object(configuration); -errospace: - ccs_release_object(objective_space); -errmemory: - free((void *)mem); - return err; -} - -ccs_result_t -ccs_features_evaluation_get_features( - ccs_features_evaluation_t evaluation, - ccs_features_t *features_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(features_ret); - *features_ret = evaluation->data->features; - return CCS_RESULT_SUCCESS; -} diff --git a/src/features_evaluation_deserialize.h b/src/features_evaluation_deserialize.h deleted file mode 100644 index 04ddf657..00000000 --- a/src/features_evaluation_deserialize.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef _FEATURES_EVALUATION_DESERIALIZE_H -#define _FEATURES_EVALUATION_DESERIALIZE_H -#include "features_evaluation_internal.h" - -struct _ccs_features_evaluation_data_mock_s { - _ccs_binding_data_t base; - ccs_search_configuration_t configuration; - ccs_features_t features; - ccs_evaluation_result_t result; -}; -typedef struct _ccs_features_evaluation_data_mock_s - _ccs_features_evaluation_data_mock_t; - -static inline ccs_result_t -_ccs_deserialize_bin_ccs_features_evaluation_data( - _ccs_features_evaluation_data_mock_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_deserialize_bin_ccs_binding_data( - &data->base, version, buffer_size, buffer)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts( - (ccs_object_t *)&data->configuration, - CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, - opts)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( - (ccs_object_t *)&data->features, CCS_OBJECT_TYPE_FEATURES, - CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, - opts)); - CCS_VALIDATE(_ccs_deserialize_bin_ccs_evaluation_result( - &data->result, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_deserialize_bin_features_evaluation( - ccs_features_evaluation_t *features_evaluation_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_CHECK_OBJ(opts->handle_map, CCS_OBJECT_TYPE_MAP); - _ccs_object_deserialize_options_t new_opts = *opts; - _ccs_object_internal_t obj; - ccs_object_t handle; - ccs_datum_t d; - ccs_objective_space_t os; - ccs_result_t res = CCS_RESULT_SUCCESS; - CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( - &obj, buffer_size, buffer, &handle)); - CCS_REFUTE( - obj.type != CCS_OBJECT_TYPE_FEATURES_EVALUATION, - CCS_RESULT_ERROR_INVALID_TYPE); - - new_opts.map_values = CCS_FALSE; - _ccs_features_evaluation_data_mock_t data = { - {NULL, 0, NULL}, NULL, NULL, CCS_RESULT_SUCCESS}; - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_ccs_features_evaluation_data( - &data, version, buffer_size, buffer, &new_opts), - end); - - CCS_VALIDATE_ERR_GOTO( - res, - ccs_map_get(opts->handle_map, ccs_object(data.base.context), &d), - end); - CCS_REFUTE_ERR_GOTO( - res, d.type != CCS_DATA_TYPE_OBJECT, - CCS_RESULT_ERROR_INVALID_HANDLE, end); - os = (ccs_objective_space_t)(d.value.o); - - CCS_VALIDATE_ERR_GOTO( - res, - ccs_create_features_evaluation( - os, data.configuration, data.features, data.result, - data.base.num_values, data.base.values, - features_evaluation_ret), - end); - - if (opts->map_values) - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_object_handle_check_add( - opts->handle_map, handle, - (ccs_object_t)*features_evaluation_ret), - err_features_evaluation); - goto end; - -err_features_evaluation: - ccs_release_object(*features_evaluation_ret); - *features_evaluation_ret = NULL; -end: - if (data.configuration) - ccs_release_object(data.configuration); - if (data.features) - ccs_release_object(data.features); - if (data.base.values) - free(data.base.values); - return res; -} - -static ccs_result_t -_ccs_features_evaluation_deserialize( - ccs_features_evaluation_t *features_evaluation_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_deserialize_bin_features_evaluation( - features_evaluation_ret, version, buffer_size, buffer, - opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*features_evaluation_ret, format, version, - buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -#endif //_FEATURES_EVALUATION_DESERIALIZE_H diff --git a/src/features_evaluation_internal.h b/src/features_evaluation_internal.h deleted file mode 100644 index 8d020107..00000000 --- a/src/features_evaluation_internal.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _FEATURES_EVALUATION_INTERNAL_H -#define _FEATURES_EVALUATION_INTERNAL_H -#include "binding_internal.h" - -struct _ccs_features_evaluation_data_s; -typedef struct _ccs_features_evaluation_data_s _ccs_features_evaluation_data_t; - -struct _ccs_features_evaluation_ops_s { - _ccs_object_ops_t obj_ops; - - ccs_result_t (*hash)( - ccs_features_evaluation_t features_evaluation, - ccs_hash_t *hash_ret); - - ccs_result_t (*cmp)( - ccs_features_evaluation_t features_evaluation, - ccs_features_evaluation_t other, - int *cmp_ret); - - ccs_result_t (*compare)( - ccs_features_evaluation_t evaluation, - ccs_features_evaluation_t other_evaluation, - ccs_comparison_t *result_ret); -}; -typedef struct _ccs_features_evaluation_ops_s _ccs_features_evaluation_ops_t; - -struct _ccs_features_evaluation_s { - _ccs_object_internal_t obj; - _ccs_features_evaluation_data_t *data; -}; - -struct _ccs_features_evaluation_data_s { - ccs_objective_space_t objective_space; - size_t num_values; - ccs_datum_t *values; - ccs_evaluation_result_t result; - ccs_search_configuration_t configuration; - ccs_features_t features; -}; - -#endif //_FEATURES_EVALUATION_INTERNAL_H diff --git a/src/features_internal.h b/src/features_internal.h index d37ddda2..1fc3820f 100644 --- a/src/features_internal.h +++ b/src/features_internal.h @@ -28,4 +28,11 @@ struct _ccs_features_data_s { ccs_datum_t *values; }; +ccs_result_t +_ccs_create_features( + ccs_feature_space_t features_space, + size_t num_values, + ccs_datum_t *values, + ccs_features_t *features_ret); + #endif //_FEATURES_INTERNAL_H diff --git a/src/features_tuner.c b/src/features_tuner.c index cde75632..4106099e 100644 --- a/src/features_tuner.c +++ b/src/features_tuner.c @@ -106,9 +106,9 @@ ccs_features_tuner_ask( ccs_result_t ccs_features_tuner_tell( - ccs_features_tuner_t tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations) + ccs_features_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); CCS_CHECK_ARY(num_evaluations, evaluations); @@ -125,11 +125,11 @@ ccs_features_tuner_tell( ccs_result_t ccs_features_tuner_get_optima( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); if (features) @@ -154,11 +154,11 @@ ccs_features_tuner_get_optima( ccs_result_t ccs_features_tuner_get_history( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); if (features) diff --git a/src/features_tuner_deserialize.h b/src/features_tuner_deserialize.h index 20631863..236e510a 100644 --- a/src/features_tuner_deserialize.h +++ b/src/features_tuner_deserialize.h @@ -6,8 +6,8 @@ struct _ccs_random_features_tuner_data_mock_s { _ccs_features_tuner_common_data_t common_data; size_t size_history; size_t size_optima; - ccs_features_evaluation_t *history; - ccs_features_evaluation_t *optima; + ccs_evaluation_t *history; + ccs_evaluation_t *optima; }; typedef struct _ccs_random_features_tuner_data_mock_s _ccs_random_features_tuner_data_mock_t; @@ -28,10 +28,6 @@ _ccs_deserialize_bin_ccs_features_tuner_common_data( (ccs_object_t *)&data->objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, opts)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( - (ccs_object_t *)&data->feature_space, - CCS_OBJECT_TYPE_FEATURE_SPACE, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } @@ -56,19 +52,18 @@ _ccs_deserialize_bin_ccs_random_features_tuner_data( return CCS_RESULT_SUCCESS; mem = (uintptr_t)calloc( (data->size_history + data->size_optima), - sizeof(ccs_features_evaluation_t)); + sizeof(ccs_evaluation_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - data->history = (ccs_features_evaluation_t *)mem; - mem += data->size_history * sizeof(ccs_features_evaluation_t); - data->optima = (ccs_features_evaluation_t *)mem; + data->history = (ccs_evaluation_t *)mem; + mem += data->size_history * sizeof(ccs_evaluation_t); + data->optima = (ccs_evaluation_t *)mem; for (size_t i = 0; i < data->size_history; i++) CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( (ccs_object_t *)data->history + i, - CCS_OBJECT_TYPE_FEATURES_EVALUATION, - CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, - buffer, opts)); + CCS_OBJECT_TYPE_EVALUATION, CCS_SERIALIZE_FORMAT_BINARY, + version, buffer_size, buffer, opts)); for (size_t i = 0; i < data->size_optima; i++) CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( @@ -80,7 +75,7 @@ _ccs_deserialize_bin_ccs_random_features_tuner_data( CCS_REFUTE( d.type != CCS_DATA_TYPE_OBJECT, CCS_RESULT_ERROR_INVALID_HANDLE); - data->optima[i] = (ccs_features_evaluation_t)(d.value.o); + data->optima[i] = (ccs_evaluation_t)(d.value.o); } return CCS_RESULT_SUCCESS; } @@ -126,9 +121,9 @@ _ccs_deserialize_bin_random_features_tuner( CCS_VALIDATE_ERR_GOTO( res, ccs_create_random_features_tuner( - data.common_data.name, data.common_data.feature_space, - data.common_data.objective_space, features_tuner_ret), - features_evaluations); + data.common_data.name, data.common_data.objective_space, + features_tuner_ret), + evaluations); odata = (_ccs_random_features_tuner_data_clone_t *)((*features_tuner_ret)->data); for (size_t i = 0; i < data.size_history; i++) @@ -139,14 +134,12 @@ _ccs_deserialize_bin_random_features_tuner( features_tuner: ccs_release_object(*features_tuner_ret); *features_tuner_ret = NULL; -features_evaluations: +evaluations: for (size_t i = 0; i < data.size_history; i++) ccs_release_object(data.history[i]); end: if (data.common_data.objective_space) ccs_release_object(data.common_data.objective_space); - if (data.common_data.feature_space) - ccs_release_object(data.common_data.feature_space); if (data.history) free(data.history); return res; @@ -203,7 +196,6 @@ _ccs_deserialize_bin_user_defined_features_tuner( res, ccs_create_user_defined_features_tuner( data.base_data.common_data.name, - data.base_data.common_data.feature_space, data.base_data.common_data.objective_space, vector, opts->data, features_tuner_ret), evaluations); @@ -236,8 +228,6 @@ _ccs_deserialize_bin_user_defined_features_tuner( end: if (data.base_data.common_data.objective_space) ccs_release_object(data.base_data.common_data.objective_space); - if (data.base_data.common_data.feature_space) - ccs_release_object(data.base_data.common_data.feature_space); if (data.base_data.history) free(data.base_data.history); return res; diff --git a/src/features_tuner_internal.h b/src/features_tuner_internal.h index 9157fa9f..66127eee 100644 --- a/src/features_tuner_internal.h +++ b/src/features_tuner_internal.h @@ -19,23 +19,23 @@ struct _ccs_features_tuner_ops_s { size_t *num_configurations_ret); ccs_result_t (*tell)( - ccs_features_tuner_t tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations); + ccs_features_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations); ccs_result_t (*get_optima)( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); ccs_result_t (*get_history)( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret); + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret); ccs_result_t (*suggest)( ccs_features_tuner_t tuner, @@ -71,9 +71,6 @@ _ccs_serialize_bin_size_ccs_features_tuner_common_data( CCS_VALIDATE(data->objective_space->obj.ops->serialize_size( data->objective_space, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); - CCS_VALIDATE(data->feature_space->obj.ops->serialize_size( - data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, cum_size, - opts)); return CCS_RESULT_SUCCESS; } @@ -91,9 +88,6 @@ _ccs_serialize_bin_ccs_features_tuner_common_data( CCS_VALIDATE(data->objective_space->obj.ops->serialize( data->objective_space, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); - CCS_VALIDATE(data->feature_space->obj.ops->serialize( - data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/features_tuner_random.c b/src/features_tuner_random.c index 25839d74..8316d238 100644 --- a/src/features_tuner_random.c +++ b/src/features_tuner_random.c @@ -1,6 +1,7 @@ #include "cconfigspace_internal.h" #include "features_tuner_internal.h" -#include "features_evaluation_internal.h" +#include "evaluation_internal.h" +#include "search_space_internal.h" #include "utarray.h" @@ -21,9 +22,10 @@ _ccs_features_tuner_random_del(ccs_object_t o) ->data; ccs_release_object(d->common_data.search_space); ccs_release_object(d->common_data.objective_space); - ccs_release_object(d->common_data.feature_space); - ccs_features_evaluation_t *e = NULL; - while ((e = (ccs_features_evaluation_t *)utarray_next(d->history, e))) { + if (d->common_data.feature_space) + ccs_release_object(d->common_data.feature_space); + ccs_evaluation_t *e = NULL; + while ((e = (ccs_evaluation_t *)utarray_next(d->history, e))) { ccs_release_object(*e); } utarray_free(d->history); @@ -38,16 +40,16 @@ _ccs_serialize_bin_size_ccs_random_features_tuner_data( size_t *cum_size, _ccs_object_serialize_options_t *opts) { - ccs_features_evaluation_t *e = NULL; + ccs_evaluation_t *e = NULL; CCS_VALIDATE(_ccs_serialize_bin_size_ccs_features_tuner_common_data( &data->common_data, cum_size, opts)); *cum_size += _ccs_serialize_bin_size_size(utarray_len(data->history)); *cum_size += _ccs_serialize_bin_size_size(utarray_len(data->optima)); - while ((e = (ccs_features_evaluation_t *)utarray_next(data->history, e))) + while ((e = (ccs_evaluation_t *)utarray_next(data->history, e))) CCS_VALIDATE((*e)->obj.ops->serialize_size( *e, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); e = NULL; - while ((e = (ccs_features_evaluation_t *)utarray_next(data->optima, e))) + while ((e = (ccs_evaluation_t *)utarray_next(data->optima, e))) *cum_size += _ccs_serialize_bin_size_ccs_object(*e); return CCS_RESULT_SUCCESS; } @@ -59,19 +61,19 @@ _ccs_serialize_bin_ccs_random_features_tuner_data( char **buffer, _ccs_object_serialize_options_t *opts) { - ccs_features_evaluation_t *e = NULL; + ccs_evaluation_t *e = NULL; CCS_VALIDATE(_ccs_serialize_bin_ccs_features_tuner_common_data( &data->common_data, buffer_size, buffer, opts)); CCS_VALIDATE(_ccs_serialize_bin_size( utarray_len(data->history), buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_size( utarray_len(data->optima), buffer_size, buffer)); - while ((e = (ccs_features_evaluation_t *)utarray_next(data->history, e))) + while ((e = (ccs_evaluation_t *)utarray_next(data->history, e))) CCS_VALIDATE((*e)->obj.ops->serialize( *e, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); e = NULL; - while ((e = (ccs_features_evaluation_t *)utarray_next(data->optima, e))) + while ((e = (ccs_evaluation_t *)utarray_next(data->optima, e))) CCS_VALIDATE( _ccs_serialize_bin_ccs_object(*e, buffer_size, buffer)); return CCS_RESULT_SUCCESS; @@ -172,12 +174,12 @@ _ccs_features_tuner_random_ask( ccs_search_space_t search_space = d->common_data.search_space; if (CCS_OBJ_TYPE(search_space) == CCS_OBJECT_TYPE_CONFIGURATION_SPACE) CCS_VALIDATE(ccs_configuration_space_samples( - (ccs_configuration_space_t)search_space, NULL, NULL, - num_configurations, + (ccs_configuration_space_t)search_space, NULL, features, + NULL, num_configurations, (ccs_configuration_t *)configurations)); else CCS_VALIDATE(ccs_tree_space_samples( - (ccs_tree_space_t)search_space, NULL, + (ccs_tree_space_t)search_space, features, NULL, num_configurations, (ccs_tree_configuration_t *)configurations)); if (num_configurations_ret) @@ -194,9 +196,9 @@ _ccs_features_tuner_random_ask( } static ccs_result_t _ccs_features_tuner_random_tell( - ccs_features_tuner_t tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations) + ccs_features_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations) { _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)tuner->data; @@ -215,7 +217,7 @@ _ccs_features_tuner_random_tell( d->old_optima = d->optima; d->optima = tmp; utarray_clear(d->optima); - ccs_features_evaluation_t *eval = NULL; + ccs_evaluation_t *eval = NULL; #undef utarray_oom #define utarray_oom() \ { \ @@ -224,8 +226,8 @@ _ccs_features_tuner_random_tell( CCS_RESULT_ERROR_OUT_OF_MEMORY, \ "Not enough memory to allocate new array"); \ } - while ((eval = (ccs_features_evaluation_t *) - utarray_next(d->old_optima, eval))) { + while ((eval = (ccs_evaluation_t *)utarray_next( + d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; err = ccs_evaluation_compare( @@ -264,11 +266,11 @@ _ccs_features_tuner_random_tell( static ccs_result_t _ccs_features_tuner_random_get_optima( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)tuner->data; @@ -279,23 +281,22 @@ _ccs_features_tuner_random_get_optima( CCS_REFUTE( num_evaluations < num_optima, CCS_RESULT_ERROR_INVALID_VALUE); - ccs_features_evaluation_t *eval = NULL; - size_t index = 0; - while ((eval = (ccs_features_evaluation_t *) - utarray_next(d->optima, eval))) + ccs_evaluation_t *eval = NULL; + size_t index = 0; + while ((eval = (ccs_evaluation_t *)utarray_next( + d->optima, eval))) evaluations[index++] = *eval; for (size_t i = num_optima; i < num_evaluations; i++) evaluations[i] = NULL; } } else { - ccs_features_evaluation_t *eval = NULL; - size_t index = 0; - ccs_features_t feat; - int cmp; - while ((eval = (ccs_features_evaluation_t *)utarray_next( + ccs_evaluation_t *eval = NULL; + size_t index = 0; + ccs_features_t feat; + int cmp; + while ((eval = (ccs_evaluation_t *)utarray_next( d->optima, eval))) { - CCS_VALIDATE(ccs_features_evaluation_get_features( - *eval, &feat)); + CCS_VALIDATE(ccs_evaluation_get_features(*eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); @@ -307,11 +308,10 @@ _ccs_features_tuner_random_get_optima( num_evaluations < num_optima, CCS_RESULT_ERROR_INVALID_VALUE); eval = NULL; - while ((eval = (ccs_features_evaluation_t *) - utarray_next(d->optima, eval))) { - CCS_VALIDATE( - ccs_features_evaluation_get_features( - *eval, &feat)); + while ((eval = (ccs_evaluation_t *)utarray_next( + d->optima, eval))) { + CCS_VALIDATE(ccs_evaluation_get_features( + *eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); @@ -329,11 +329,11 @@ _ccs_features_tuner_random_get_optima( static ccs_result_t _ccs_features_tuner_random_get_history( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)tuner->data; @@ -344,23 +344,22 @@ _ccs_features_tuner_random_get_history( CCS_REFUTE( num_evaluations < size_history, CCS_RESULT_ERROR_INVALID_VALUE); - ccs_features_evaluation_t *eval = NULL; - size_t index = 0; - while ((eval = (ccs_features_evaluation_t *) - utarray_next(d->history, eval))) + ccs_evaluation_t *eval = NULL; + size_t index = 0; + while ((eval = (ccs_evaluation_t *)utarray_next( + d->history, eval))) evaluations[index++] = *eval; for (size_t i = size_history; i < num_evaluations; i++) evaluations[i] = NULL; } } else { - ccs_features_evaluation_t *eval = NULL; - ccs_features_t feat; - int cmp; - size_t index = 0; - while ((eval = (ccs_features_evaluation_t *)utarray_next( + ccs_evaluation_t *eval = NULL; + ccs_features_t feat; + int cmp; + size_t index = 0; + while ((eval = (ccs_evaluation_t *)utarray_next( d->history, eval))) { - CCS_VALIDATE(ccs_features_evaluation_get_features( - *eval, &feat)); + CCS_VALIDATE(ccs_evaluation_get_features(*eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); @@ -372,11 +371,10 @@ _ccs_features_tuner_random_get_history( num_evaluations < size_history, CCS_RESULT_ERROR_INVALID_VALUE); eval = NULL; - while ((eval = (ccs_features_evaluation_t *) - utarray_next(d->history, eval))) { - CCS_VALIDATE( - ccs_features_evaluation_get_features( - *eval, &feat)); + while ((eval = (ccs_evaluation_t *)utarray_next( + d->history, eval))) { + CCS_VALIDATE(ccs_evaluation_get_features( + *eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); @@ -400,14 +398,12 @@ _ccs_features_tuner_random_suggest( { _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)tuner->data; - size_t count = 0; - ccs_features_evaluation_t *eval = NULL; - ccs_features_t feat; - int cmp; - while ((eval = (ccs_features_evaluation_t *)utarray_next( - d->optima, eval))) { - CCS_VALIDATE( - ccs_features_evaluation_get_features(*eval, &feat)); + size_t count = 0; + ccs_evaluation_t *eval = NULL; + ccs_features_t feat; + int cmp; + while ((eval = (ccs_evaluation_t *)utarray_next(d->optima, eval))) { + CCS_VALIDATE(ccs_evaluation_get_features(*eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); if (cmp == 0) @@ -429,10 +425,9 @@ _ccs_features_tuner_random_suggest( &rng)); CCS_VALIDATE(ccs_rng_get(rng, &indx)); indx = indx % count; - while ((eval = (ccs_features_evaluation_t *)utarray_next( + while ((eval = (ccs_evaluation_t *)utarray_next( d->optima, eval))) { - CCS_VALIDATE(ccs_features_evaluation_get_features( - *eval, &feat)); + CCS_VALIDATE(ccs_evaluation_get_features(*eval, &feat)); CCS_VALIDATE(ccs_binding_cmp( (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); @@ -463,7 +458,7 @@ static _ccs_features_tuner_ops_t _ccs_features_tuner_random_ops = { &_ccs_features_tuner_random_suggest}; static const UT_icd _evaluation_icd = { - sizeof(ccs_features_evaluation_t), + sizeof(ccs_evaluation_t), NULL, NULL, NULL, @@ -479,16 +474,17 @@ static const UT_icd _evaluation_icd = { ccs_result_t ccs_create_random_features_tuner( const char *name, - ccs_feature_space_t feature_space, ccs_objective_space_t objective_space, ccs_features_tuner_t *tuner_ret) { - ccs_search_space_t search_space; + ccs_search_space_t search_space; + ccs_feature_space_t feature_space; CCS_CHECK_PTR(name); - CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( objective_space, &search_space)); + CCS_VALIDATE(_ccs_search_space_get_feature_space( + search_space, &feature_space)); CCS_CHECK_PTR(tuner_ret); uintptr_t mem = (uintptr_t)calloc( @@ -502,7 +498,9 @@ ccs_create_random_features_tuner( CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), erros); + if (feature_space) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(feature_space), erros); tun = (ccs_features_tuner_t)mem; _ccs_object_init( diff --git a/src/features_tuner_user_defined.c b/src/features_tuner_user_defined.c index 771b24db..950276e2 100644 --- a/src/features_tuner_user_defined.c +++ b/src/features_tuner_user_defined.c @@ -1,6 +1,7 @@ #include "cconfigspace_internal.h" #include "features_tuner_internal.h" -#include "features_evaluation_internal.h" +#include "evaluation_internal.h" +#include "search_space_internal.h" #include "string.h" struct _ccs_user_defined_features_tuner_data_s { @@ -40,11 +41,11 @@ _ccs_serialize_bin_size_ccs_user_defined_features_tuner( (_ccs_object_internal_t *)features_tuner); CCS_VALIDATE(_ccs_serialize_bin_size_ccs_features_tuner_common_data( &data->common_data, cum_size, opts)); - size_t history_size = 0; - size_t num_optima = 0; - size_t state_size = 0; - ccs_features_evaluation_t *history = NULL; - ccs_features_evaluation_t *optima = NULL; + size_t history_size = 0; + size_t num_optima = 0; + size_t state_size = 0; + ccs_evaluation_t *history = NULL; + ccs_evaluation_t *optima = NULL; CCS_VALIDATE(data->vector.get_history( features_tuner, NULL, 0, NULL, &history_size)); CCS_VALIDATE(data->vector.get_optima( @@ -52,9 +53,8 @@ _ccs_serialize_bin_size_ccs_user_defined_features_tuner( *cum_size += _ccs_serialize_bin_size_size(history_size); *cum_size += _ccs_serialize_bin_size_size(num_optima); if (0 != history_size + num_optima) { - history = (ccs_features_evaluation_t *)calloc( - sizeof(ccs_features_evaluation_t), - history_size + num_optima); + history = (ccs_evaluation_t *)calloc( + sizeof(ccs_evaluation_t), history_size + num_optima); CCS_REFUTE(!history, CCS_RESULT_ERROR_OUT_OF_MEMORY); optima = history + history_size; if (history_size) { @@ -114,11 +114,11 @@ _ccs_serialize_bin_ccs_user_defined_features_tuner( (_ccs_object_internal_t *)features_tuner, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_ccs_features_tuner_common_data( &data->common_data, buffer_size, buffer, opts)); - size_t history_size = 0; - size_t num_optima = 0; - size_t state_size = 0; - ccs_features_evaluation_t *history = NULL; - ccs_features_evaluation_t *optima = NULL; + size_t history_size = 0; + size_t num_optima = 0; + size_t state_size = 0; + ccs_evaluation_t *history = NULL; + ccs_evaluation_t *optima = NULL; CCS_VALIDATE(data->vector.get_history( features_tuner, NULL, 0, NULL, &history_size)); CCS_VALIDATE(data->vector.get_optima( @@ -127,9 +127,8 @@ _ccs_serialize_bin_ccs_user_defined_features_tuner( _ccs_serialize_bin_size(history_size, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_size(num_optima, buffer_size, buffer)); if (0 != history_size + num_optima) { - history = (ccs_features_evaluation_t *)calloc( - sizeof(ccs_features_evaluation_t), - history_size + num_optima); + history = (ccs_evaluation_t *)calloc( + sizeof(ccs_evaluation_t), history_size + num_optima); CCS_REFUTE(!history, CCS_RESULT_ERROR_OUT_OF_MEMORY); optima = history + history_size; if (history_size) { @@ -255,9 +254,9 @@ _ccs_features_tuner_user_defined_ask( static ccs_result_t _ccs_features_tuner_user_defined_tell( - ccs_features_tuner_t tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations) + ccs_features_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations) { _ccs_user_defined_features_tuner_data_t *d = (_ccs_user_defined_features_tuner_data_t *)tuner->data; @@ -267,11 +266,11 @@ _ccs_features_tuner_user_defined_tell( static ccs_result_t _ccs_features_tuner_user_defined_get_optima( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { _ccs_user_defined_features_tuner_data_t *d = (_ccs_user_defined_features_tuner_data_t *)tuner->data; @@ -283,11 +282,11 @@ _ccs_features_tuner_user_defined_get_optima( static ccs_result_t _ccs_features_tuner_user_defined_get_history( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { _ccs_user_defined_features_tuner_data_t *d = (_ccs_user_defined_features_tuner_data_t *)tuner->data; @@ -323,18 +322,19 @@ static _ccs_features_tuner_ops_t _ccs_features_tuner_user_defined_ops = { ccs_result_t ccs_create_user_defined_features_tuner( const char *name, - ccs_feature_space_t feature_space, ccs_objective_space_t objective_space, ccs_user_defined_features_tuner_vector_t *vector, void *tuner_data, ccs_features_tuner_t *tuner_ret) { - ccs_search_space_t search_space; + ccs_search_space_t search_space; + ccs_feature_space_t feature_space; CCS_CHECK_PTR(name); - CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( objective_space, &search_space)); + CCS_VALIDATE(_ccs_search_space_get_feature_space( + search_space, &feature_space)); CCS_CHECK_PTR(tuner_ret); CCS_CHECK_PTR(vector); CCS_CHECK_PTR(vector->del); @@ -355,7 +355,9 @@ ccs_create_user_defined_features_tuner( CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), erros); + if (feature_space) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(feature_space), erros); tun = (ccs_features_tuner_t)mem; _ccs_object_init( diff --git a/src/objective_space.c b/src/objective_space.c index f5865101..9801c8c3 100644 --- a/src/objective_space.c +++ b/src/objective_space.c @@ -39,14 +39,17 @@ _ccs_serialize_bin_size_ccs_objective_space_data( size_t *cum_size, _ccs_object_serialize_options_t *opts) { - ccs_search_space_t search_space = data->search_space; - size_t num_parameters = data->num_parameters; - ccs_parameter_t *parameters = data->parameters; - size_t num_objectives = data->num_objectives; - _ccs_objective_t *objectives = data->objectives; + ccs_feature_space_t feature_space = data->feature_space; + ccs_search_space_t search_space = data->search_space; + size_t num_parameters = data->num_parameters; + ccs_parameter_t *parameters = data->parameters; + size_t num_objectives = data->num_objectives; + _ccs_objective_t *objectives = data->objectives; *cum_size += _ccs_serialize_bin_size_string(data->name); + *cum_size += _ccs_serialize_bin_size_ccs_object(feature_space); + *cum_size += _ccs_serialize_bin_size_ccs_object(search_space); CCS_VALIDATE(search_space->obj.ops->serialize_size( search_space, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); @@ -78,15 +81,20 @@ _ccs_serialize_bin_ccs_objective_space_data( char **buffer, _ccs_object_serialize_options_t *opts) { - ccs_search_space_t search_space = data->search_space; - size_t num_parameters = data->num_parameters; - ccs_parameter_t *parameters = data->parameters; - size_t num_objectives = data->num_objectives; - _ccs_objective_t *objectives = data->objectives; + ccs_feature_space_t feature_space = data->feature_space; + ccs_search_space_t search_space = data->search_space; + size_t num_parameters = data->num_parameters; + ccs_parameter_t *parameters = data->parameters; + size_t num_objectives = data->num_objectives; + _ccs_objective_t *objectives = data->objectives; CCS_VALIDATE( _ccs_serialize_bin_string(data->name, buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_object( + feature_space, buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_object( + search_space, buffer_size, buffer)); CCS_VALIDATE(search_space->obj.ops->serialize( search_space, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); @@ -284,7 +292,12 @@ ccs_create_objective_space( errparams); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errparams); obj_space->data->search_space = search_space; - *objective_space_ret = obj_space; + CCS_VALIDATE_ERR_GOTO( + err, + _ccs_search_space_get_feature_space( + search_space, &obj_space->data->feature_space), + errparams); + *objective_space_ret = obj_space; return CCS_RESULT_SUCCESS; errparams: _ccs_objective_space_del(obj_space); @@ -331,7 +344,7 @@ ccs_objective_space_check_evaluation( ccs_bool_t *is_valid_ret) { CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); CCS_REFUTE( evaluation->data->objective_space != objective_space, CCS_RESULT_ERROR_INVALID_EVALUATION); diff --git a/src/objective_space_deserialize.h b/src/objective_space_deserialize.h index 5a84819a..81492a04 100644 --- a/src/objective_space_deserialize.h +++ b/src/objective_space_deserialize.h @@ -4,6 +4,7 @@ struct _ccs_objective_space_data_mock_s { const char *name; + ccs_object_t feature_space_handle; ccs_object_t search_space_handle; ccs_search_space_t search_space; size_t num_parameters; @@ -22,13 +23,15 @@ _ccs_deserialize_bin_ccs_objective_space_data( const char **buffer, _ccs_object_deserialize_options_t *opts) { - uintptr_t mem; - _ccs_object_internal_t obj; + uintptr_t mem; CCS_VALIDATE( _ccs_deserialize_bin_string(&data->name, buffer_size, buffer)); - CCS_VALIDATE(_ccs_peek_bin_ccs_object_internal( - &obj, buffer_size, buffer, &data->search_space_handle)); + + CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( + &data->feature_space_handle, buffer_size, buffer)); + CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( + &data->search_space_handle, buffer_size, buffer)); CCS_VALIDATE(_ccs_object_deserialize_with_opts( (ccs_object_t *)&data->search_space, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, @@ -81,6 +84,7 @@ _ccs_deserialize_bin_objective_space( _ccs_object_deserialize_options_t new_opts = *opts; _ccs_object_internal_t obj; ccs_object_t handle; + ccs_datum_t datum; ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( &obj, buffer_size, buffer, &handle)); @@ -91,7 +95,7 @@ _ccs_deserialize_bin_objective_space( new_opts.map_values = CCS_TRUE; CCS_VALIDATE(ccs_create_map(&new_opts.handle_map)); - _ccs_objective_space_data_mock_t data = {NULL, NULL, NULL, 0, + _ccs_objective_space_data_mock_t data = {NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL}; CCS_VALIDATE_ERR_GOTO( res, @@ -105,7 +109,31 @@ _ccs_deserialize_bin_objective_space( data.parameters, data.num_objectives, data.objectives, data.objective_types, objective_space_ret), end); + if (opts && opts->map_values && opts->handle_map) { + if (data.feature_space_handle) { + CCS_VALIDATE_ERR_GOTO( + res, + ccs_map_get( + new_opts.handle_map, + ccs_object(data.feature_space_handle), + &datum), + err_objective_space); + CCS_REFUTE_ERR_GOTO( + res, + datum.type != CCS_DATA_TYPE_OBJECT || + CCS_OBJ_TYPE(datum.value.o) != + CCS_OBJECT_TYPE_FEATURE_SPACE, + CCS_RESULT_ERROR_INVALID_TYPE, + err_objective_space); + CCS_VALIDATE_ERR_GOTO( + res, + _ccs_object_handle_check_add( + opts->handle_map, + data.feature_space_handle, + datum.value.o), + err_objective_space); + } CCS_VALIDATE_ERR_GOTO( res, _ccs_object_handle_check_add( diff --git a/src/objective_space_internal.h b/src/objective_space_internal.h index ed7c44d3..b718798c 100644 --- a/src/objective_space_internal.h +++ b/src/objective_space_internal.h @@ -32,6 +32,7 @@ struct _ccs_objective_space_data_s { size_t num_objectives; _ccs_objective_t *objectives; ccs_search_space_t search_space; + ccs_feature_space_t feature_space; }; #endif //_OBJECTIVE_SPACE_INTERNAL_H diff --git a/src/search_configuration_internal.h b/src/search_configuration_internal.h index 3e3af95e..8070a535 100644 --- a/src/search_configuration_internal.h +++ b/src/search_configuration_internal.h @@ -1,5 +1,7 @@ #ifndef _SEARCH_CONFIGURATION_INTERNAL_H #define _SEARCH_CONFIGURATION_INTERNAL_H +#include "configuration_internal.h" +#include "tree_configuration_internal.h" struct _ccs_search_configuration_data_s; typedef struct _ccs_search_configuration_data_s _ccs_search_configuration_data_t; @@ -50,4 +52,28 @@ _ccs_search_configuration_cmp( return CCS_RESULT_SUCCESS; } +static inline ccs_result_t +_ccs_search_configuration_get_features( + ccs_search_configuration_t configuration, + ccs_features_t *features_ret) +{ + switch (CCS_OBJ_TYPE(configuration)) { + case CCS_OBJECT_TYPE_CONFIGURATION: { + ccs_configuration_t config = (ccs_configuration_t)configuration; + *features_ret = config->data->features; + } break; + case CCS_OBJECT_TYPE_TREE_CONFIGURATION: { + ccs_tree_configuration_t config = + (ccs_tree_configuration_t)configuration; + *features_ret = config->data->features; + } break; + default: + CCS_RAISE( + CCS_RESULT_ERROR_INVALID_OBJECT, + "Unsupported object type: %d", + CCS_OBJ_TYPE(configuration)); + } + return CCS_RESULT_SUCCESS; +} + #endif //_SEARCH_CONFIGURATION_INTERNAL_H diff --git a/src/search_space_internal.h b/src/search_space_internal.h index 9aba11fe..930b72e3 100644 --- a/src/search_space_internal.h +++ b/src/search_space_internal.h @@ -1,5 +1,7 @@ #ifndef _SEARCH_SPACE_INTERNAL_H #define _SEARCH_SPACE_INTERNAL_H +#include "configuration_space_internal.h" +#include "tree_space_internal.h" struct _ccs_search_space_data_s; typedef struct _ccs_search_space_data_s _ccs_search_space_data_t; @@ -9,4 +11,29 @@ struct _ccs_search_space_s { _ccs_search_space_data_t *data; }; +static inline ccs_result_t +_ccs_search_space_get_feature_space( + ccs_search_space_t search_space, + ccs_feature_space_t *feature_space_ret) +{ + switch (CCS_OBJ_TYPE(search_space)) { + case CCS_OBJECT_TYPE_TREE_SPACE: { + ccs_tree_space_t tree_space = (ccs_tree_space_t)search_space; + *feature_space_ret = + ((_ccs_tree_space_common_data_t *)(tree_space->data)) + ->feature_space; + } break; + case CCS_OBJECT_TYPE_CONFIGURATION_SPACE: { + ccs_configuration_space_t configuration_space = + (ccs_configuration_space_t)search_space; + *feature_space_ret = configuration_space->data->feature_space; + } break; + default: + CCS_RAISE( + CCS_RESULT_ERROR_INVALID_OBJECT, + "Unsupported object type: %d", + CCS_OBJ_TYPE(search_space)); + } + return CCS_RESULT_SUCCESS; +} #endif //_SEARCH_SPACE_INTERNAL_H diff --git a/src/tree_configuration.c b/src/tree_configuration.c index c642826c..7055c299 100644 --- a/src/tree_configuration.c +++ b/src/tree_configuration.c @@ -1,5 +1,7 @@ #include "cconfigspace_internal.h" #include "tree_configuration_internal.h" +#include "tree_space_internal.h" +#include "features_internal.h" #include static ccs_result_t @@ -7,26 +9,37 @@ _ccs_tree_configuration_del(ccs_object_t object) { ccs_tree_configuration_t tree_configuration = (ccs_tree_configuration_t)object; - ccs_release_object(tree_configuration->data->tree_space); + if (tree_configuration->data->tree_space) + ccs_release_object(tree_configuration->data->tree_space); + if (tree_configuration->data->features) + ccs_release_object(tree_configuration->data->features); return CCS_RESULT_SUCCESS; } -static inline size_t +static inline ccs_result_t _ccs_serialize_bin_size_ccs_tree_configuration_data( - _ccs_tree_configuration_data_t *data) + _ccs_tree_configuration_data_t *data, + size_t *cum_size, + _ccs_object_serialize_options_t *opts) { - size_t sz = _ccs_serialize_bin_size_ccs_object(data->tree_space) + - _ccs_serialize_bin_size_size(data->position_size); + *cum_size += _ccs_serialize_bin_size_ccs_object(data->tree_space) + + _ccs_serialize_bin_size_size(data->position_size); for (size_t i = 0; i < data->position_size; i++) - sz += _ccs_serialize_bin_size_size(data->position[i]); - return sz; + *cum_size += _ccs_serialize_bin_size_size(data->position[i]); + *cum_size += _ccs_serialize_bin_size_ccs_bool(data->features != NULL); + if (data->features) + CCS_VALIDATE(data->features->obj.ops->serialize_size( + data->features, CCS_SERIALIZE_FORMAT_BINARY, cum_size, + opts)); + return CCS_RESULT_SUCCESS; } static inline ccs_result_t _ccs_serialize_bin_ccs_tree_configuration_data( - _ccs_tree_configuration_data_t *data, - size_t *buffer_size, - char **buffer) + _ccs_tree_configuration_data_t *data, + size_t *buffer_size, + char **buffer, + _ccs_object_serialize_options_t *opts) { CCS_VALIDATE(_ccs_serialize_bin_ccs_object( data->tree_space, buffer_size, buffer)); @@ -35,32 +48,40 @@ _ccs_serialize_bin_ccs_tree_configuration_data( for (size_t i = 0; i < data->position_size; i++) CCS_VALIDATE(_ccs_serialize_bin_size( data->position[i], buffer_size, buffer)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_bool( + data->features != NULL, buffer_size, buffer)); + if (data->features) + CCS_VALIDATE(data->features->obj.ops->serialize( + data->features, CCS_SERIALIZE_FORMAT_BINARY, + buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } static inline ccs_result_t _ccs_serialize_bin_size_ccs_tree_configuration( - ccs_tree_configuration_t tree_configuration, - size_t *cum_size) + ccs_tree_configuration_t tree_configuration, + size_t *cum_size, + _ccs_object_serialize_options_t *opts) { *cum_size += _ccs_serialize_bin_size_ccs_object_internal( (_ccs_object_internal_t *)tree_configuration); - *cum_size += _ccs_serialize_bin_size_ccs_tree_configuration_data( - tree_configuration->data); + CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_configuration_data( + tree_configuration->data, cum_size, opts)); return CCS_RESULT_SUCCESS; } static inline ccs_result_t _ccs_serialize_bin_ccs_tree_configuration( - ccs_tree_configuration_t tree_configuration, - size_t *buffer_size, - char **buffer) + ccs_tree_configuration_t tree_configuration, + size_t *buffer_size, + char **buffer, + _ccs_object_serialize_options_t *opts) { CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( (_ccs_object_internal_t *)tree_configuration, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_configuration_data( - tree_configuration->data, buffer_size, buffer)); + tree_configuration->data, buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } @@ -74,7 +95,7 @@ _ccs_tree_configuration_serialize_size( switch (format) { case CCS_SERIALIZE_FORMAT_BINARY: CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_configuration( - (ccs_tree_configuration_t)object, cum_size)); + (ccs_tree_configuration_t)object, cum_size, opts)); break; default: CCS_RAISE( @@ -97,7 +118,8 @@ _ccs_tree_configuration_serialize( switch (format) { case CCS_SERIALIZE_FORMAT_BINARY: CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_configuration( - (ccs_tree_configuration_t)object, buffer_size, buffer)); + (ccs_tree_configuration_t)object, buffer_size, buffer, + opts)); break; default: CCS_RAISE( @@ -129,11 +151,20 @@ static _ccs_tree_configuration_ops_t _tree_configuration_ops = { ccs_result_t ccs_create_tree_configuration( ccs_tree_space_t tree_space, + ccs_features_t features, size_t position_size, const size_t *position, ccs_tree_configuration_t *configuration_ret) { CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + _ccs_tree_space_common_data_t *tsdata = + (_ccs_tree_space_common_data_t *)tree_space->data; + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != tsdata->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } CCS_CHECK_PTR(configuration_ret); CCS_CHECK_ARY(position_size, position); ccs_result_t err; @@ -142,25 +173,38 @@ ccs_create_tree_configuration( sizeof(struct _ccs_tree_configuration_data_s) + position_size * sizeof(size_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree_space), errmem); + uintptr_t mem_orig = mem; ccs_tree_configuration_t config; config = (ccs_tree_configuration_t)mem; + mem += sizeof(struct _ccs_tree_configuration_s); _ccs_object_init( &(config->obj), CCS_OBJECT_TYPE_TREE_CONFIGURATION, (_ccs_object_ops_t *)&_tree_configuration_ops); - config->data = - (struct _ccs_tree_configuration_data_s - *)(mem + sizeof(struct _ccs_tree_configuration_s)); - config->data->tree_space = tree_space; + config->data = (struct _ccs_tree_configuration_data_s *)mem; + mem += sizeof(struct _ccs_tree_configuration_data_s); config->data->position_size = position_size; - config->data->position = - (size_t *)(mem + sizeof(struct _ccs_tree_configuration_s) + sizeof(struct _ccs_tree_configuration_data_s)); + config->data->position = (size_t *)mem; + mem += sizeof(size_t) * position_size; + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree_space), errinit); + config->data->tree_space = tree_space; + if (features) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(features), errinit); + else if (tsdata->feature_space) + CCS_VALIDATE_ERR_GOTO( + err, + ccs_feature_space_get_default_features( + tsdata->feature_space, &features), + errinit); + config->data->features = features; memcpy(config->data->position, position, position_size * sizeof(size_t)); *configuration_ret = config; return CCS_RESULT_SUCCESS; -errmem: - free((void *)mem); +errinit: + _ccs_tree_configuration_del(config); + _ccs_object_deinit(&(config->obj)); + free((void *)mem_orig); return err; } @@ -175,6 +219,17 @@ ccs_tree_configuration_get_tree_space( return CCS_RESULT_SUCCESS; } +ccs_result_t +ccs_tree_configuration_get_feature( + ccs_tree_configuration_t configuration, + ccs_features_t *features_ret) +{ + CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); + CCS_CHECK_PTR(features_ret); + *features_ret = configuration->data->features; + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_tree_configuration_get_position( ccs_tree_configuration_t configuration, diff --git a/src/tree_configuration_deserialize.h b/src/tree_configuration_deserialize.h index a46e2806..d6bca5b1 100644 --- a/src/tree_configuration_deserialize.h +++ b/src/tree_configuration_deserialize.h @@ -3,14 +3,24 @@ #include "cconfigspace_internal.h" #include "tree_configuration_internal.h" +struct _ccs_tree_configuration_data_mock_s { + ccs_tree_space_t tree_space; + size_t position_size; + size_t *position; + ccs_bool_t features_present; + ccs_features_t features; +}; +typedef struct _ccs_tree_configuration_data_mock_s + _ccs_tree_configuration_data_mock_t; + static inline ccs_result_t _ccs_deserialize_bin_tree_configuration_data( - _ccs_tree_configuration_data_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer) + _ccs_tree_configuration_data_mock_t *data, + uint32_t version, + size_t *buffer_size, + const char **buffer, + _ccs_object_deserialize_options_t *opts) { - (void)version; CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( (ccs_object_t *)&data->tree_space, buffer_size, buffer)); CCS_VALIDATE(_ccs_deserialize_bin_size( @@ -23,6 +33,13 @@ _ccs_deserialize_bin_tree_configuration_data( CCS_VALIDATE(_ccs_deserialize_bin_size( data->position + i, buffer_size, buffer)); } + CCS_VALIDATE(_ccs_deserialize_bin_ccs_bool( + &data->features_present, buffer_size, buffer)); + if (data->features_present) + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)&data->features, + CCS_OBJECT_TYPE_FEATURES, CCS_SERIALIZE_FORMAT_BINARY, + version, buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } @@ -35,22 +52,26 @@ _ccs_deserialize_bin_tree_configuration( _ccs_object_deserialize_options_t *opts) { CCS_CHECK_OBJ(opts->handle_map, CCS_OBJECT_TYPE_MAP); - _ccs_object_internal_t obj; - ccs_object_t handle; - ccs_datum_t d; - ccs_tree_space_t tree_space; - ccs_tree_configuration_t configuration; + _ccs_object_deserialize_options_t new_opts = *opts; + _ccs_object_internal_t obj; + ccs_object_t handle; + ccs_datum_t d; + ccs_tree_space_t tree_space; + ccs_tree_configuration_t configuration; + ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( &obj, buffer_size, buffer, &handle)); CCS_REFUTE( obj.type != CCS_OBJECT_TYPE_TREE_CONFIGURATION, CCS_RESULT_ERROR_INVALID_TYPE); - _ccs_tree_configuration_data_t data = {NULL, 0, NULL}; - ccs_result_t res = CCS_RESULT_SUCCESS; + + new_opts.map_values = CCS_FALSE; + _ccs_tree_configuration_data_mock_t data = { + NULL, 0, NULL, CCS_FALSE, NULL}; CCS_VALIDATE_ERR_GOTO( res, _ccs_deserialize_bin_tree_configuration_data( - &data, version, buffer_size, buffer), + &data, version, buffer_size, buffer, &new_opts), end); CCS_VALIDATE_ERR_GOTO( @@ -65,8 +86,8 @@ _ccs_deserialize_bin_tree_configuration( CCS_VALIDATE_ERR_GOTO( res, ccs_create_tree_configuration( - tree_space, data.position_size, data.position, - &configuration), + tree_space, data.features, data.position_size, + data.position, &configuration), end); if (opts->map_values) @@ -82,6 +103,8 @@ _ccs_deserialize_bin_tree_configuration( err_configuration: ccs_release_object(configuration); end: + if (data.features) + ccs_release_object(data.features); if (data.position) free(data.position); return res; diff --git a/src/tree_configuration_internal.h b/src/tree_configuration_internal.h index ee6de434..809c885f 100644 --- a/src/tree_configuration_internal.h +++ b/src/tree_configuration_internal.h @@ -27,6 +27,7 @@ struct _ccs_tree_configuration_data_s { ccs_tree_space_t tree_space; size_t position_size; size_t *position; + ccs_features_t features; }; #endif //_TREE_CONFIGURATION_INTERNAL_H diff --git a/src/tree_deserialize.h b/src/tree_deserialize.h index fbed9f08..1133a6a6 100644 --- a/src/tree_deserialize.h +++ b/src/tree_deserialize.h @@ -31,6 +31,7 @@ _ccs_deserialize_bin_ccs_tree_data( { _ccs_object_deserialize_options_t new_opts = *opts; new_opts.handle_map = NULL; + new_opts.map_values = CCS_FALSE; CCS_VALIDATE( _ccs_deserialize_bin_size(&data->arity, buffer_size, buffer)); CCS_VALIDATE(_ccs_deserialize_bin_ccs_float( @@ -94,7 +95,7 @@ _ccs_deserialize_bin_tree( res, ccs_tree_set_child(tree, i, data.children[i]), err_tree); - if (opts && opts->handle_map) + if (opts && opts->map_values && opts->handle_map) CCS_VALIDATE_ERR_GOTO( res, _ccs_object_handle_check_add( diff --git a/src/tree_space.c b/src/tree_space.c index 481d9dce..3be5750d 100644 --- a/src/tree_space.c +++ b/src/tree_space.c @@ -2,6 +2,7 @@ #include "tree_space_internal.h" #include "tree_configuration_internal.h" #include "tree_internal.h" +#include "features_internal.h" #include "utarray.h" static inline _ccs_tree_space_ops_t * @@ -39,6 +40,19 @@ ccs_tree_space_get_rng(ccs_tree_space_t tree_space, ccs_rng_t *rng_ret) return CCS_RESULT_SUCCESS; } +ccs_result_t +ccs_tree_space_get_feature_space( + ccs_tree_space_t tree_space, + ccs_feature_space_t *feature_space_ret) +{ + CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + CCS_CHECK_PTR(feature_space_ret); + *feature_space_ret = + ((_ccs_tree_space_common_data_t *)(tree_space->data)) + ->feature_space; + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_tree_space_get_tree(ccs_tree_space_t tree_space, ccs_tree_t *tree_ret) { @@ -129,6 +143,7 @@ ccs_tree_space_check_configuration( static inline ccs_result_t _ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations) @@ -163,7 +178,7 @@ _ccs_tree_space_samples( CCS_VALIDATE_ERR_GOTO( err, ccs_create_tree_configuration( - tree_space, utarray_len(arr), + tree_space, features, utarray_len(arr), (size_t *)utarray_eltptr(arr, 0), configurations + i), err_arr); @@ -178,32 +193,50 @@ _ccs_tree_space_samples( ccs_result_t ccs_tree_space_sample( ccs_tree_space_t tree_space, + ccs_features_t features, ccs_rng_t rng, ccs_tree_configuration_t *configuration_ret) { CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + _ccs_tree_space_common_data_t *data = + (_ccs_tree_space_common_data_t *)tree_space->data; + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(configuration_ret); - CCS_VALIDATE( - _ccs_tree_space_samples(tree_space, rng, 1, configuration_ret)); + CCS_VALIDATE(_ccs_tree_space_samples( + tree_space, features, rng, 1, configuration_ret)); return CCS_RESULT_SUCCESS; } ccs_result_t ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_features_t features, ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations) { CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + _ccs_tree_space_common_data_t *data = + (_ccs_tree_space_common_data_t *)tree_space->data; + if (features) { + CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); + CCS_REFUTE( + features->data->feature_space != data->feature_space, + CCS_RESULT_ERROR_INVALID_FEATURES); + } if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_ARY(num_configurations, configurations); if (num_configurations == 0) return CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_tree_space_samples( - tree_space, rng, num_configurations, configurations)); + tree_space, features, rng, num_configurations, configurations)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_space_deserialize.h b/src/tree_space_deserialize.h index 849781ec..a41886db 100644 --- a/src/tree_space_deserialize.h +++ b/src/tree_space_deserialize.h @@ -2,16 +2,28 @@ #define _TREE_SPACE_DESERIALIZE_H #include "tree_space_internal.h" +struct _ccs_tree_space_common_data_mock_s { + ccs_tree_space_type_t type; + const char *name; + ccs_rng_t rng; + ccs_tree_t tree; + ccs_object_t feature_space_handle; + ccs_feature_space_t feature_space; +}; +typedef struct _ccs_tree_space_common_data_mock_s + _ccs_tree_space_common_data_mock_t; + static inline ccs_result_t _ccs_deserialize_bin_ccs_tree_space_common_data( - _ccs_tree_space_common_data_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) + _ccs_tree_space_common_data_mock_t *data, + uint32_t version, + size_t *buffer_size, + const char **buffer, + _ccs_object_deserialize_options_t *opts) { _ccs_object_deserialize_options_t new_opts = *opts; new_opts.handle_map = NULL; + new_opts.map_values = CCS_FALSE; CCS_VALIDATE(_ccs_deserialize_bin_ccs_tree_space_type( &data->type, buffer_size, buffer)); CCS_VALIDATE( @@ -24,85 +36,91 @@ _ccs_deserialize_bin_ccs_tree_space_common_data( (ccs_object_t *)&data->tree, CCS_OBJECT_TYPE_TREE, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, &new_opts)); + CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( + &data->feature_space_handle, buffer_size, buffer)); + if (data->feature_space_handle) { + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)&data->feature_space, + CCS_OBJECT_TYPE_FEATURE_SPACE, + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, + buffer, opts)); + } return CCS_RESULT_SUCCESS; } static inline ccs_result_t _ccs_deserialize_bin_tree_space_static( - ccs_tree_space_t *tree_space_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) + ccs_tree_space_t *tree_space_ret, + uint32_t version, + size_t *buffer_size, + const char **buffer, + _ccs_object_deserialize_options_t *opts, + _ccs_tree_space_common_data_mock_t *data) { - ccs_result_t res = CCS_RESULT_SUCCESS; - _ccs_tree_space_common_data_t data = { - CCS_TREE_SPACE_TYPE_STATIC, NULL, NULL, NULL}; + ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE_ERR_GOTO( res, _ccs_deserialize_bin_ccs_tree_space_common_data( - &data, version, buffer_size, buffer, opts), + data, version, buffer_size, buffer, opts), end); CCS_VALIDATE_ERR_GOTO( res, ccs_create_static_tree_space( - data.name, data.tree, data.rng, tree_space_ret), + data->name, data->tree, data->feature_space, data->rng, + tree_space_ret), end); end: - if (data.rng) - ccs_release_object(data.rng); - if (data.tree) - ccs_release_object(data.tree); + if (data->feature_space) + ccs_release_object(data->feature_space); + if (data->rng) + ccs_release_object(data->rng); + if (data->tree) + ccs_release_object(data->tree); return res; } -struct _ccs_tree_space_dynamic_data_mock_s { - _ccs_tree_space_common_data_t common_data; - _ccs_blob_t blob; -}; -typedef struct _ccs_tree_space_dynamic_data_mock_s - _ccs_tree_space_dynamic_data_mock_t; - static inline ccs_result_t _ccs_deserialize_bin_tree_space_dynamic( - ccs_tree_space_t *tree_space_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) + ccs_tree_space_t *tree_space_ret, + uint32_t version, + size_t *buffer_size, + const char **buffer, + _ccs_object_deserialize_options_t *opts, + _ccs_tree_space_common_data_mock_t *data) { - _ccs_tree_space_dynamic_data_mock_t data = { - {CCS_TREE_SPACE_TYPE_DYNAMIC, NULL, NULL, NULL}, {0, NULL}}; + _ccs_blob_t blob = {0, NULL}; ccs_dynamic_tree_space_vector_t *vector = (ccs_dynamic_tree_space_vector_t *)opts->vector; ccs_result_t res = CCS_RESULT_SUCCESS; CCS_VALIDATE_ERR_GOTO( res, _ccs_deserialize_bin_ccs_tree_space_common_data( - &data.common_data, version, buffer_size, buffer, opts), + data, version, buffer_size, buffer, opts), end); + CCS_VALIDATE(_ccs_deserialize_bin_ccs_blob(&blob, buffer_size, buffer)); CCS_VALIDATE_ERR_GOTO( res, ccs_create_dynamic_tree_space( - data.common_data.name, data.common_data.tree, - data.common_data.rng, vector, opts->data, - tree_space_ret), + data->name, data->tree, data->feature_space, data->rng, + vector, opts->data, tree_space_ret), end); if (vector->deserialize_state) CCS_VALIDATE_ERR_GOTO( res, vector->deserialize_state( - *tree_space_ret, data.blob.sz, data.blob.blob), + *tree_space_ret, blob.sz, blob.blob), tree_space); goto end; tree_space: ccs_release_object(*tree_space_ret); *tree_space_ret = NULL; end: - if (data.common_data.rng) - ccs_release_object(data.common_data.rng); - if (data.common_data.tree) - ccs_release_object(data.common_data.tree); + if (data->feature_space) + ccs_release_object(data->feature_space); + if (data->rng) + ccs_release_object(data->rng); + if (data->tree) + ccs_release_object(data->tree); return res; } @@ -126,27 +144,42 @@ _ccs_deserialize_bin_tree_space( ccs_tree_space_type_t stype; CCS_VALIDATE( _ccs_peek_bin_ccs_tree_space_type(&stype, buffer_size, buffer)); + + _ccs_tree_space_common_data_mock_t data = { + CCS_TREE_SPACE_TYPE_STATIC, NULL, NULL, NULL, NULL, NULL}; + switch (stype) { case CCS_TREE_SPACE_TYPE_STATIC: CCS_VALIDATE(_ccs_deserialize_bin_tree_space_static( - tree_space_ret, version, buffer_size, buffer, opts)); + tree_space_ret, version, buffer_size, buffer, opts, + &data)); break; case CCS_TREE_SPACE_TYPE_DYNAMIC: CCS_VALIDATE(_ccs_deserialize_bin_tree_space_dynamic( - tree_space_ret, version, buffer_size, buffer, opts)); + tree_space_ret, version, buffer_size, buffer, opts, + &data)); break; default: CCS_RAISE( CCS_RESULT_ERROR_UNSUPPORTED_OPERATION, "Unsupported tree space type: %d", stype); } - if (opts && opts->handle_map) + if (opts && opts->map_values && opts->handle_map) { + if (data.feature_space_handle) + CCS_VALIDATE_ERR_GOTO( + res, + _ccs_object_handle_check_add( + opts->handle_map, + data.feature_space_handle, + (ccs_object_t)data.feature_space), + err_tree_space); CCS_VALIDATE_ERR_GOTO( res, _ccs_object_handle_check_add( opts->handle_map, handle, (ccs_object_t)*tree_space_ret), err_tree_space); + } return CCS_RESULT_SUCCESS; err_tree_space: ccs_release_object(*tree_space_ret); diff --git a/src/tree_space_dynamic.c b/src/tree_space_dynamic.c index 0ff5a2ed..0ff18d36 100644 --- a/src/tree_space_dynamic.c +++ b/src/tree_space_dynamic.c @@ -15,10 +15,15 @@ _ccs_tree_space_dynamic_del(ccs_object_t o) struct _ccs_tree_space_dynamic_data_s *data = (struct _ccs_tree_space_dynamic_data_s *)(((ccs_tree_space_t)o) ->data); - ccs_result_t err; - err = data->vector.del((ccs_tree_space_t)o); - ccs_release_object(data->common_data.rng); - ccs_release_object(data->common_data.tree); + ccs_result_t err = CCS_RESULT_SUCCESS; + if (data->vector.del) + err = data->vector.del((ccs_tree_space_t)o); + if (data->common_data.rng) + ccs_release_object(data->common_data.rng); + if (data->common_data.tree) + ccs_release_object(data->common_data.tree); + if (data->common_data.feature_space) + ccs_release_object(data->common_data.feature_space); return err; } @@ -251,6 +256,7 @@ ccs_result_t ccs_create_dynamic_tree_space( const char *name, ccs_tree_t tree, + ccs_feature_space_t feature_space, ccs_rng_t rng, ccs_dynamic_tree_space_vector_t *vector, void *tree_space_data, @@ -258,6 +264,8 @@ ccs_create_dynamic_tree_space( { CCS_CHECK_PTR(name); CCS_CHECK_OBJ(tree, CCS_OBJECT_TYPE_TREE); + if (feature_space) + CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(vector); @@ -270,36 +278,40 @@ ccs_create_dynamic_tree_space( sizeof(struct _ccs_tree_space_dynamic_data_s) + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - if (!rng) - CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); - else - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errmem); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), err_rng); + uintptr_t mem_orig = mem; - ccs_tree_space_t tree_space; + ccs_tree_space_t tree_space; + _ccs_tree_space_dynamic_data_t *data; tree_space = (ccs_tree_space_t)mem; + mem += sizeof(struct _ccs_tree_space_s); _ccs_object_init( &(tree_space->obj), CCS_OBJECT_TYPE_TREE_SPACE, (_ccs_object_ops_t *)&_ccs_tree_space_dynamic_ops); - _ccs_tree_space_dynamic_data_t *data; - data = (struct _ccs_tree_space_dynamic_data_s - *)(mem + sizeof(struct _ccs_tree_space_s)); + data = (struct _ccs_tree_space_dynamic_data_s *)mem; + mem += sizeof(struct _ccs_tree_space_dynamic_data_s); data->common_data.type = CCS_TREE_SPACE_TYPE_DYNAMIC; - data->common_data.name = - (const char - *)(mem + sizeof(struct _ccs_tree_space_s) + sizeof(struct _ccs_tree_space_dynamic_data_s)); - data->common_data.rng = rng; + data->common_data.name = (const char *)mem; + tree_space->data = (_ccs_tree_space_data_t *)data; + if (!rng) + CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errinit); + else + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errinit); + data->common_data.rng = rng; + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), errinit); data->common_data.tree = tree; + if (feature_space) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(feature_space), errinit); + data->common_data.feature_space = feature_space; strcpy((char *)(data->common_data.name), name); data->tree_space_data = tree_space_data; memcpy(&data->vector, vector, sizeof(data->vector)); - tree_space->data = (_ccs_tree_space_data_t *)data; - *tree_space_ret = tree_space; + *tree_space_ret = tree_space; return CCS_RESULT_SUCCESS; -err_rng: - ccs_release_object(rng); -errmem: - free((void *)mem); +errinit: + _ccs_tree_space_dynamic_del(tree_space); + _ccs_object_deinit(&(tree_space->obj)); + free((void *)mem_orig); return err; } diff --git a/src/tree_space_internal.h b/src/tree_space_internal.h index 09769abc..f465829d 100644 --- a/src/tree_space_internal.h +++ b/src/tree_space_internal.h @@ -2,6 +2,7 @@ #define _TREE_SPACE_INTERNAL_H #include "tree_internal.h" #include "rng_internal.h" +#include "feature_space_internal.h" #define CCS_CHECK_TREE_SPACE(o, t) \ do { \ @@ -49,6 +50,7 @@ struct _ccs_tree_space_common_data_s { const char *name; ccs_rng_t rng; ccs_tree_t tree; + ccs_feature_space_t feature_space; }; typedef struct _ccs_tree_space_common_data_s _ccs_tree_space_common_data_t; @@ -64,6 +66,11 @@ _ccs_serialize_bin_size_ccs_tree_space_common_data( data->rng, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); CCS_VALIDATE(data->tree->obj.ops->serialize_size( data->tree, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); + *cum_size += _ccs_serialize_bin_size_ccs_object(data->feature_space); + if (data->feature_space) + CCS_VALIDATE(data->feature_space->obj.ops->serialize_size( + data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, + cum_size, opts)); return CCS_RESULT_SUCCESS; } @@ -84,6 +91,12 @@ _ccs_serialize_bin_ccs_tree_space_common_data( CCS_VALIDATE(data->tree->obj.ops->serialize( data->tree, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); + CCS_VALIDATE(_ccs_serialize_bin_ccs_object( + data->feature_space, buffer_size, buffer)); + if (data->feature_space) + CCS_VALIDATE(data->feature_space->obj.ops->serialize( + data->feature_space, CCS_SERIALIZE_FORMAT_BINARY, + buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_space_static.c b/src/tree_space_static.c index 00c41ee7..d31ccda8 100644 --- a/src/tree_space_static.c +++ b/src/tree_space_static.c @@ -13,8 +13,12 @@ _ccs_tree_space_static_del(ccs_object_t o) struct _ccs_tree_space_static_data_s *data = (struct _ccs_tree_space_static_data_s *)(((ccs_tree_space_t)o) ->data); - ccs_release_object(data->common_data.rng); - ccs_release_object(data->common_data.tree); + if (data->common_data.rng) + ccs_release_object(data->common_data.rng); + if (data->common_data.tree) + ccs_release_object(data->common_data.tree); + if (data->common_data.feature_space) + ccs_release_object(data->common_data.feature_space); return CCS_RESULT_SUCCESS; } @@ -170,13 +174,16 @@ static _ccs_tree_space_ops_t _ccs_tree_space_static_ops = { ccs_result_t ccs_create_static_tree_space( - const char *name, - ccs_tree_t tree, - ccs_rng_t rng, - ccs_tree_space_t *tree_space_ret) + const char *name, + ccs_tree_t tree, + ccs_feature_space_t feature_space, + ccs_rng_t rng, + ccs_tree_space_t *tree_space_ret) { CCS_CHECK_PTR(name); CCS_CHECK_OBJ(tree, CCS_OBJECT_TYPE_TREE); + if (feature_space) + CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); if (rng) CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(tree_space_ret); @@ -186,33 +193,37 @@ ccs_create_static_tree_space( sizeof(struct _ccs_tree_space_static_data_s) + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - if (!rng) - CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); - else - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errmem); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), err_rng); + uintptr_t mem_orig = mem; - ccs_tree_space_t tree_space; + ccs_tree_space_t tree_space; + _ccs_tree_space_static_data_t *data; tree_space = (ccs_tree_space_t)mem; + mem += sizeof(struct _ccs_tree_space_s); _ccs_object_init( &(tree_space->obj), CCS_OBJECT_TYPE_TREE_SPACE, (_ccs_object_ops_t *)&_ccs_tree_space_static_ops); - _ccs_tree_space_static_data_t *data; - data = (struct _ccs_tree_space_static_data_s - *)(mem + sizeof(struct _ccs_tree_space_s)); + data = (struct _ccs_tree_space_static_data_s *)mem; + mem += sizeof(struct _ccs_tree_space_static_data_s); data->common_data.type = CCS_TREE_SPACE_TYPE_STATIC; - data->common_data.name = - (const char - *)(mem + sizeof(struct _ccs_tree_space_s) + sizeof(struct _ccs_tree_space_static_data_s)); - data->common_data.rng = rng; + data->common_data.name = (const char *)mem; + tree_space->data = (_ccs_tree_space_data_t *)data; + if (!rng) + CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errinit); + else + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errinit); + data->common_data.rng = rng; + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), errinit); data->common_data.tree = tree; + if (feature_space) + CCS_VALIDATE_ERR_GOTO( + err, ccs_retain_object(feature_space), errinit); + data->common_data.feature_space = feature_space; strcpy((char *)(data->common_data.name), name); - tree_space->data = (_ccs_tree_space_data_t *)data; - *tree_space_ret = tree_space; + *tree_space_ret = tree_space; return CCS_RESULT_SUCCESS; -err_rng: - ccs_release_object(rng); -errmem: - free((void *)mem); +errinit: + _ccs_tree_space_static_del(tree_space); + _ccs_object_deinit(&(tree_space->obj)); + free((void *)mem_orig); return err; } diff --git a/src/tuner_random.c b/src/tuner_random.c index a196756e..c486711e 100644 --- a/src/tuner_random.c +++ b/src/tuner_random.c @@ -165,11 +165,11 @@ _ccs_tuner_random_ask( if (CCS_OBJ_TYPE(search_space) == CCS_OBJECT_TYPE_CONFIGURATION_SPACE) CCS_VALIDATE(ccs_configuration_space_samples( (ccs_configuration_space_t)search_space, NULL, NULL, - num_configurations, + NULL, num_configurations, (ccs_configuration_t *)configurations)); else CCS_VALIDATE(ccs_tree_space_samples( - (ccs_tree_space_t)search_space, NULL, + (ccs_tree_space_t)search_space, NULL, NULL, num_configurations, (ccs_tree_configuration_t *)configurations)); if (num_configurations_ret) diff --git a/tests/test_condition.c b/tests/test_condition.c index 26da0da6..805e88a7 100644 --- a/tests/test_condition.c +++ b/tests/test_condition.c @@ -25,14 +25,15 @@ test_simple(void) assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "space", 2, parameters, conditions, 0, NULL, NULL, &space); + "space", 2, parameters, conditions, 0, NULL, NULL, NULL, + &space); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; err = ccs_configuration_space_sample( - space, NULL, NULL, &configuration); + space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( (ccs_binding_t)configuration, 2, values, NULL); @@ -53,7 +54,7 @@ test_simple(void) } err = ccs_configuration_space_samples( - space, NULL, NULL, 100, configurations); + space, NULL, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { @@ -112,7 +113,8 @@ test_transitive(void) assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "space", 3, parameters, conditions, 0, NULL, NULL, &space); + "space", 3, parameters, conditions, 0, NULL, NULL, NULL, + &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(conditions[0]); @@ -124,7 +126,7 @@ test_transitive(void) ccs_float_t f; ccs_bool_t check; err = ccs_configuration_space_sample( - space, NULL, NULL, &configuration); + space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( (ccs_binding_t)configuration, 3, values, NULL); @@ -156,7 +158,7 @@ test_transitive(void) } err = ccs_configuration_space_samples( - space, NULL, NULL, 100, configurations); + space, NULL, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { diff --git a/tests/test_configuration_space.c b/tests/test_configuration_space.c index d6c219cf..2c5720a3 100644 --- a/tests/test_configuration_space.c +++ b/tests/test_configuration_space.c @@ -72,7 +72,7 @@ check_configuration( } err = ccs_configuration_space_get_default_configuration( - configuration_space, &configuration); + configuration_space, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_check(configuration, &check); @@ -102,19 +102,19 @@ test_empty(void) ccs_result_t err; err = ccs_create_configuration_space( - "my_config_space", 0, NULL, NULL, 0, NULL, NULL, + "my_config_space", 0, NULL, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( - configuration_space, NULL, NULL, &configuration); + configuration_space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_get_default_configuration( - configuration_space, &configuration); + configuration_space, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(configuration); @@ -139,19 +139,19 @@ test_create(void) parameters[2] = parameters[0]; err = ccs_create_configuration_space( - "my_config_space", 3, NULL, NULL, 0, NULL, NULL, + "my_config_space", 3, NULL, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_ERROR_INVALID_VALUE); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_ERROR_INVALID_PARAMETER); parameters[2] = parameter3; err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -192,12 +192,12 @@ test_sample(void) assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "my_config_space", 4, parameters, NULL, 0, NULL, NULL, + "my_config_space", 4, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( - configuration_space, NULL, NULL, &configuration); + configuration_space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_check(configuration, &check); @@ -205,7 +205,7 @@ test_sample(void) assert(check); err = ccs_configuration_space_samples( - configuration_space, NULL, NULL, 100, configurations); + configuration_space, NULL, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); for (size_t i = 0; i < 100; i++) { @@ -244,12 +244,12 @@ test_configuration_deserialize(void) parameters[2] = create_numerical("param3", -5.0, 5.0); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( - configuration_space, NULL, NULL, &configuration_ref); + configuration_space, NULL, NULL, NULL, &configuration_ref); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_map(&map); @@ -343,7 +343,7 @@ test_deserialize(void) err = ccs_create_configuration_space( "my_config_space", 3, parameters, conditions, 1, &expression, - NULL, &space); + NULL, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(expression); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_distribution_space.c b/tests/test_distribution_space.c index ea5dffd7..d8c54032 100644 --- a/tests/test_distribution_space.c +++ b/tests/test_distribution_space.c @@ -72,7 +72,7 @@ check_configuration( } err = ccs_configuration_space_get_default_configuration( - configuration_space, &configuration); + configuration_space, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_check(configuration, &check); @@ -108,7 +108,7 @@ test_create(void) parameters[2] = create_dummy_parameter("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -155,7 +155,7 @@ test_set_distribution(void) parameters[2] = create_dummy_parameter("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -195,7 +195,7 @@ test_set_distribution(void) assert(dindex_ret == 1); err = ccs_configuration_space_samples( - configuration_space, distribution_space, NULL, 100, + configuration_space, distribution_space, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); @@ -234,7 +234,7 @@ test_set_distribution(void) assert(dindex_ret == 0); err = ccs_configuration_space_samples( - configuration_space, distribution_space, NULL, 100, + configuration_space, distribution_space, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); @@ -292,7 +292,8 @@ test_deserialize(void) parameters[2] = create_numerical("param3", -5.0, 5.0); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, NULL, 0, NULL, NULL, &space); + "my_config_space", 3, parameters, NULL, 0, NULL, NULL, NULL, + &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_distribution_space(space, &distrib_space); diff --git a/tests/test_dynamic_tree_space.c b/tests/test_dynamic_tree_space.c index 56533821..adf0cb01 100644 --- a/tests/test_dynamic_tree_space.c +++ b/tests/test_dynamic_tree_space.c @@ -58,7 +58,7 @@ test_dynamic_tree_space(void) err = ccs_create_rng(&rng); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_dynamic_tree_space( - "space", root, rng, &vector, NULL, &tree_space); + "space", root, NULL, rng, &vector, NULL, &tree_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_space_get_type(tree_space, &tree_type); @@ -116,10 +116,11 @@ test_dynamic_tree_space(void) free(values); free(position); - err = ccs_tree_space_sample(tree_space, NULL, &config); + err = ccs_tree_space_sample(tree_space, NULL, NULL, &config); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); + err = ccs_tree_space_samples( + tree_space, NULL, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); char *buff; @@ -180,7 +181,8 @@ test_dynamic_tree_space(void) assert(err == CCS_RESULT_SUCCESS); free(buff); - err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); + err = ccs_tree_space_samples( + tree_space, NULL, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; diff --git a/tests/test_expression.c b/tests/test_expression.c index 2ec50c35..e5dca951 100644 --- a/tests/test_expression.c +++ b/tests/test_expression.c @@ -173,7 +173,7 @@ test_equal_numerical(void) parameters[1] = create_dummy_numerical("param2"); err = ccs_create_configuration_space( - "my_config_space", 2, parameters, NULL, 0, NULL, NULL, + "my_config_space", 2, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -182,7 +182,7 @@ test_equal_numerical(void) values[0] = ccs_float(1.0); values[1] = ccs_float(0.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -192,7 +192,7 @@ test_equal_numerical(void) values[0] = ccs_float(0.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -205,7 +205,7 @@ test_equal_numerical(void) values[0] = ccs_float(1.0); values[1] = ccs_float(1.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -215,7 +215,7 @@ test_equal_numerical(void) values[1] = ccs_float(0.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -225,7 +225,7 @@ test_equal_numerical(void) nodes[0] = ccs_int(0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -235,7 +235,7 @@ test_equal_numerical(void) nodes[0] = ccs_bool(CCS_FALSE); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -264,7 +264,7 @@ test_equal_categorical(void) parameters[0] = create_dummy_categorical("param1"); parameters[1] = create_dummy_categorical("param2"); err = ccs_create_configuration_space( - "my_config_space", 2, parameters, NULL, 0, NULL, NULL, + "my_config_space", 2, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -273,7 +273,7 @@ test_equal_categorical(void) values[0] = ccs_float(2.0); values[1] = ccs_int(1); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -284,7 +284,7 @@ test_equal_categorical(void) // Values tested must exist in the set nodes[1] = ccs_float(3.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -294,7 +294,7 @@ test_equal_categorical(void) nodes[1] = ccs_int(1); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -323,7 +323,7 @@ test_equal_ordinal(void) parameters[0] = create_dummy_ordinal("param1"); parameters[1] = create_dummy_ordinal("param2"); err = ccs_create_configuration_space( - "my_config_space", 2, parameters, NULL, 0, NULL, NULL, + "my_config_space", 2, parameters, NULL, 0, NULL, NULL, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); @@ -332,7 +332,7 @@ test_equal_ordinal(void) values[0] = ccs_float(2.0); values[1] = ccs_int(1); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -343,7 +343,7 @@ test_equal_ordinal(void) // Values tested must exist in the set nodes[1] = ccs_float(3.0); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -353,7 +353,7 @@ test_equal_ordinal(void) nodes[1] = ccs_int(1); err = ccs_create_configuration( - configuration_space, 2, values, &configuration); + configuration_space, NULL, 2, values, &configuration); assert(err == CCS_RESULT_SUCCESS); test_expression_wrapper( CCS_EXPRESSION_TYPE_EQUAL, 2, nodes, configuration, @@ -980,7 +980,7 @@ test_check_context(void) parameters[1] = parameter2; err = ccs_create_configuration_space( - "space", 2, parameters, NULL, 0, NULL, NULL, &space); + "space", 2, parameters, NULL, 0, NULL, NULL, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_binary_expression( diff --git a/tests/test_forbidden.c b/tests/test_forbidden.c index 00336e61..a378ac85 100644 --- a/tests/test_forbidden.c +++ b/tests/test_forbidden.c @@ -24,14 +24,15 @@ test_simple(void) ccs_float(0.0), &expression); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "space", 2, parameters, NULL, 1, &expression, NULL, &space); + "space", 2, parameters, NULL, 1, &expression, NULL, NULL, + &space); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; err = ccs_configuration_space_sample( - space, NULL, NULL, &configuration); + space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( (ccs_binding_t)configuration, 2, values, NULL); @@ -50,7 +51,7 @@ test_simple(void) assert(err == CCS_RESULT_SUCCESS); } err = ccs_configuration_space_samples( - space, NULL, NULL, 100, configurations); + space, NULL, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { @@ -115,7 +116,7 @@ test_combined(void) assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "space", 3, parameters, conditions, 1, &expression, NULL, + "space", 3, parameters, conditions, 1, &expression, NULL, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(expression); @@ -130,7 +131,7 @@ test_combined(void) ccs_float_t f; ccs_bool_t check; err = ccs_configuration_space_sample( - space, NULL, NULL, &configuration); + space, NULL, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( (ccs_binding_t)configuration, 3, values, NULL); @@ -162,7 +163,7 @@ test_combined(void) } err = ccs_configuration_space_samples( - space, NULL, NULL, 100, configurations); + space, NULL, NULL, NULL, 100, configurations); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { diff --git a/tests/test_random_features_tuner.c b/tests/test_random_features_tuner.c index 3774b3e0..5fbac038 100644 --- a/tests/test_random_features_tuner.c +++ b/tests/test_random_features_tuner.c @@ -18,18 +18,17 @@ test(void) size_t buff_size; ccs_map_t map; - cspace = create_2d_plane(); - ospace = create_height_objective(cspace); fspace = create_knobs(&features_on, &features_off); + cspace = create_2d_plane(fspace); + ospace = create_height_objective(cspace); - err = ccs_create_random_features_tuner( - "problem", fspace, ospace, &tuner); + err = ccs_create_random_features_tuner("problem", ospace, &tuner); assert(err == CCS_RESULT_SUCCESS); for (size_t i = 0; i < 50; i++) { ccs_datum_t values[2], res; ccs_search_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -39,9 +38,9 @@ test(void) res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + (values[1].value.f - 2) * (values[1].value.f - 2)); - err = ccs_create_features_evaluation( - ospace, configuration, features_on, CCS_RESULT_SUCCESS, - 1, &res, &evaluation); + err = ccs_create_evaluation( + ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, + &evaluation); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); @@ -54,7 +53,7 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t values[2], res; ccs_search_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -64,9 +63,9 @@ test(void) res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + (values[1].value.f - 2) * (values[1].value.f - 2)); - err = ccs_create_features_evaluation( - ospace, configuration, features_off, CCS_RESULT_SUCCESS, - 1, &res, &evaluation); + err = ccs_create_evaluation( + ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, + &evaluation); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); @@ -76,11 +75,11 @@ test(void) assert(err == CCS_RESULT_SUCCESS); } - size_t count; - ccs_features_evaluation_t history[100]; - ccs_features_evaluation_t evaluation; - ccs_datum_t min_on = ccs_float(INFINITY); - ccs_datum_t min_off = ccs_float(INFINITY); + size_t count; + ccs_evaluation_t history[100]; + ccs_evaluation_t evaluation; + ccs_datum_t min_on = ccs_float(INFINITY); + ccs_datum_t min_off = ccs_float(INFINITY); err = ccs_features_tuner_get_history(tuner, NULL, 0, NULL, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 100); @@ -197,24 +196,24 @@ test_evaluation_deserialize(void) ccs_result_t err; ccs_configuration_t configuration; ccs_features_t features_on; - ccs_features_evaluation_t evaluation_ref, evaluation; + ccs_evaluation_t evaluation_ref, evaluation; ccs_datum_t res, d; char *buff; size_t buff_size; ccs_map_t map; int cmp; - cspace = create_2d_plane(); - ospace = create_height_objective(cspace); fspace = create_knobs(&features_on, NULL); + cspace = create_2d_plane(fspace); + ospace = create_height_objective(cspace); err = ccs_configuration_space_sample( - cspace, NULL, NULL, &configuration); + cspace, NULL, features_on, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); res = ccs_float(1.5); - err = ccs_create_features_evaluation( - ospace, (ccs_search_configuration_t)configuration, features_on, + err = ccs_create_evaluation( + ospace, (ccs_search_configuration_t)configuration, CCS_RESULT_SUCCESS, 1, &res, &evaluation_ref); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_random_tree_tuner.c b/tests/test_random_tree_tuner.c index 813102ec..215936b7 100644 --- a/tests/test_random_tree_tuner.c +++ b/tests/test_random_tree_tuner.c @@ -35,7 +35,8 @@ create_tree_tuning_problem( ccs_result_t err; generate_tree(&root, 5, 0); - err = ccs_create_static_tree_space("space", root, NULL, tree_space); + err = ccs_create_static_tree_space( + "space", root, NULL, NULL, tree_space); assert(err == CCS_RESULT_SUCCESS); parameter = create_numerical("sum", -CCS_INFINITY, CCS_INFINITY); @@ -46,7 +47,6 @@ create_tree_tuning_problem( err = ccs_create_objective_space( "ospace", (ccs_search_space_t)*tree_space, 1, ¶meter, 1, &expression, &otype, ospace); - print_ccs_error_stack(); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(root); @@ -147,6 +147,7 @@ test(void) CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff, CCS_DESERIALIZE_OPTION_HANDLE_MAP, map, CCS_DESERIALIZE_OPTION_END); + print_ccs_error_stack(); assert(err == CCS_RESULT_SUCCESS); err = ccs_tuner_get_history(tuner_copy, 100, history, &count); @@ -191,7 +192,7 @@ test_tree_evaluation_deserialize(void) create_tree_tuning_problem(&tree_space, &ospace); - err = ccs_tree_space_sample(tree_space, NULL, &configuration); + err = ccs_tree_space_sample(tree_space, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); res = ccs_float(1.5); diff --git a/tests/test_random_tuner.c b/tests/test_random_tuner.c index 43fc1d07..4574f538 100644 --- a/tests/test_random_tuner.c +++ b/tests/test_random_tuner.c @@ -16,7 +16,7 @@ test(void) size_t buff_size; ccs_map_t map; - cspace = create_2d_plane(); + cspace = create_2d_plane(NULL); ospace = create_height_objective(cspace); err = ccs_create_random_tuner("problem", ospace, &tuner); @@ -132,11 +132,12 @@ test_evaluation_deserialize(void) ccs_map_t map; int cmp; - cspace = create_2d_plane(); + cspace = create_2d_plane(NULL); ospace = create_height_objective(cspace); err = ccs_configuration_space_sample( - cspace, NULL, NULL, (ccs_configuration_t *)&configuration); + cspace, NULL, NULL, NULL, + (ccs_configuration_t *)&configuration); assert(err == CCS_RESULT_SUCCESS); res = ccs_float(1.5); diff --git a/tests/test_static_tree_space.c b/tests/test_static_tree_space.c index 8884c836..c8cd89d8 100644 --- a/tests/test_static_tree_space.c +++ b/tests/test_static_tree_space.c @@ -42,7 +42,8 @@ test_static_tree_space(void) generate_tree(&root, 4, 0); err = ccs_create_rng(&rng); assert(err == CCS_RESULT_SUCCESS); - err = ccs_create_static_tree_space("space", root, rng, &tree_space); + err = ccs_create_static_tree_space( + "space", root, NULL, rng, &tree_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_space_get_type(tree_space, &tree_type); @@ -81,7 +82,7 @@ test_static_tree_space(void) free(values); free(position); - err = ccs_tree_space_sample(tree_space, NULL, &config); + err = ccs_tree_space_sample(tree_space, NULL, NULL, &config); assert(err == CCS_RESULT_SUCCESS); ccs_map_t map; @@ -133,7 +134,8 @@ test_static_tree_space(void) err = ccs_release_object(map); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); + err = ccs_tree_space_samples( + tree_space, NULL, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; @@ -186,7 +188,8 @@ test_static_tree_space(void) assert(err == CCS_RESULT_SUCCESS); free(buff); - err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); + err = ccs_tree_space_samples( + tree_space, NULL, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; diff --git a/tests/test_user_defined_features_tuner.c b/tests/test_user_defined_features_tuner.c index e9dd2439..792f572f 100644 --- a/tests/test_user_defined_features_tuner.c +++ b/tests/test_user_defined_features_tuner.c @@ -5,7 +5,7 @@ #include "test_utils.h" struct tuner_last_s { - ccs_features_evaluation_t last_eval; + ccs_evaluation_t last_eval; }; typedef struct tuner_last_s tuner_last_t; @@ -44,7 +44,7 @@ tuner_last_ask( if (err) return err; err = ccs_configuration_space_samples( - configuration_space, NULL, NULL, num_configurations, + configuration_space, NULL, features, NULL, num_configurations, (ccs_configuration_t *)configurations); if (err) return err; @@ -55,9 +55,9 @@ tuner_last_ask( ccs_result_t tuner_last_tell( - ccs_features_tuner_t tuner, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations) + ccs_features_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations) { if (!num_evaluations) return CCS_RESULT_SUCCESS; @@ -78,11 +78,11 @@ tuner_last_tell( ccs_result_t tuner_last_get_optima( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { size_t count = 0; if (evaluations) { @@ -95,7 +95,7 @@ tuner_last_get_optima( if (features) { ccs_features_t feat; int cmp; - err = ccs_features_evaluation_get_features( + err = ccs_evaluation_get_features( tuner_data->last_eval, &feat); if (err) return err; @@ -126,11 +126,11 @@ tuner_last_get_optima( ccs_result_t tuner_last_get_history( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_evaluations, - ccs_features_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { return tuner_last_get_optima( tuner, features, num_evaluations, evaluations, @@ -162,23 +162,22 @@ test(void) size_t buff_size; ccs_map_t map; - cspace = create_2d_plane(); - ospace = create_height_objective(cspace); fspace = create_knobs(&features_on, &features_off); + cspace = create_2d_plane(fspace); + ospace = create_height_objective(cspace); tuner_data = (tuner_last_t *)calloc(1, sizeof(tuner_last_t)); assert(tuner_data); err = ccs_create_user_defined_features_tuner( - "problem", fspace, ospace, &tuner_last_vector, tuner_data, - &tuner); + "problem", ospace, &tuner_last_vector, tuner_data, &tuner); assert(err == CCS_RESULT_SUCCESS); - ccs_features_evaluation_t last_evaluation; + ccs_evaluation_t last_evaluation; for (size_t i = 0; i < 50; i++) { ccs_datum_t values[2], res; ccs_search_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -188,9 +187,9 @@ test(void) res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + (values[1].value.f - 2) * (values[1].value.f - 2)); - err = ccs_create_features_evaluation( - ospace, configuration, features_on, CCS_RESULT_SUCCESS, - 1, &res, &evaluation); + err = ccs_create_evaluation( + ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, + &evaluation); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); @@ -204,7 +203,7 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t values[2], res; ccs_search_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -214,9 +213,9 @@ test(void) res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + (values[1].value.f - 2) * (values[1].value.f - 2)); - err = ccs_create_features_evaluation( - ospace, configuration, features_off, CCS_RESULT_SUCCESS, - 1, &res, &evaluation); + err = ccs_create_evaluation( + ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, + &evaluation); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); @@ -227,13 +226,13 @@ test(void) assert(err == CCS_RESULT_SUCCESS); } - size_t count; - ccs_features_evaluation_t history[100]; + size_t count; + ccs_evaluation_t history[100]; err = ccs_features_tuner_get_history(tuner, NULL, 100, history, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 1); - ccs_features_evaluation_t evaluation; + ccs_evaluation_t evaluation; err = ccs_features_tuner_get_optima( tuner, NULL, 1, &evaluation, &count); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_user_defined_tree_tuner.c b/tests/test_user_defined_tree_tuner.c index 1190e431..79c43940 100644 --- a/tests/test_user_defined_tree_tuner.c +++ b/tests/test_user_defined_tree_tuner.c @@ -35,7 +35,8 @@ create_tree_tuning_problem( ccs_result_t err; generate_tree(&root, 5, 0); - err = ccs_create_static_tree_space("space", root, NULL, tree_space); + err = ccs_create_static_tree_space( + "space", root, NULL, NULL, tree_space); assert(err == CCS_RESULT_SUCCESS); parameter = create_numerical("sum", -CCS_INFINITY, CCS_INFINITY); @@ -94,7 +95,7 @@ tuner_last_ask( if (err) return err; err = ccs_tree_space_samples( - tree_space, NULL, num_configurations, + tree_space, NULL, NULL, num_configurations, (ccs_tree_configuration_t *)configurations); if (err) return err; diff --git a/tests/test_user_defined_tuner.c b/tests/test_user_defined_tuner.c index e73bbd74..de83242b 100644 --- a/tests/test_user_defined_tuner.c +++ b/tests/test_user_defined_tuner.c @@ -42,7 +42,7 @@ tuner_last_ask( if (err) return err; err = ccs_configuration_space_samples( - configuration_space, NULL, NULL, num_configurations, + configuration_space, NULL, NULL, NULL, num_configurations, (ccs_configuration_t *)configurations); if (err) return err; @@ -147,7 +147,7 @@ test(void) size_t buff_size; ccs_map_t map; - cspace = create_2d_plane(); + cspace = create_2d_plane(NULL); ospace = create_height_objective(cspace); tuner_data = (tuner_last_t *)calloc(1, sizeof(tuner_last_t)); diff --git a/tests/test_utils.c b/tests/test_utils.c index 64c300f8..4e837f2c 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -43,7 +43,7 @@ create_numerical(const char *name, double lower, double upper) } ccs_configuration_space_t -create_2d_plane(void) +create_2d_plane(ccs_feature_space_t fspace) { ccs_parameter_t parameters[2]; ccs_configuration_space_t cspace; @@ -53,7 +53,7 @@ create_2d_plane(void) parameters[1] = create_numerical("y", -5.0, 5.0); err = ccs_create_configuration_space( - "2dplane", 2, parameters, NULL, 0, NULL, NULL, &cspace); + "2dplane", 2, parameters, NULL, 0, NULL, fspace, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(parameters[0]); diff --git a/tests/test_utils.h b/tests/test_utils.h index 72516fc5..dc4fea77 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -7,7 +7,7 @@ extern ccs_parameter_t create_numerical(const char *name, double lower, double upper); extern ccs_configuration_space_t -create_2d_plane(void); +create_2d_plane(ccs_feature_space_t fspace); extern ccs_objective_space_t create_height_objective(ccs_configuration_space_t cspace);