From 35c645c45b83e22c4c357d9d732062ffed0b5254 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Mon, 3 Jul 2023 17:21:26 -0500 Subject: [PATCH] Bindings are now immutable and thus thread safe. --- bindings/python/cconfigspace/binding.py | 29 ++------ bindings/python/cconfigspace/evaluation.py | 16 ++--- .../cconfigspace/features_evaluation.py | 16 ++--- .../python/cconfigspace/tree_evaluation.py | 16 ++--- bindings/python/test/test_evaluation.py | 20 +++--- bindings/python/test/test_tree_evaluation.py | 20 +++--- bindings/ruby/lib/cconfigspace/binding.rb | 44 ++---------- bindings/ruby/lib/cconfigspace/evaluation.rb | 20 +++--- .../lib/cconfigspace/features_evaluation.rb | 20 +++--- .../ruby/lib/cconfigspace/tree_evaluation.rb | 20 +++--- bindings/ruby/test/test_evaluation.rb | 4 +- bindings/ruby/test/test_tree_evaluation.rb | 4 +- include/cconfigspace/binding.h | 72 ------------------- include/cconfigspace/configuration.h | 22 ------ include/cconfigspace/evaluation.h | 40 ----------- include/cconfigspace/features.h | 20 ------ include/cconfigspace/features_evaluation.h | 40 ----------- include/cconfigspace/tree_evaluation.h | 40 ----------- src/binding.c | 42 ----------- src/binding_internal.h | 62 ---------------- src/configuration.c | 37 +++++----- src/configuration_internal.h | 7 ++ src/configuration_space.c | 6 +- src/evaluation.c | 22 ------ src/features.c | 9 --- src/features_evaluation.c | 22 ------ src/tree_evaluation.c | 22 ------ tests/test_features_space.c | 10 ++- 28 files changed, 118 insertions(+), 584 deletions(-) diff --git a/bindings/python/cconfigspace/binding.py b/bindings/python/cconfigspace/binding.py index 667efb00..8ae28f9e 100644 --- a/bindings/python/cconfigspace/binding.py +++ b/bindings/python/cconfigspace/binding.py @@ -4,13 +4,9 @@ ccs_binding_get_context = _ccs_get_function("ccs_binding_get_context", [ccs_binding, ct.POINTER(ccs_context)]) ccs_binding_get_value = _ccs_get_function("ccs_binding_get_value", [ccs_binding, ct.c_size_t, ct.POINTER(Datum)]) -ccs_binding_set_value = _ccs_get_function("ccs_binding_set_value", [ccs_binding, ct.c_size_t, DatumFix]) ccs_binding_get_values = _ccs_get_function("ccs_binding_get_values", [ccs_binding, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) -ccs_binding_set_values = _ccs_get_function("ccs_binding_set_values", [ccs_binding, ct.c_size_t, ct.POINTER(Datum)]) ccs_binding_get_value_by_name = _ccs_get_function("ccs_binding_get_value_by_name", [ccs_binding, ct.c_char_p, ct.POINTER(Datum)]) -ccs_binding_set_value_by_name = _ccs_get_function("ccs_binding_set_value_by_name", [ccs_binding, ct.c_char_p, DatumFix]) ccs_binding_get_value_by_parameter = _ccs_get_function("ccs_binding_get_value_by_parameter", [ccs_binding, ccs_parameter, ct.POINTER(Datum)]) -ccs_binding_set_value_by_parameter = _ccs_get_function("ccs_binding_set_value_by_parameter", [ccs_binding, ccs_parameter, DatumFix]) ccs_binding_hash = _ccs_get_function("ccs_binding_hash", [ccs_binding, ct.POINTER(ccs_hash)]) ccs_binding_cmp = _ccs_get_function("ccs_binding_cmp", [ccs_binding, ccs_binding, ct.POINTER(ct.c_int)]) @@ -36,17 +32,6 @@ def num_values(self): self._num_values = v.value return self._num_values - def set_value(self, parameter, value): - pv = Datum(value) - v = DatumFix(pv) - if isinstance(parameter, Parameter): - res = ccs_binding_set_value_by_parameter(self.handle, parameter.handle, v) - elif isinstance(parameter, str): - res = ccs_binding_set_value_by_name(self.handle, str.encode(parameter), ct.byref(v)) - else: - res = ccs_binding_set_value(self.handle, parameter, v) - Error.check(res) - def value(self, parameter): v = Datum() if isinstance(parameter, Parameter): @@ -60,22 +45,16 @@ def value(self, parameter): @property def values(self): + if hasattr(self, "_values"): + return self._values sz = self.num_values if sz == 0: return [] v = (Datum * sz)() res = ccs_binding_get_values(self.handle, sz, v, None) Error.check(res) - return [x.value for x in v] - - def set_values(self, values): - sz = len(values) - v = (Datum*sz)() - ss = [] - for i in range(sz): - v[i].set_value(values[i], string_store = ss) - res = ccs_binding_set_values(self.handle, sz, v) - Error.check(res) + self._values = tuple(x.value for x in v) + return self._values def cmp(self, other): v = ct.c_int() diff --git a/bindings/python/cconfigspace/evaluation.py b/bindings/python/cconfigspace/evaluation.py index ea3ad9f5..3c64b05a 100644 --- a/bindings/python/cconfigspace/evaluation.py +++ b/bindings/python/cconfigspace/evaluation.py @@ -15,7 +15,6 @@ class Comparison(CEnumeration): ccs_evaluation_get_objective_space = _ccs_get_function("ccs_evaluation_get_objective_space", [ccs_evaluation, ct.POINTER(ccs_objective_space)]) ccs_evaluation_get_configuration = _ccs_get_function("ccs_evaluation_get_configuration", [ccs_evaluation, ct.POINTER(ccs_configuration)]) ccs_evaluation_get_result = _ccs_get_function("ccs_evaluation_get_result", [ccs_evaluation, ct.POINTER(ccs_evaluation_result)]) -ccs_evaluation_set_result = _ccs_get_function("ccs_evaluation_set_result", [ccs_evaluation, ccs_evaluation_result]) ccs_evaluation_get_objective_value = _ccs_get_function("ccs_evaluation_get_objective_value", [ccs_evaluation, ct.c_size_t, ct.POINTER(Datum)]) ccs_evaluation_get_objective_values = _ccs_get_function("ccs_evaluation_get_objective_values", [ccs_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) ccs_evaluation_compare = _ccs_get_function("ccs_evaluation_compare", [ccs_evaluation, ccs_evaluation, ct.POINTER(Comparison)]) @@ -67,15 +66,13 @@ def configuration(self): @property def result(self): + if hasattr(self, "_result"): + return self._result v = ccs_evaluation_result() res = ccs_evaluation_get_result(self.handle, ct.byref(v)) Error.check(res) - return v.value - - @result.setter - def result(self, v): - res = ccs_evaluation_set_result(self.handle, v) - Error.check(res) + self._result = v.value + return self._result @property def num_objective_values(self): @@ -89,13 +86,16 @@ def num_objective_values(self): @property def objective_values(self): + if hasattr(self, "_objective_values"): + return self._objective_values sz = self.num_objective_values if sz == 0: return [] v = (Datum * sz)() res = ccs_evaluation_get_objective_values(self.handle, sz, v, None) Error.check(res) - return [x.value for x in v] + self._objective_values = tuple(x.value for x in v) + return self._objective_values def compare(self, other): v = Comparison(0) diff --git a/bindings/python/cconfigspace/features_evaluation.py b/bindings/python/cconfigspace/features_evaluation.py index 0ac43dd0..e786b180 100644 --- a/bindings/python/cconfigspace/features_evaluation.py +++ b/bindings/python/cconfigspace/features_evaluation.py @@ -15,7 +15,6 @@ ccs_features_evaluation_get_configuration = _ccs_get_function("ccs_features_evaluation_get_configuration", [ccs_features_evaluation, ct.POINTER(ccs_configuration)]) ccs_features_evaluation_get_features = _ccs_get_function("ccs_features_evaluation_get_features", [ccs_features_evaluation, ct.POINTER(ccs_features)]) ccs_features_evaluation_get_result = _ccs_get_function("ccs_features_evaluation_get_result", [ccs_features_evaluation, ct.POINTER(ccs_evaluation_result)]) -ccs_features_evaluation_set_result = _ccs_get_function("ccs_features_evaluation_set_result", [ccs_features_evaluation, ccs_evaluation_result]) ccs_features_evaluation_get_objective_value = _ccs_get_function("ccs_features_evaluation_get_objective_value", [ccs_features_evaluation, ct.c_size_t, ct.POINTER(Datum)]) ccs_features_evaluation_get_objective_values = _ccs_get_function("ccs_features_evaluation_get_objective_values", [ccs_features_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) ccs_features_evaluation_compare = _ccs_get_function("ccs_features_evaluation_compare", [ccs_features_evaluation, ccs_features_evaluation, ct.POINTER(Comparison)]) @@ -77,15 +76,13 @@ def features(self): @property def result(self): + if hasattr(self, "_result"): + return self._result v = ccs_evaluation_result() res = ccs_features_evaluation_get_result(self.handle, ct.byref(v)) Error.check(res) - return v.value - - @result.setter - def result(self, v): - res = ccs_features_evaluation_set_result(self.handle, v) - Error.check(res) + self._result = v.value + return self._result @property def num_objective_values(self): @@ -99,13 +96,16 @@ def num_objective_values(self): @property def objective_values(self): + if hasattr(self, "_objective_values"): + return self._objective_values sz = self.num_objective_values if sz == 0: return [] v = (Datum * sz)() res = ccs_features_evaluation_get_objective_values(self.handle, sz, v, None) Error.check(res) - return [x.value for x in v] + self._objective_values = tuple(x.value for x in v) + return self._objective_values def compare(self, other): v = Comparison(0) diff --git a/bindings/python/cconfigspace/tree_evaluation.py b/bindings/python/cconfigspace/tree_evaluation.py index c3f0f8be..bc7a7223 100644 --- a/bindings/python/cconfigspace/tree_evaluation.py +++ b/bindings/python/cconfigspace/tree_evaluation.py @@ -9,7 +9,6 @@ ccs_tree_evaluation_get_objective_space = _ccs_get_function("ccs_tree_evaluation_get_objective_space", [ccs_tree_evaluation, ct.POINTER(ccs_objective_space)]) ccs_tree_evaluation_get_configuration = _ccs_get_function("ccs_tree_evaluation_get_configuration", [ccs_tree_evaluation, ct.POINTER(ccs_tree_configuration)]) ccs_tree_evaluation_get_result = _ccs_get_function("ccs_tree_evaluation_get_result", [ccs_tree_evaluation, ct.POINTER(ccs_evaluation_result)]) -ccs_tree_evaluation_set_result = _ccs_get_function("ccs_tree_evaluation_set_result", [ccs_tree_evaluation, ccs_evaluation_result]) ccs_tree_evaluation_get_objective_value = _ccs_get_function("ccs_tree_evaluation_get_objective_value", [ccs_tree_evaluation, ct.c_size_t, ct.POINTER(Datum)]) ccs_tree_evaluation_get_objective_values = _ccs_get_function("ccs_tree_evaluation_get_objective_values", [ccs_tree_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) ccs_tree_evaluation_compare = _ccs_get_function("ccs_tree_evaluation_compare", [ccs_tree_evaluation, ccs_tree_evaluation, ct.POINTER(Comparison)]) @@ -61,15 +60,13 @@ def configuration(self): @property def result(self): + if hasattr(self, "_result"): + return self._result v = ccs_evaluation_result() res = ccs_tree_evaluation_get_result(self.handle, ct.byref(v)) Error.check(res) - return v.value - - @result.setter - def result(self, v): - res = ccs_tree_evaluation_set_result(self.handle, v) - Error.check(res) + self._result = v.value + return self._result @property def num_objective_values(self): @@ -83,13 +80,16 @@ def num_objective_values(self): @property def objective_values(self): + if hasattr(self, "_objective_values"): + return self._objective_values sz = self.num_objective_values if sz == 0: return [] v = (Datum * sz)() res = ccs_tree_evaluation_get_objective_values(self.handle, sz, v, None) Error.check(res) - return [x.value for x in v] + self._objective_values = tuple(x.value for x in v) + return self._objective_values def compare(self, other): v = Comparison(0) diff --git a/bindings/python/test/test_evaluation.py b/bindings/python/test/test_evaluation.py index 00ebf0fb..6133fdc1 100644 --- a/bindings/python/test/test_evaluation.py +++ b/bindings/python/test/test_evaluation.py @@ -17,23 +17,21 @@ def test_create(self): e1 = ccs.Expression.Variable(parameter = v1) e2 = ccs.Expression.Variable(parameter = v2) os.add_objectives( { e1: ccs.ObjectiveType.MAXIMIZE, e2: ccs.ObjectiveType.MINIMIZE } ) - ev1 = ccs.Evaluation(objective_space = os, configuration = cs.sample()) - ev1.set_value(0, 0.5) - ev1.set_value(v2, 0.6) - self.assertEqual( [0.5, 0.6], ev1.values ) - self.assertEqual( [0.5, 0.6], ev1.objective_values ) + ev1 = ccs.Evaluation(objective_space = os, configuration = cs.sample(), values = [0.5, 0.6]) + self.assertEqual( (0.5, 0.6), ev1.values ) + self.assertEqual( (0.5, 0.6), ev1.objective_values ) self.assertTrue( ev1.check ) self.assertTrue( os.check_values(ev1.values) ) ev2 = ccs.Evaluation(objective_space = os, configuration = cs.sample(), values = [0.5, 0.6]) - self.assertEqual( [0.5, 0.6], ev2.values ) - self.assertEqual( [0.5, 0.6], ev2.objective_values ) + self.assertEqual( (0.5, 0.6), ev2.values ) + self.assertEqual( (0.5, 0.6), ev2.objective_values ) self.assertEqual( ccs.Comparison.EQUIVALENT, ev1.compare(ev2) ) ev3 = ccs.Evaluation(objective_space = os, configuration = cs.sample(), values = [0.6, 0.5]) - self.assertEqual( [0.6, 0.5], ev3.objective_values ) + self.assertEqual( (0.6, 0.5), ev3.objective_values ) self.assertEqual( ccs.Comparison.WORSE, ev1.compare(ev3) ) self.assertEqual( ccs.Comparison.BETTER, ev3.compare(ev1) ) ev4 = ccs.Evaluation(objective_space = os, configuration = cs.sample(), values = [0.6, 0.7]) - self.assertEqual( [0.6, 0.7], ev4.objective_values ) + self.assertEqual( (0.6, 0.7), ev4.objective_values ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev1.compare(ev4) ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev4.compare(ev1) ) @@ -56,8 +54,8 @@ def test_serialize(self): ev = ccs.deserialize(buffer = buff, handle_map = handle_map) self.assertEqual( cs.handle.value, ev.configuration.configuration_space.handle.value) self.assertEqual( os.handle.value, ev.objective_space.handle.value) - self.assertEqual( [0.5, 0.6], ev.values ) - self.assertEqual( [0.5, 0.6], ev.objective_values ) + self.assertEqual( (0.5, 0.6), ev.values ) + self.assertEqual( (0.5, 0.6), ev.objective_values ) if __name__ == '__main__': unittest.main() diff --git a/bindings/python/test/test_tree_evaluation.py b/bindings/python/test/test_tree_evaluation.py index 8a8335a1..f5a6acb6 100644 --- a/bindings/python/test/test_tree_evaluation.py +++ b/bindings/python/test/test_tree_evaluation.py @@ -24,23 +24,21 @@ def test_create(self): e1 = ccs.Expression.Variable(parameter = v1) e2 = ccs.Expression.Variable(parameter = v2) os.add_objectives( { e1: ccs.ObjectiveType.MAXIMIZE, e2: ccs.ObjectiveType.MINIMIZE } ) - ev1 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample()) - ev1.set_value(0, 0.5) - ev1.set_value(v2, 0.6) - self.assertEqual( [0.5, 0.6], ev1.values ) - self.assertEqual( [0.5, 0.6], ev1.objective_values ) + ev1 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) + self.assertEqual( (0.5, 0.6), ev1.values ) + self.assertEqual( (0.5, 0.6), ev1.objective_values ) self.assertTrue( ev1.check ) self.assertTrue( os.check_values(ev1.values) ) ev2 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) - self.assertEqual( [0.5, 0.6], ev2.values ) - self.assertEqual( [0.5, 0.6], ev2.objective_values ) + self.assertEqual( (0.5, 0.6), ev2.values ) + self.assertEqual( (0.5, 0.6), ev2.objective_values ) self.assertEqual( ccs.Comparison.EQUIVALENT, ev1.compare(ev2) ) ev3 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.5]) - self.assertEqual( [0.6, 0.5], ev3.objective_values ) + self.assertEqual( (0.6, 0.5), ev3.objective_values ) self.assertEqual( ccs.Comparison.WORSE, ev1.compare(ev3) ) self.assertEqual( ccs.Comparison.BETTER, ev3.compare(ev1) ) ev4 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.7]) - self.assertEqual( [0.6, 0.7], ev4.objective_values ) + self.assertEqual( (0.6, 0.7), ev4.objective_values ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev1.compare(ev4) ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev4.compare(ev1) ) @@ -61,8 +59,8 @@ def test_serialize(self): ev = ccs.deserialize(buffer = buff, handle_map = handle_map) self.assertEqual( ts.handle.value, ev.configuration.tree_space.handle.value) self.assertEqual( os.handle.value, ev.objective_space.handle.value) - self.assertEqual( [0.5, 0.6], ev.values ) - self.assertEqual( [0.5, 0.6], ev.objective_values ) + self.assertEqual( (0.5, 0.6), ev.values ) + self.assertEqual( (0.5, 0.6), ev.objective_values ) if __name__ == '__main__': unittest.main() diff --git a/bindings/ruby/lib/cconfigspace/binding.rb b/bindings/ruby/lib/cconfigspace/binding.rb index 0dd8221e..c822774e 100644 --- a/bindings/ruby/lib/cconfigspace/binding.rb +++ b/bindings/ruby/lib/cconfigspace/binding.rb @@ -1,13 +1,9 @@ module CCS attach_function :ccs_binding_get_context, [:ccs_binding_t, :pointer], :ccs_result_t attach_function :ccs_binding_get_value, [:ccs_binding_t, :size_t, :pointer], :ccs_result_t - attach_function :ccs_binding_set_value, [:ccs_binding_t, :size_t, :ccs_datum_t], :ccs_result_t attach_function :ccs_binding_get_values, [:ccs_binding_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_binding_set_values, [:ccs_binding_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_binding_get_value_by_name, [:ccs_binding_t, :string, :pointer], :ccs_result_t - attach_function :ccs_binding_set_value_by_name, [:ccs_binding_t, :string, :ccs_datum_t], :ccs_result_t attach_function :ccs_binding_get_value_by_parameter, [:ccs_binding_t, :ccs_parameter_t, :pointer], :ccs_result_t - attach_function :ccs_binding_set_value_by_parameter, [:ccs_binding_t, :ccs_parameter_t, :ccs_datum_t], :ccs_result_t attach_function :ccs_binding_hash, [:ccs_binding_t, :pointer], :ccs_result_t attach_function :ccs_binding_cmp, [:ccs_binding_t, :ccs_binding_t, :pointer], :ccs_result_t @@ -16,24 +12,6 @@ class Binding < Object add_property :hash, :ccs_hash_t, :ccs_binding_hash, memoize: false add_handle_property :context, :ccs_context_t, :ccs_binding_get_context, memoize: true - def set_value(parameter, value) - d = Datum.from_value(value) - case parameter - when String - CCS.error_check CCS.ccs_binding_set_value_by_name(@handle, parameter, d) - when Symbol - name = parameter.inspect - CCS.error_check CCS.ccs_binding_set_value_by_name(@handle, name, d) - when Parameter - CCS.error_check CCS.ccs_binding_set_value_by_parameter(@handle, parameter.handle, d) - when Integer - CCS.error_check CCS.ccs_binding_set_value(@handle, parameter, d) - else - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE - end - self - end - def value(parameter) ptr = MemoryPointer::new(:ccs_datum_t) case parameter @@ -53,21 +31,13 @@ def value(parameter) end def values - count = num_values - return [] if count == 0 - values = MemoryPointer::new(:ccs_datum_t, count) - CCS.error_check CCS.ccs_binding_get_values(@handle, count, values, nil) - count.times.collect { |i| Datum::new(values[i]).value } - end - - def set_values(values) - count = values.size - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if count == 0 - ss = [] - vals = MemoryPointer::new(:ccs_datum_t, count) - values.each_with_index{ |v, i| Datum::new(vals[i]).set_value(v, string_store: ss) } - CCS.error_check CCS.ccs_binding_set_values(@handle, count, vals) - self + @values ||= begin + count = num_values + return [] if count == 0 + values = MemoryPointer::new(:ccs_datum_t, count) + CCS.error_check CCS.ccs_binding_get_values(@handle, count, values, nil) + count.times.collect { |i| Datum::new(values[i]).value }.freeze + end end def num_values diff --git a/bindings/ruby/lib/cconfigspace/evaluation.rb b/bindings/ruby/lib/cconfigspace/evaluation.rb index bd5b09ad..57386395 100644 --- a/bindings/ruby/lib/cconfigspace/evaluation.rb +++ b/bindings/ruby/lib/cconfigspace/evaluation.rb @@ -14,7 +14,6 @@ def read_ccs_comparison_t attach_function :ccs_create_evaluation, [:ccs_objective_space_t, :ccs_configuration_t, :ccs_evaluation_result_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_evaluation_get_configuration, [:ccs_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_evaluation_get_result, [:ccs_evaluation_t, :pointer], :ccs_result_t - attach_function :ccs_evaluation_set_result, [:ccs_evaluation_t, :ccs_evaluation_result_t], :ccs_result_t attach_function :ccs_evaluation_get_objective_values, [:ccs_evaluation_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_evaluation_compare, [:ccs_evaluation_t, :ccs_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_evaluation_check, [:ccs_evaluation_t, :pointer], :ccs_result_t @@ -22,7 +21,7 @@ def read_ccs_comparison_t class Evaluation < Binding alias objective_space context add_handle_property :configuration, :ccs_configuration_t, :ccs_evaluation_get_configuration, memoize: true - add_property :result, :ccs_evaluation_result_t, :ccs_evaluation_get_result, memoize: false + add_property :result, :ccs_evaluation_result_t, :ccs_evaluation_get_result, memoize: true def initialize(handle = nil, retain: false, auto_release: true, objective_space: nil, configuration: nil, result: :CCS_RESULT_SUCCESS, values: nil) @@ -51,11 +50,6 @@ def self.from_handle(handle, retain: true, auto_release: true) self::new(handle, retain: retain, auto_release: auto_release) end - def result=(res) - CCS.error_check CCS.ccs_evaluation_set_result(@handle, res) - res - end - def num_objective_values @num_objective_values ||= begin ptr = MemoryPointer::new(:size_t) @@ -65,11 +59,13 @@ def num_objective_values end def objective_values - count = num_objective_values - return [] if count == 0 - values = MemoryPointer::new(:ccs_datum_t, count) - CCS.error_check CCS.ccs_evaluation_get_objective_values(@handle, count, values, nil) - count.times.collect { |i| Datum::new(values[i]).value } + @objective_values ||= begin + count = num_objective_values + return [] if count == 0 + values = MemoryPointer::new(:ccs_datum_t, count) + CCS.error_check CCS.ccs_evaluation_get_objective_values(@handle, count, values, nil) + count.times.collect { |i| Datum::new(values[i]).value }.freeze + end end def check diff --git a/bindings/ruby/lib/cconfigspace/features_evaluation.rb b/bindings/ruby/lib/cconfigspace/features_evaluation.rb index d8ca4a39..793d258d 100644 --- a/bindings/ruby/lib/cconfigspace/features_evaluation.rb +++ b/bindings/ruby/lib/cconfigspace/features_evaluation.rb @@ -3,7 +3,6 @@ module CCS attach_function :ccs_features_evaluation_get_configuration, [:ccs_features_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_features_evaluation_get_features, [:ccs_features_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_features_evaluation_get_result, [:ccs_features_evaluation_t, :pointer], :ccs_result_t - attach_function :ccs_features_evaluation_set_result, [:ccs_features_evaluation_t, :ccs_evaluation_result_t], :ccs_result_t attach_function :ccs_features_evaluation_get_objective_value, [:ccs_features_evaluation_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_features_evaluation_get_objective_values, [:ccs_features_evaluation_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_features_evaluation_compare, [:ccs_features_evaluation_t, :ccs_features_evaluation_t, :pointer], :ccs_result_t @@ -12,7 +11,7 @@ class FeaturesEvaluation < Binding alias objective_space context add_handle_property :configuration, :ccs_configuration_t, :ccs_features_evaluation_get_configuration, memoize: true add_handle_property :features, :ccs_features_t, :ccs_features_evaluation_get_features, memoize: true - add_property :result, :ccs_evaluation_result_t, :ccs_features_evaluation_get_result, memoize: false + add_property :result, :ccs_evaluation_result_t, :ccs_features_evaluation_get_result, memoize: true def initialize(handle = nil, retain: false, auto_release: true, objective_space: nil, configuration: nil, features: nil, result: :CCS_RESULT_SUCCESS, values: nil) @@ -42,11 +41,6 @@ def self.from_handle(handle, retain: true, auto_release: true) self::new(handle, retain: retain, auto_release: auto_release) end - def result=(res) - CCS.error_check CCS.ccs_features_evaluation_set_result(@handle, res) - res - end - def num_objective_values @num_objective_values ||= begin ptr = MemoryPointer::new(:size_t) @@ -56,11 +50,13 @@ def num_objective_values end def objective_values - count = num_objective_values - return [] if count == 0 - values = MemoryPointer::new(:ccs_datum_t, count) - CCS.error_check CCS.ccs_features_evaluation_get_objective_values(@handle, count, values, nil) - count.times.collect { |i| Datum::new(values[i]).value } + @objective_values ||= begin + count = num_objective_values + return [] if count == 0 + values = MemoryPointer::new(:ccs_datum_t, count) + CCS.error_check CCS.ccs_features_evaluation_get_objective_values(@handle, count, values, nil) + count.times.collect { |i| Datum::new(values[i]).value }.freeze + end end def check diff --git a/bindings/ruby/lib/cconfigspace/tree_evaluation.rb b/bindings/ruby/lib/cconfigspace/tree_evaluation.rb index b3bed16d..83d1ec33 100644 --- a/bindings/ruby/lib/cconfigspace/tree_evaluation.rb +++ b/bindings/ruby/lib/cconfigspace/tree_evaluation.rb @@ -3,7 +3,6 @@ module CCS attach_function :ccs_create_tree_evaluation, [:ccs_objective_space_t, :ccs_tree_configuration_t, :ccs_evaluation_result_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_tree_evaluation_get_configuration, [:ccs_tree_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_tree_evaluation_get_result, [:ccs_tree_evaluation_t, :pointer], :ccs_result_t - attach_function :ccs_tree_evaluation_set_result, [:ccs_tree_evaluation_t, :ccs_evaluation_result_t], :ccs_result_t attach_function :ccs_tree_evaluation_get_objective_values, [:ccs_tree_evaluation_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_tree_evaluation_compare, [:ccs_tree_evaluation_t, :ccs_tree_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_tree_evaluation_check, [:ccs_tree_evaluation_t, :pointer], :ccs_result_t @@ -11,7 +10,7 @@ module CCS class TreeEvaluation < Binding alias objective_space context add_handle_property :configuration, :ccs_tree_configuration_t, :ccs_tree_evaluation_get_configuration, memoize: true - add_property :result, :ccs_evaluation_result_t, :ccs_tree_evaluation_get_result, memoize: false + add_property :result, :ccs_evaluation_result_t, :ccs_tree_evaluation_get_result, memoize: true def initialize(handle = nil, retain: false, auto_release: true, objective_space: nil, configuration: nil, result: :CCS_RESULT_SUCCESS, values: nil) @@ -40,11 +39,6 @@ def self.from_handle(handle, retain: true, auto_release: true) self::new(handle, retain: retain, auto_release: auto_release) end - def result=(res) - CCS.error_check CCS.ccs_tree_evaluation_set_result(@handle, res) - res - end - def num_objective_values @num_objective_values ||= begin ptr = MemoryPointer::new(:size_t) @@ -54,11 +48,13 @@ def num_objective_values end def objective_values - count = num_objective_values - return [] if count == 0 - values = MemoryPointer::new(:ccs_datum_t, count) - CCS.error_check CCS.ccs_tree_evaluation_get_objective_values(@handle, count, values, nil) - count.times.collect { |i| Datum::new(values[i]).value } + @objective_values ||= begin + count = num_objective_values + return [] if count == 0 + values = MemoryPointer::new(:ccs_datum_t, count) + CCS.error_check CCS.ccs_tree_evaluation_get_objective_values(@handle, count, values, nil) + count.times.collect { |i| Datum::new(values[i]).value }.freeze + end end def check diff --git a/bindings/ruby/test/test_evaluation.rb b/bindings/ruby/test/test_evaluation.rb index c90d8737..11008bde 100644 --- a/bindings/ruby/test/test_evaluation.rb +++ b/bindings/ruby/test/test_evaluation.rb @@ -17,9 +17,7 @@ def test_create e1 = CCS::Expression::Variable::new(parameter: v1) e2 = CCS::Expression::Variable::new(parameter: v2) os.add_objectives( { e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE, e2 => :CCS_OBJECTIVE_TYPE_MINIMIZE } ) - ev1 = CCS::Evaluation::new(objective_space: os, configuration: cs.sample) - ev1.set_value(0, 0.5) - ev1.set_value(v2, 0.6) + ev1 = CCS::Evaluation::new(objective_space: os, configuration: cs.sample, values: [0.5, 0.6]) assert_equal( [0.5, 0.6], ev1.values ) assert_equal( [0.5, 0.6], ev1.objective_values ) assert( ev1.check ) diff --git a/bindings/ruby/test/test_tree_evaluation.rb b/bindings/ruby/test/test_tree_evaluation.rb index fdae0385..38da7149 100644 --- a/bindings/ruby/test/test_tree_evaluation.rb +++ b/bindings/ruby/test/test_tree_evaluation.rb @@ -27,9 +27,7 @@ def test_create e1 = CCS::Expression::Variable.new(parameter: v1) e2 = CCS::Expression::Variable.new(parameter: v2) os.add_objectives( { e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE, e2 => :CCS_OBJECTIVE_TYPE_MINIMIZE } ) - ev1 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample) - ev1.set_value(0, 0.5) - ev1.set_value(v2, 0.6) + ev1 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) assert_equal( [0.5, 0.6], ev1.values ) assert_equal( [0.5, 0.6], ev1.objective_values ) assert( ev1.check ) diff --git a/include/cconfigspace/binding.h b/include/cconfigspace/binding.h index a7e8b553..3aea6f08 100644 --- a/include/cconfigspace/binding.h +++ b/include/cconfigspace/binding.h @@ -42,24 +42,6 @@ ccs_binding_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] binding - * @param[in] index index of the parameter in the associated context - * @param[in] value the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * object - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the context - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - */ -extern ccs_result_t -ccs_binding_set_value(ccs_binding_t binding, size_t index, ccs_datum_t value); - /** * Get all the values in the binding. * @param[in] binding @@ -85,26 +67,6 @@ ccs_binding_get_values( ccs_datum_t *values, size_t *num_values_ret); -/** - * Set all the values in the binding. - * @param[in,out] binding - * @param[in] num_values the size of the \p values array - * @param[in] values an array of size \p num_values - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * object - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p num_values is not equal to the number - * of values in the binding - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - */ -extern ccs_result_t -ccs_binding_set_values( - ccs_binding_t binding, - size_t num_values, - ccs_datum_t *values); - /** * Get the value of the parameter with the given name. * @param[in] binding @@ -123,23 +85,6 @@ ccs_binding_get_value_by_name( const char *name, ccs_datum_t *value_ret); -/** - * Set the value of the parameter with the given name. - * @param[in,out] binding - * @param[in] name the name of the parameter whose value to set - * @param[in] value the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * object - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p binding context - */ -extern ccs_result_t -ccs_binding_set_value_by_name( - ccs_binding_t binding, - const char *name, - ccs_datum_t value); - /** * Get the value of the parameter with the given handle. * @param[in] binding @@ -157,23 +102,6 @@ ccs_binding_get_value_by_parameter( ccs_parameter_t parameter, ccs_datum_t *value_ret); -/** - * Set the value of the parameter with the given handle. - * @param[in,out] binding - * @param[in] parameter parameter whose value to set - * @param[in] value the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * object - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p parameter does not exist in - * the \p binding context - */ -extern ccs_result_t -ccs_binding_set_value_by_parameter( - ccs_binding_t binding, - ccs_parameter_t parameter, - ccs_datum_t value); - /** * Compute a hash value for the binding by hashing together the context * reference, the number of values, and the values themselves. diff --git a/include/cconfigspace/configuration.h b/include/cconfigspace/configuration.h index 5510e175..7baa09b6 100644 --- a/include/cconfigspace/configuration.h +++ b/include/cconfigspace/configuration.h @@ -71,28 +71,6 @@ ccs_configuration_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] configuration - * @param[in] index index of the parameter in the associated configuration - * space - * @param[in] value the value - * @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 value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the configuration space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - */ -extern ccs_result_t -ccs_configuration_set_value( - ccs_configuration_t configuration, - size_t index, - ccs_datum_t value); - /** * Get all the values in the configuration. * @param[in] configuration diff --git a/include/cconfigspace/evaluation.h b/include/cconfigspace/evaluation.h index 3322bf15..b9addc0b 100644 --- a/include/cconfigspace/evaluation.h +++ b/include/cconfigspace/evaluation.h @@ -120,22 +120,6 @@ ccs_evaluation_get_result( ccs_evaluation_t evaluation, ccs_evaluation_result_t *result_ret); -/** - * Set the result code associated with an evaluation. A successful - * evaluation should have it's error set to #CCS_RESULT_SUCCESS. - * @param[in,out] evaluation - * @param[in] result the result code associated withe the evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_evaluation_set_result( - ccs_evaluation_t evaluation, - ccs_evaluation_result_t result); - /** * Get the value of the parameter at the given index. * @param[in] evaluation @@ -157,30 +141,6 @@ ccs_evaluation_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[in] value the value - * @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 value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_evaluation_set_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t value); - /** * Get all the values in an evaluation. * @param[in] evaluation diff --git a/include/cconfigspace/features.h b/include/cconfigspace/features.h index 0227d085..a46182fc 100644 --- a/include/cconfigspace/features.h +++ b/include/cconfigspace/features.h @@ -75,26 +75,6 @@ ccs_features_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] features - * @param[in] index index of the parameter in the associated features space - * @param[in] value the value - * @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_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the features space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_features_set_value(ccs_features_t features, size_t index, ccs_datum_t value); - /** * Get all the values in the features. * @param[in] features diff --git a/include/cconfigspace/features_evaluation.h b/include/cconfigspace/features_evaluation.h index 82a8ec30..654422db 100644 --- a/include/cconfigspace/features_evaluation.h +++ b/include/cconfigspace/features_evaluation.h @@ -118,22 +118,6 @@ ccs_features_evaluation_get_result( ccs_features_evaluation_t features_evaluation, ccs_evaluation_result_t *result_ret); -/** - * Set the result code associated with a features evaluation. A successful - * evaluation should have it's error set to #CCS_RESULT_SUCCESS. - * @param[in,out] features_evaluation - * @param[in] result the result code associated withe the features_evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_set_result( - ccs_features_evaluation_t features_evaluation, - ccs_evaluation_result_t result); - /** * Get the value of the parameter at the given index. * @param[in] features_evaluation @@ -155,30 +139,6 @@ ccs_features_evaluation_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] features_evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[in] value the value - * @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 value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_set_value( - ccs_features_evaluation_t features_evaluation, - size_t index, - ccs_datum_t value); - /** * Get all the values in a features evaluation. * @param[in] features_evaluation diff --git a/include/cconfigspace/tree_evaluation.h b/include/cconfigspace/tree_evaluation.h index cf3d90d8..17342ad0 100644 --- a/include/cconfigspace/tree_evaluation.h +++ b/include/cconfigspace/tree_evaluation.h @@ -98,22 +98,6 @@ ccs_tree_evaluation_get_result( ccs_tree_evaluation_t evaluation, ccs_evaluation_result_t *result_ret); -/** - * Set the result code associated with a tree evaluation. A successful - * evaluation should have it's error set to #CCS_RESULT_SUCCESS. - * @param[in,out] evaluation - * @param[in] result the result code associated withe the evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_set_result( - ccs_tree_evaluation_t evaluation, - ccs_evaluation_result_t result); - /** * Get the value of the parameter at the given index. * @param[in] evaluation @@ -135,30 +119,6 @@ ccs_tree_evaluation_get_value( size_t index, ccs_datum_t *value_ret); -/** - * Set the value of the parameter at the given index. Transient values will - * be validated and memoized if needed. - * @param[in,out] evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[in] value the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_set_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t value); - /** * Get all the values in a tree evaluation. * @param[in] evaluation diff --git a/src/binding.c b/src/binding.c index 6c2f7057..3c183338 100644 --- a/src/binding.c +++ b/src/binding.c @@ -32,14 +32,6 @@ ccs_binding_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_binding_set_value(ccs_binding_t binding, size_t index, ccs_datum_t value) -{ - CCS_CHECK_BINDING(binding); - CCS_VALIDATE(_ccs_binding_set_value(binding, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_binding_get_values( ccs_binding_t binding, @@ -53,17 +45,6 @@ ccs_binding_get_values( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_binding_set_values( - ccs_binding_t binding, - size_t num_values, - ccs_datum_t *values) -{ - CCS_CHECK_BINDING(binding); - CCS_VALIDATE(_ccs_binding_set_values(binding, num_values, values)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_binding_get_value_by_name( ccs_binding_t binding, @@ -75,17 +56,6 @@ ccs_binding_get_value_by_name( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_binding_set_value_by_name( - ccs_binding_t binding, - const char *name, - ccs_datum_t value) -{ - CCS_CHECK_BINDING(binding); - CCS_VALIDATE(_ccs_binding_set_value_by_name(binding, name, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_binding_get_value_by_parameter( ccs_binding_t binding, @@ -98,18 +68,6 @@ ccs_binding_get_value_by_parameter( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_binding_set_value_by_parameter( - ccs_binding_t binding, - ccs_parameter_t parameter, - ccs_datum_t value) -{ - CCS_CHECK_BINDING(binding); - CCS_VALIDATE( - _ccs_binding_set_value_by_parameter(binding, parameter, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret) { diff --git a/src/binding_internal.h b/src/binding_internal.h index f1ebd263..6b6f962a 100644 --- a/src/binding_internal.h +++ b/src/binding_internal.h @@ -49,19 +49,6 @@ _ccs_binding_get_value( return CCS_RESULT_SUCCESS; } -static inline ccs_result_t -_ccs_binding_set_value(ccs_binding_t binding, size_t index, ccs_datum_t value) -{ - CCS_REFUTE( - index >= binding->data->num_values, - CCS_RESULT_ERROR_OUT_OF_BOUNDS); - if (value.flags & CCS_DATUM_FLAG_TRANSIENT) - CCS_VALIDATE(ccs_context_validate_value( - binding->data->context, index, value, &value)); - binding->data->values[index] = value; - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _ccs_binding_get_values( ccs_binding_t binding, @@ -86,28 +73,6 @@ _ccs_binding_get_values( return CCS_RESULT_SUCCESS; } -static inline ccs_result_t -_ccs_binding_set_values( - ccs_binding_t binding, - size_t num_values, - ccs_datum_t *values) -{ - CCS_CHECK_ARY(num_values, values); - size_t num = binding->data->num_values; - CCS_REFUTE(num_values != num, CCS_RESULT_ERROR_INVALID_VALUE); - if (values) { - for (size_t i = 0; i < num_values; i++) { - ccs_datum_t value = values[i]; - if (value.flags & CCS_DATUM_FLAG_TRANSIENT) - CCS_VALIDATE(ccs_context_validate_value( - binding->data->context, i, value, - &value)); - binding->data->values[i] = value; - } - } - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _ccs_binding_get_value_by_name( ccs_binding_t binding, @@ -122,20 +87,6 @@ _ccs_binding_get_value_by_name( return CCS_RESULT_SUCCESS; } -static inline ccs_result_t -_ccs_binding_set_value_by_name( - ccs_binding_t binding, - const char *name, - ccs_datum_t value) -{ - CCS_CHECK_PTR(name); - size_t index; - CCS_VALIDATE(ccs_context_get_parameter_index_by_name( - binding->data->context, name, &index)); - CCS_VALIDATE(_ccs_binding_set_value(binding, index, value)); - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _ccs_binding_get_value_by_parameter( ccs_binding_t binding, @@ -149,19 +100,6 @@ _ccs_binding_get_value_by_parameter( return CCS_RESULT_SUCCESS; } -static inline ccs_result_t -_ccs_binding_set_value_by_parameter( - ccs_binding_t binding, - ccs_parameter_t parameter, - ccs_datum_t value) -{ - size_t index; - CCS_VALIDATE(ccs_context_get_parameter_index( - binding->data->context, parameter, &index)); - CCS_VALIDATE(_ccs_binding_set_value(binding, index, value)); - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _ccs_binding_hash(_ccs_binding_data_t *data, ccs_hash_t *hash_ret) { diff --git a/src/configuration.c b/src/configuration.c index d558a05e..7c4ae36d 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -84,15 +84,12 @@ static _ccs_configuration_ops_t _configuration_ops = { &_ccs_configuration_cmp}; ccs_result_t -ccs_create_configuration( +_ccs_create_configuration( ccs_configuration_space_t configuration_space, size_t num_values, ccs_datum_t *values, ccs_configuration_t *configuration_ret) { - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_CHECK_PTR(configuration_ret); - CCS_CHECK_ARY(num_values, values); ccs_result_t err; size_t num_parameters; CCS_VALIDATE(ccs_configuration_space_get_num_parameters( @@ -139,6 +136,26 @@ ccs_create_configuration( return err; } +ccs_result_t +ccs_create_configuration( + ccs_configuration_space_t configuration_space, + size_t num_values, + ccs_datum_t *values, + ccs_configuration_t *configuration_ret) +{ + CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + CCS_CHECK_PTR(configuration_ret); + CCS_CHECK_ARY(num_values, values); + size_t num_parameters; + CCS_VALIDATE(ccs_configuration_space_get_num_parameters( + configuration_space, &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)); + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_configuration_get_configuration_space( ccs_configuration_t configuration, @@ -163,18 +180,6 @@ ccs_configuration_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_configuration_set_value( - ccs_configuration_t configuration, - size_t index, - ccs_datum_t value) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_VALIDATE(_ccs_binding_set_value( - (ccs_binding_t)configuration, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_configuration_get_values( ccs_configuration_t configuration, diff --git a/src/configuration_internal.h b/src/configuration_internal.h index 96d17129..641e0833 100644 --- a/src/configuration_internal.h +++ b/src/configuration_internal.h @@ -29,4 +29,11 @@ struct _ccs_configuration_data_s { ccs_datum_t *values; }; +ccs_result_t +_ccs_create_configuration( + ccs_configuration_space_t configuration_space, + size_t num_values, + ccs_datum_t *values, + ccs_configuration_t *configuration_ret); + #endif //_CONFIGURATION_INTERNAL_H diff --git a/src/configuration_space.c b/src/configuration_space.c index 26563d6b..d9e8f8f6 100644 --- a/src/configuration_space.c +++ b/src/configuration_space.c @@ -902,7 +902,7 @@ ccs_configuration_space_get_default_configuration( CCS_RESULT_ERROR_INVALID_GRAPH); ccs_result_t err; ccs_configuration_t config; - CCS_VALIDATE(ccs_create_configuration( + CCS_VALIDATE(_ccs_create_configuration( configuration_space, 0, NULL, &config)); UT_array *array = configuration_space->data->parameters; _ccs_parameter_wrapper_cs_t *wrapper = NULL; @@ -1117,7 +1117,7 @@ ccs_configuration_space_sample( CCS_RESULT_ERROR_INVALID_GRAPH, errgraph); CCS_VALIDATE_ERR_GOTO( err, - ccs_create_configuration(configuration_space, 0, NULL, &config), + _ccs_create_configuration(configuration_space, 0, NULL, &config), errgraph); do { CCS_VALIDATE_ERR_GOTO( @@ -1164,7 +1164,7 @@ ccs_configuration_space_samples( if (!config) CCS_VALIDATE_ERR_GOTO( err, - ccs_create_configuration( + _ccs_create_configuration( configuration_space, 0, NULL, &config), errgraph); CCS_VALIDATE_ERR_GOTO( diff --git a/src/evaluation.c b/src/evaluation.c index acabf579..517d3daa 100644 --- a/src/evaluation.c +++ b/src/evaluation.c @@ -258,16 +258,6 @@ ccs_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_evaluation_set_result( - ccs_evaluation_t evaluation, - ccs_evaluation_result_t result) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - evaluation->data->result = result; - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_evaluation_get_value( ccs_evaluation_t evaluation, @@ -280,18 +270,6 @@ ccs_evaluation_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_evaluation_set_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t value) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(_ccs_binding_set_value( - (ccs_binding_t)evaluation, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_evaluation_get_values( ccs_evaluation_t evaluation, diff --git a/src/features.c b/src/features.c index 65831b86..e354cef4 100644 --- a/src/features.c +++ b/src/features.c @@ -162,15 +162,6 @@ ccs_features_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_features_set_value(ccs_features_t features, size_t index, ccs_datum_t value) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_VALIDATE( - _ccs_binding_set_value((ccs_binding_t)features, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_get_values( ccs_features_t features, diff --git a/src/features_evaluation.c b/src/features_evaluation.c index 7d2c1032..426f9c0a 100644 --- a/src/features_evaluation.c +++ b/src/features_evaluation.c @@ -299,16 +299,6 @@ ccs_features_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_features_evaluation_set_result( - ccs_features_evaluation_t evaluation, - ccs_evaluation_result_t result) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - evaluation->data->result = result; - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_evaluation_get_value( ccs_features_evaluation_t evaluation, @@ -321,18 +311,6 @@ ccs_features_evaluation_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_features_evaluation_set_value( - ccs_features_evaluation_t evaluation, - size_t index, - ccs_datum_t value) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(_ccs_binding_set_value( - (ccs_binding_t)evaluation, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_evaluation_get_values( ccs_features_evaluation_t evaluation, diff --git a/src/tree_evaluation.c b/src/tree_evaluation.c index c78232fc..2baf19a2 100644 --- a/src/tree_evaluation.c +++ b/src/tree_evaluation.c @@ -261,16 +261,6 @@ ccs_tree_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_tree_evaluation_set_result( - ccs_tree_evaluation_t evaluation, - ccs_evaluation_result_t result) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - evaluation->data->result = result; - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_tree_evaluation_get_value( ccs_tree_evaluation_t evaluation, @@ -283,18 +273,6 @@ ccs_tree_evaluation_get_value( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_tree_evaluation_set_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t value) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(_ccs_binding_set_value( - (ccs_binding_t)evaluation, index, value)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_tree_evaluation_get_values( ccs_tree_evaluation_t evaluation, diff --git a/tests/test_features_space.c b/tests/test_features_space.c index 3b42c88a..30bdd962 100644 --- a/tests/test_features_space.c +++ b/tests/test_features_space.c @@ -185,15 +185,21 @@ test_features() err = ccs_features_cmp(features1, features2, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(0 == cmp); + err = ccs_release_object(features2); + assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_set_value(features2, 1, ccs_float(0.5)); + values[1] = ccs_float(0.5); + err = ccs_create_features(features_space, 3, values, &features2); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_cmp(features1, features2, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(0 > cmp); + err = ccs_release_object(features2); + assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_set_value(features2, 1, ccs_float(10.0)); + values[1] = ccs_float(10.0); + err = ccs_create_features(features_space, 3, values, &features2); assert(err == CCS_RESULT_SUCCESS); err = ccs_features_check(features2, &check);