Skip to content

Commit

Permalink
Features are created valid and immutable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Oct 10, 2024
1 parent 08fbbc3 commit 215cabd
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 159 deletions.
7 changes: 0 additions & 7 deletions bindings/python/cconfigspace/feature_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

ccs_create_feature_space = _ccs_get_function("ccs_create_feature_space", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_feature_space)])
ccs_feature_space_get_default_features = _ccs_get_function("ccs_feature_space_get_default_features", [ccs_feature_space, ct.POINTER(ccs_features)])
ccs_feature_space_check_features = _ccs_get_function("ccs_feature_space_check_features", [ccs_feature_space, ccs_features, ct.POINTER(ccs_bool)])

class FeatureSpace(Context):
def __init__(self, handle = None, retain = False, auto_release = True,
Expand Down Expand Up @@ -34,10 +33,4 @@ def default_features(self):
self._default_features = Features.from_handle(v)
return self._default_features

def check(self, features):
valid = ccs_bool()
res = ccs_feature_space_check_features(self.handle, features.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True

from .features import Features
7 changes: 0 additions & 7 deletions bindings/python/cconfigspace/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

ccs_create_features = _ccs_get_function("ccs_create_features", [ccs_feature_space, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features)])
ccs_features_get_feature_space = _ccs_get_function("ccs_features_get_feature_space", [ccs_features, ct.POINTER(ccs_feature_space)])
ccs_features_check = _ccs_get_function("ccs_features_check", [ccs_features, ct.POINTER(ccs_bool)])

class Features(Binding):
def __init__(self, handle = None, retain = False, auto_release = True,
Expand Down Expand Up @@ -42,10 +41,4 @@ def feature_space(self):
self._feature_space = FeatureSpace.from_handle(v)
return self._feature_space

def check(self):
valid = ccs_bool()
res = ccs_features_check(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True

from .feature_space import FeatureSpace
7 changes: 0 additions & 7 deletions bindings/ruby/lib/cconfigspace/feature_space.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module CCS
attach_function :ccs_create_feature_space, [:string, :size_t, :pointer, :pointer], :ccs_result_t
attach_function :ccs_feature_space_get_default_features, [:ccs_feature_space_t, :pointer], :ccs_result_t
attach_function :ccs_feature_space_check_features, [:ccs_feature_space_t, :ccs_features_t, :pointer], :ccs_result_t

class FeatureSpace < Context
add_handle_property :default_features, :ccs_features_t, :ccs_feature_space_get_default_features, memoize: true
Expand All @@ -24,11 +23,5 @@ def self.from_handle(handle, retain: true, auto_release: true)
self::new(handle, retain: retain, auto_release: auto_release)
end

def check(features)
ptr = MemoryPointer::new(:ccs_bool_t)
CCS.error_check CCS.ccs_feature_space_check_features(@handle, features, ptr)
return ptr.read_ccs_bool_t == CCS::FALSE ? false : true
end

end
end
7 changes: 0 additions & 7 deletions bindings/ruby/lib/cconfigspace/features.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module CCS

attach_function :ccs_create_features, [:ccs_feature_space_t, :size_t, :pointer, :pointer], :ccs_result_t
attach_function :ccs_features_check, [:ccs_features_t, :pointer], :ccs_result_t

class Features < Binding
alias feature_space context
Expand Down Expand Up @@ -32,12 +31,6 @@ def self.from_handle(handle, retain: true, auto_release: true)
self::new(handle, retain: retain, auto_release: auto_release)
end

def check
ptr = MemoryPointer::new(:ccs_bool_t)
CCS.error_check CCS.ccs_features_check(@handle, ptr)
return ptr.read_ccs_bool_t == CCS::FALSE ? false : true
end

end

end
24 changes: 0 additions & 24 deletions include/cconfigspace/feature_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ 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
* @param[in] features
* @param[out] is_valid_ret a pointer to a variable that will hold the result
* of the check. Result will be #CCS_TRUE if the
* features is valid. Result will be #CCS_FALSE if
* an parameter value is not a valid value
* for this parameter;
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p feature_space is not a valid
* CCS feature space; or if \p features is not a valid CCS features
* @return #CCS_RESULT_ERROR_INVALID_FEATURES if \p features is not associated
* to the feature space; or if the number of values contained in \p features is
* not equal to the number of parameters in the feature space
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_feature_space_check_features(
ccs_feature_space_t feature_space,
ccs_features_t features,
ccs_bool_t *is_valid_ret);

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 0 additions & 19 deletions include/cconfigspace/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@ ccs_features_get_feature_space(
ccs_features_t features,
ccs_feature_space_t *feature_space_ret);

/**
* Check that the features is a valid features for the feature space.
* @param[in] features
* @param[out] is_valid_ret a pointer to a variable that will hold the result
* of the check. Result will be #CCS_TRUE if the
* features is valid. Result will be #CCS_FALSE if
* an parameter value is not a valid value
* for this parameter
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features is not a valid CCS
* features
* @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if \p features is found to be
* invalid
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_features_check(ccs_features_t features, ccs_bool_t *is_valid_ret);

#ifdef __cplusplus
}
#endif
Expand Down
34 changes: 0 additions & 34 deletions src/feature_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,3 @@ ccs_feature_space_get_default_features(
ccs_release_object(features);
return err;
}

static inline ccs_result_t
_check_features(
ccs_feature_space_t feature_space,
ccs_features_t features,
ccs_bool_t *is_valid_ret)
{
ccs_parameter_t *parameters = feature_space->data->parameters;
size_t num_parameters = feature_space->data->num_parameters;
ccs_datum_t *values = features->data->values;
*is_valid_ret = CCS_TRUE;
for (size_t i = 0; i < num_parameters; i++) {
CCS_VALIDATE(ccs_parameter_check_value(
parameters[i], values[i], is_valid_ret));
if (*is_valid_ret == CCS_FALSE)
return CCS_RESULT_SUCCESS;
}
return CCS_RESULT_SUCCESS;
}

ccs_result_t
ccs_feature_space_check_features(
ccs_feature_space_t feature_space,
ccs_features_t features,
ccs_bool_t *is_valid_ret)
{
CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE);
CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES);
CCS_REFUTE(
features->data->feature_space != feature_space,
CCS_RESULT_ERROR_INVALID_FEATURES);
CCS_VALIDATE(_check_features(feature_space, features, is_valid_ret));
return CCS_RESULT_SUCCESS;
}
24 changes: 7 additions & 17 deletions src/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ _ccs_create_features(
memcpy(feat->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)feature_space, i,
values[i],
feat->data->values + i),
errinit);
CCS_VALIDATE_ERR_GOTO(
err,
ccs_context_validate_value(
(ccs_context_t)feature_space, i,
values[i],
feat->data->values + i),
errinit);
}
*features_ret = feat;
return CCS_RESULT_SUCCESS;
Expand Down Expand Up @@ -155,12 +154,3 @@ ccs_features_get_feature_space(
(ccs_binding_t)features, (ccs_context_t *)feature_space_ret));
return CCS_RESULT_SUCCESS;
}

ccs_result_t
ccs_features_check(ccs_features_t features, ccs_bool_t *is_valid_ret)
{
CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES);
CCS_VALIDATE(ccs_feature_space_check_features(
features->data->feature_space, features, is_valid_ret));
return CCS_RESULT_SUCCESS;
}
32 changes: 15 additions & 17 deletions src/tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ ccs_tuner_ask(
size_t *num_configurations_ret)
{
CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TUNER);
if (features)
if (features) {
_ccs_tuner_common_data_t *d =
(_ccs_tuner_common_data_t *)tuner->data;
CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES);
CCS_REFUTE(
features->data->feature_space != d->feature_space,
CCS_RESULT_ERROR_INVALID_FEATURES);
}
CCS_CHECK_ARY(num_configurations, configurations);
CCS_REFUTE(
!configurations && !num_configurations_ret,
CCS_RESULT_ERROR_INVALID_VALUE);
_ccs_tuner_common_data_t *d = (_ccs_tuner_common_data_t *)tuner->data;
if (d->feature_space && features) {
ccs_bool_t valid;
CCS_VALIDATE(ccs_feature_space_check_features(
d->feature_space, features, &valid));
CCS_REFUTE(!valid, CCS_RESULT_ERROR_INVALID_FEATURES);
}
ccs_result_t err = CCS_RESULT_SUCCESS;
_ccs_tuner_ops_t *ops = ccs_tuner_get_ops(tuner);
CCS_OBJ_RDLOCK(tuner);
Expand Down Expand Up @@ -196,18 +195,17 @@ ccs_tuner_suggest(
ccs_search_configuration_t *configuration)
{
CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TUNER);
if (features) {
_ccs_tuner_common_data_t *d =
(_ccs_tuner_common_data_t *)tuner->data;
CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES);
CCS_REFUTE(
features->data->feature_space != d->feature_space,
CCS_RESULT_ERROR_INVALID_FEATURES);
}
_ccs_tuner_ops_t *ops = ccs_tuner_get_ops(tuner);
CCS_REFUTE(!ops->suggest, CCS_RESULT_ERROR_UNSUPPORTED_OPERATION);
if (features)
CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES);
CCS_CHECK_PTR(configuration);
_ccs_tuner_common_data_t *d = (_ccs_tuner_common_data_t *)tuner->data;
if (d->feature_space) {
ccs_bool_t valid;
CCS_VALIDATE(ccs_feature_space_check_features(
d->feature_space, features, &valid));
CCS_REFUTE(!valid, CCS_RESULT_ERROR_INVALID_FEATURES);
}
ccs_result_t err = CCS_RESULT_SUCCESS;
CCS_OBJ_RDLOCK(tuner);
CCS_VALIDATE_ERR_GOTO(
Expand Down
21 changes: 1 addition & 20 deletions tests/test_feature_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ test_features(void)
ccs_datum_t datum;
size_t num_values_ret;
int cmp;
ccs_bool_t check;

parameters[0] = create_dummy_parameter("param1");
parameters[1] = create_dummy_parameter("param2");
Expand Down Expand Up @@ -169,15 +168,6 @@ test_features(void)
assert(values[1].type == datum.type);
assert(values[1].value.f == datum.value.f);

err = ccs_features_check(features1, &check);
assert(err == CCS_RESULT_SUCCESS);
assert(check);

err = ccs_feature_space_check_features(
feature_space, features1, &check);
assert(err == CCS_RESULT_SUCCESS);
assert(check);

err = ccs_create_features(feature_space, 3, values, &features2);
assert(err == CCS_RESULT_SUCCESS);

Expand All @@ -201,16 +191,7 @@ test_features(void)

values[1] = ccs_float(10.0);
err = ccs_create_features(feature_space, 3, values, &features2);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_features_check(features2, &check);
assert(err == CCS_RESULT_SUCCESS);
assert(!check);

err = ccs_feature_space_check_features(
feature_space, features2, &check);
assert(err == CCS_RESULT_SUCCESS);
assert(!check);
assert(err == CCS_RESULT_ERROR_INVALID_VALUE);

for (size_t i = 0; i < 3; i++) {
err = ccs_release_object(parameters[i]);
Expand Down

0 comments on commit 215cabd

Please sign in to comment.