diff --git a/bindings/python/cconfigspace/configuration_space.py b/bindings/python/cconfigspace/configuration_space.py index 1325c1ca..6973df53 100644 --- a/bindings/python/cconfigspace/configuration_space.py +++ b/bindings/python/cconfigspace/configuration_space.py @@ -8,14 +8,12 @@ from .rng import Rng from parglare.parser import Context as PContext -ccs_create_configuration_space = _ccs_get_function("ccs_create_configuration_space", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_configuration_space)]) +ccs_create_configuration_space = _ccs_get_function("ccs_create_configuration_space", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_parameter), ct.c_size_t, ct.POINTER(ccs_expression), ct.POINTER(ccs_configuration_space)]) ccs_configuration_space_set_rng = _ccs_get_function("ccs_configuration_space_set_rng", [ccs_configuration_space, ccs_rng]) ccs_configuration_space_get_rng = _ccs_get_function("ccs_configuration_space_get_rng", [ccs_configuration_space, ct.POINTER(ccs_rng)]) ccs_configuration_space_set_condition = _ccs_get_function("ccs_configuration_space_set_condition", [ccs_configuration_space, ct.c_size_t, ccs_expression]) ccs_configuration_space_get_condition = _ccs_get_function("ccs_configuration_space_get_condition", [ccs_configuration_space, ct.c_size_t, ct.POINTER(ccs_expression)]) ccs_configuration_space_get_conditions = _ccs_get_function("ccs_configuration_space_get_conditions", [ccs_configuration_space, ct.c_size_t, ct.POINTER(ccs_expression), ct.POINTER(ct.c_size_t)]) -ccs_configuration_space_add_forbidden_clause = _ccs_get_function("ccs_configuration_space_add_forbidden_clause", [ccs_configuration_space, ccs_expression]) -ccs_configuration_space_add_forbidden_clauses = _ccs_get_function("ccs_configuration_space_add_forbidden_clauses", [ccs_configuration_space, ct.c_size_t, ccs_expression]) ccs_configuration_space_get_forbidden_clause = _ccs_get_function("ccs_configuration_space_get_forbidden_clause", [ccs_configuration_space, ct.c_size_t, ct.POINTER(ccs_expression)]) ccs_configuration_space_get_forbidden_clauses = _ccs_get_function("ccs_configuration_space_get_forbidden_clauses", [ccs_configuration_space, ct.c_size_t, ct.POINTER(ccs_expression), ct.POINTER(ct.c_size_t)]) ccs_configuration_space_check_configuration = _ccs_get_function("ccs_configuration_space_check_configuration", [ccs_configuration_space, ccs_configuration, ct.POINTER(ccs_bool)]) @@ -26,12 +24,23 @@ class ConfigurationSpace(Context): def __init__(self, handle = None, retain = False, auto_release = True, - name = "", parameters = None): + name = "", parameters = None, forbidden_clauses = None): if handle is None: count = len(parameters) + if forbidden_clauses is not None: + numfc = len(forbidden_clauses) + if numfc > 0: + ctx = dict(zip([x.name for x in parameters], parameters)) + fc_expressions = [ parser.parse(fc, context = PContext(extra=ctx)) if isinstance(fc, str) else fc for fc in forbidden_clauses ] + fcv = (ccs_expression * numfc)(*[x.handle.value for x in fc_expressions]) + else: + fcv = None + else: + numfc = 0 + fcv = None parameters = (ccs_parameter * count)(*[x.handle.value for x in parameters]) handle = ccs_configuration_space() - res = ccs_create_configuration_space(str.encode(name), count, parameters, ct.byref(handle)) + res = ccs_create_configuration_space(str.encode(name), count, parameters, numfc, fcv, ct.byref(handle)) Error.check(res) super().__init__(handle = handle, retain = False) else: @@ -100,21 +109,6 @@ def unconditional_parameters(self): conds = self.conditions return [x for x, y in zip(hps, conds) if y is None] - def add_forbidden_clause(self, expression): - if isinstance(expression, str): - expression = parser.parse(expression, context = PContext(extra=self)) - res = ccs_configuration_space_add_forbidden_clause(self.handle, expression.handle) - Error.check(res) - - def add_forbidden_clauses(self, expressions): - sz = len(expressions) - if sz == 0: - return None - expressions = [ parser.parse(expression, context = PContext(extra=self)) if isinstance(expression, str) else expression for expression in expressions ] - v = (ccs_expression * sz)(*[x.handle.value for x in expressions]) - res = ccs_configuration_space_add_forbidden_clauses(self.handle, sz, v) - Error.check(res) - def forbidden_clause(self, index): v = ccs_expression() res = ccs_configuration_space_get_forbidden_clause(self.handle, index, ct.byref(v)) @@ -123,18 +117,24 @@ def forbidden_clause(self, index): @property def num_forbidden_clauses(self): + if hasattr(self, "_num_forbidden_clauses"): + return self._num_forbidden_clauses v = ct.c_size_t() res = ccs_configuration_space_get_forbidden_clauses(self.handle, 0, None, ct.byref(v)) Error.check(res) - return v.value + self._num_forbidden_clauses = v.value + return self._num_forbidden_clauses @property def forbidden_clauses(self): + if hasattr(self, "_forbidden_clauses"): + return self._forbidden_clauses sz = self.num_forbidden_clauses v = (ccs_expression * sz)() res = ccs_configuration_space_get_forbidden_clauses(self.handle, sz, v, None) Error.check(res) - return [Expression.from_handle(ccs_expression(x)) for x in v] + self._forbidden_clauses = tuple(Expression.from_handle(ccs_expression(x)) for x in v) + return self._forbidden_clauses def check(self, configuration): valid = ccs_bool() diff --git a/bindings/python/test/test_configuration_space.py b/bindings/python/test/test_configuration_space.py index 2cef4cca..a95de053 100644 --- a/bindings/python/test/test_configuration_space.py +++ b/bindings/python/test/test_configuration_space.py @@ -17,7 +17,7 @@ def test_create(self): self.assertIsInstance( cs.rng, ccs.Rng ) self.assertEqual( 3, cs.num_parameters ) self.assertEqual( [None, None, None], cs.conditions ) - self.assertEqual( [], cs.forbidden_clauses ) + self.assertEqual( (), cs.forbidden_clauses ) self.assertEqual( h1, cs.parameter(0) ) self.assertEqual( h2, cs.parameter(1) ) self.assertEqual( h3, cs.parameter(2) ) @@ -60,13 +60,12 @@ def test_conditions(self): h1 = ccs.NumericalParameter.Float(lower = -1.0, upper = 1.0, default = 0.0) h2 = ccs.NumericalParameter.Float(lower = -1.0, upper = 1.0) h3 = ccs.NumericalParameter.Float(lower = -1.0, upper = 1.0) - cs = ccs.ConfigurationSpace(name = "space", parameters = [h1, h2, h3]) + f1 = ccs.Expression.Less(left = h1, right = 0.0) + cs = ccs.ConfigurationSpace(name = "space", parameters = [h1, h2, h3], forbidden_clauses = [f1]) e1 = ccs.Expression.Less(left = h2, right = 0.0) cs.set_condition(h3, e1) e2 = ccs.Expression.Less(left = h3, right = 0.0) cs.set_condition(h1, e2) - e3 = ccs.Expression.Less(left = h1, right = 0.0) - cs.add_forbidden_clause(e3) conditions = cs.conditions conditional_parameters = cs.conditional_parameters unconditional_parameters = cs.unconditional_parameters @@ -81,7 +80,7 @@ def test_conditions(self): self.assertEqual( h2.handle.value, unconditional_parameters[0].handle.value ) forbidden_clauses = cs.forbidden_clauses self.assertEqual( 1, len(forbidden_clauses) ) - self.assertEqual( e3.handle.value, forbidden_clauses[0].handle.value ) + self.assertEqual( f1.handle.value, forbidden_clauses[0].handle.value ) def extract_active_parameters(self, values): res = ['p1'] @@ -138,7 +137,15 @@ def test_omp(self): name = 'p9', values = ['1', '8', '16']) - cs = ccs.ConfigurationSpace(name = "omp", parameters = [p1, p2, p3, p4, p5, p6, p7, p8, p9]) + forbiddena = ccs.ExpressionEqual(left = p1, right = '#pragma omp #P2') + forbiddenb = ccs.ExpressionEqual(left = p2, right = ' ') + forbidden0 = ccs.Expression.And(left = forbiddena, right = forbiddenb) + + forbiddenc = ccs.Expression.Equal(left = p1, right = '#pragma omp #P3') + forbiddend = ccs.Expression.Equal(left = p3, right = ' ') + forbidden1 = ccs.Expression.And(left = forbiddenc, right = forbiddend) + + cs = ccs.ConfigurationSpace(name = "omp", parameters = [p1, p2, p3, p4, p5, p6, p7, p8, p9], forbidden_clauses = [forbidden0, forbidden1]) cond0 = ccs.Expression.Equal(left = p1, right = '#pragma omp #P2') cond1 = ccs.Expression.Equal(left = p1, right = '#pragma omp target teams distribute #P2') @@ -165,15 +172,6 @@ def test_omp(self): cs.set_condition(p8, ccs.Expression.Or(left = cond7, right = cond9)) cs.set_condition(p9, cond10) - forbiddena = ccs.ExpressionEqual(left = p1, right = '#pragma omp #P2') - forbiddenb = ccs.ExpressionEqual(left = p2, right = ' ') - forbidden0 = ccs.Expression.And(left = forbiddena, right = forbiddenb) - - forbiddenc = ccs.Expression.Equal(left = p1, right = '#pragma omp #P3') - forbiddend = ccs.Expression.Equal(left = p3, right = ' ') - forbidden1 = ccs.Expression.And(left = forbiddenc, right = forbiddend) - cs.add_forbidden_clauses([forbidden0, forbidden1]) - all_params = [ "p{}".format(i) for i in range(1,10) ] for i in range(1000): s = cs.sample() @@ -234,7 +232,9 @@ def test_omp_parse(self): name = 'p9', values = ['1', '8', '16']) - cs = ccs.ConfigurationSpace(name = "omp", parameters = [p1, p2, p3, p4, p5, p6, p7, p8, p9]) + cs = ccs.ConfigurationSpace(name = "omp", parameters = [p1, p2, p3, p4, p5, p6, p7, p8, p9], + forbidden_clauses = ["p1 == '#pragma omp #P2' && p2 == ' '", + "p1 == '#pragma omp #P3' && p3 == ' '"]) cs.set_condition(p2, "p1 # ['#pragma omp #P2', '#pragma omp target teams distribute #P2']") cs.set_condition(p4, "p1 == '#pragma omp target teams distribute #P4'") @@ -245,9 +245,6 @@ def test_omp_parse(self): cs.set_condition(p8, "p4 == 'dist_schedule(static, #P8)' || p5 == 'schedule(#P7,#P8)'") cs.set_condition(p9, "p6 == 'numthreads(#P9)'") - cs.add_forbidden_clauses(["p1 == '#pragma omp #P2' && p2 == ' '", - "p1 == '#pragma omp #P3' && p3 == ' '"]) - all_params = [ "p{}".format(i) for i in range(1,10) ] for i in range(1000): s = cs.sample() diff --git a/bindings/ruby/lib/cconfigspace/configuration_space.rb b/bindings/ruby/lib/cconfigspace/configuration_space.rb index 792481af..2d072644 100644 --- a/bindings/ruby/lib/cconfigspace/configuration_space.rb +++ b/bindings/ruby/lib/cconfigspace/configuration_space.rb @@ -1,12 +1,10 @@ module CCS - attach_function :ccs_create_configuration_space, [:string, :size_t, :pointer, :pointer], :ccs_result_t + attach_function :ccs_create_configuration_space, [:string, :size_t, :pointer, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_configuration_space_set_rng, [:ccs_configuration_space_t, :ccs_rng_t], :ccs_result_t attach_function :ccs_configuration_space_get_rng, [:ccs_configuration_space_t, :pointer], :ccs_result_t attach_function :ccs_configuration_space_set_condition, [:ccs_configuration_space_t, :size_t, :ccs_expression_t], :ccs_result_t attach_function :ccs_configuration_space_get_condition, [:ccs_configuration_space_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_configuration_space_get_conditions, [:ccs_configuration_space_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_configuration_space_add_forbidden_clause, [:ccs_configuration_space_t, :ccs_expression_t], :ccs_result_t - attach_function :ccs_configuration_space_add_forbidden_clauses, [:ccs_configuration_space_t, :size_t, :ccs_expression_t], :ccs_result_t attach_function :ccs_configuration_space_get_forbidden_clause, [:ccs_configuration_space_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_configuration_space_get_forbidden_clauses, [:ccs_configuration_space_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_configuration_space_check_configuration, [:ccs_configuration_space_t, :ccs_configuration_t, :pointer], :ccs_result_t @@ -18,7 +16,7 @@ module CCS class ConfigurationSpace < Context def initialize(handle = nil, retain: false, auto_release: true, - name: "", parameters: nil) + name: "", parameters: nil, forbidden_clauses: nil) if handle super(handle, retain: retain, auto_release: auto_release) else @@ -26,7 +24,18 @@ def initialize(handle = nil, retain: false, auto_release: true, p_parameters = MemoryPointer::new(:ccs_parameter_t, count) p_parameters.write_array_of_pointer(parameters.collect(&:handle)) ptr = MemoryPointer::new(:ccs_configuration_space_t) - CCS.error_check CCS.ccs_create_configuration_space(name, count, p_parameters, ptr) + if forbidden_clauses + ctx = parameters.map { |p| [p.name, p] }.to_h + p = ExpressionParser::new(ctx) + forbidden_clauses = forbidden_clauses.collect { |e| e.kind_of?(String) ? p.parse(e) : e } + fccount = forbidden_clauses.size + fcptr = MemoryPointer::new(:ccs_expression_t, count) + fcptr.write_array_of_pointer(forbidden_clauses.collect(&:handle)) + else + fccount = 0 + fcptr = nil + end + CCS.error_check CCS.ccs_create_configuration_space(name, count, p_parameters, fccount, fcptr, ptr) super(ptr.read_ccs_configuration_space_t, retain:false) end end @@ -94,30 +103,6 @@ def unconditional_parameters hps.each_with_index.select { |h, i| !conds[i] }.collect { |h, i| h }.to_a end - def add_forbidden_clause(expression) - if expression.kind_of? String - expression = ExpressionParser::new(self).parse(expression) - end - CCS.error_check CCS.ccs_configuration_space_add_forbidden_clause(@handle, expression) - self - end - - def add_forbidden_clauses(expressions) - p = ExpressionParser::new(self) - expressions = expressions.collect { |e| - if e.kind_of? String - e = p.parse(e) - else - e - end - } - count = expressions.size - ptr = MemoryPointer::new(:ccs_expression_t, count) - ptr.write_array_of_pointer(expressions.collect(&:handle)) - CCS.error_check CCS.ccs_configuration_space_add_forbidden_clauses(@handle, count, ptr) - self - end - def forbidden_clause(index) ptr = MemoryPointer::new(:ccs_expression_t) CCS.error_check CCS.ccs_configuration_space_get_forbidden_clause(@handle, index, ptr) @@ -125,16 +110,20 @@ def forbidden_clause(index) end def num_forbidden_clauses - ptr = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_configuration_space_get_forbidden_clauses(@handle, 0, nil, ptr) - ptr.read_size_t + @num_forbidden_clauses ||= begin + ptr = MemoryPointer::new(:size_t) + CCS.error_check CCS.ccs_configuration_space_get_forbidden_clauses(@handle, 0, nil, ptr) + ptr.read_size_t + end end def forbidden_clauses - count = num_forbidden_clauses - ptr = MemoryPointer::new(:ccs_expression_t, count) - CCS.error_check CCS.ccs_configuration_space_get_forbidden_clauses(@handle, count, ptr, nil) - count.times.collect { |i| Expression::from_handle(ptr[i].read_pointer) } + @forbidden_clauses ||= begin + count = num_forbidden_clauses + ptr = MemoryPointer::new(:ccs_expression_t, count) + CCS.error_check CCS.ccs_configuration_space_get_forbidden_clauses(@handle, count, ptr, nil) + count.times.collect { |i| Expression::from_handle(ptr[i].read_pointer) }.freeze + end end def check(configuration) diff --git a/bindings/ruby/test/test_configuration_space.rb b/bindings/ruby/test/test_configuration_space.rb index 7f32692d..aedc59df 100644 --- a/bindings/ruby/test/test_configuration_space.rb +++ b/bindings/ruby/test/test_configuration_space.rb @@ -60,13 +60,12 @@ def test_conditions h1 = CCS::NumericalParameter::Float.new(lower: -1.0, upper: 1.0, default: 0.0) h2 = CCS::NumericalParameter::Float.new(lower: -1.0, upper: 1.0) h3 = CCS::NumericalParameter::Float.new(lower: -1.0, upper: 1.0) - cs = CCS::ConfigurationSpace::new(name: "space", parameters: [h1, h2, h3]) + f1 = CCS::Expression::Less.new(left: h1, right: 0.0) + cs = CCS::ConfigurationSpace::new(name: "space", parameters: [h1, h2, h3], forbidden_clauses: [f1]) e1 = CCS::Expression::Less.new(left: h2, right: 0.0) cs.set_condition(h3, e1) e2 = CCS::Expression::Less.new(left: h3, right: 0.0) cs.set_condition(h1, e2) - e3 = CCS::Expression::Less.new(left: h1, right: 0.0) - cs.add_forbidden_clause(e3) conditions = cs.conditions conditional_parameters = cs.conditional_parameters unconditional_parameters = cs.unconditional_parameters @@ -81,7 +80,7 @@ def test_conditions assert_equal( h2.handle, unconditional_parameters[0].handle ) forbidden_clauses = cs.forbidden_clauses assert_equal( 1, forbidden_clauses.length ) - assert_equal( e3.handle, forbidden_clauses[0].handle ) + assert_equal( f1.handle, forbidden_clauses[0].handle ) end def extract_active_parameters(values) @@ -147,7 +146,16 @@ def test_omp name: 'p9', values: ['1', '8', '16']) - cs = CCS::ConfigurationSpace::new(name: "omp", parameters: [p1, p2, p3, p4, p5, p6, p7, p8, p9]) + forbiddena = CCS::Expression::Equal.new(left: p1, right: '#pragma omp #P2') + forbiddenb = CCS::Expression::Equal.new(left: p2, right: ' ') + forbidden0 = CCS::Expression::And.new(left: forbiddena, right: forbiddenb) + + forbiddenc = CCS::Expression::Equal.new(left: p1, right: '#pragma omp #P3') + forbiddend = CCS::Expression::Equal.new(left: p3, right: ' ') + forbidden1 = CCS::Expression::And.new(left: forbiddenc, right: forbiddend) + + cs = CCS::ConfigurationSpace::new(name: "omp", parameters: [p1, p2, p3, p4, p5, p6, p7, p8, p9], + forbidden_clauses: [forbidden0, forbidden1]) cond0 = CCS::Expression::Equal.new(left: p1, right: '#pragma omp #P2') cond1 = CCS::Expression::Equal.new(left: p1, right: '#pragma omp target teams distribute #P2') @@ -175,15 +183,6 @@ def test_omp cs.set_condition(p8, cond_p8) cs.set_condition(p9, cond10) - forbiddena = CCS::Expression::Equal.new(left: p1, right: '#pragma omp #P2') - forbiddenb = CCS::Expression::Equal.new(left: p2, right: ' ') - forbidden0 = CCS::Expression::And.new(left: forbiddena, right: forbiddenb) - - forbiddenc = CCS::Expression::Equal.new(left: p1, right: '#pragma omp #P3') - forbiddend = CCS::Expression::Equal.new(left: p3, right: ' ') - forbidden1 = CCS::Expression::And.new(left: forbiddenc, right: forbiddend) - cs.add_forbidden_clauses([forbidden0, forbidden1]) - all_params = (1..9).collect { |i| "p#{i}" } 1000.times { @@ -249,7 +248,9 @@ def test_omp_parse name: 'p9', values: ['1', '8', '16']) - cs = CCS::ConfigurationSpace::new(name: "omp", parameters: [p1, p2, p3, p4, p5, p6, p7, p8, p9]) + cs = CCS::ConfigurationSpace::new(name: "omp", parameters: [p1, p2, p3, p4, p5, p6, p7, p8, p9], + forbidden_clauses: ["p1 == '#pragma omp #P2' && p2 == ' '", + "p1 == '#pragma omp #P3' && p3 == ' '"]) cs.set_condition(p2, "p1 # ['#pragma omp #P2', '#pragma omp target teams distribute #P2']") cs.set_condition(p4, "p1 == '#pragma omp target teams distribute #P4'") @@ -260,9 +261,6 @@ def test_omp_parse cs.set_condition(p8, "p4 == 'dist_schedule(static, #P8)' || p5 == 'schedule(#P7,#P8)'") cs.set_condition(p9, "p6 == 'numthreads(#P9)'") - cs.add_forbidden_clauses(["p1 == '#pragma omp #P2' && p2 == ' '", - "p1 == '#pragma omp #P3' && p3 == ' '"]) - all_params = (1..9).collect { |i| "p#{i}" } 1000.times { diff --git a/connectors/kokkos/ccs-kokkos-connector.cpp b/connectors/kokkos/ccs-kokkos-connector.cpp index e07fd2c3..f2e87f55 100644 --- a/connectors/kokkos/ccs-kokkos-connector.cpp +++ b/connectors/kokkos/ccs-kokkos-connector.cpp @@ -515,7 +515,7 @@ kokkosp_request_values( CCS_CHECK(ccs_create_configuration_space( ("cs (region: " + std::to_string(regionCounter) + ")").c_str(), - numTuningVariables, cs_parameters, &cs)); + numTuningVariables, cs_parameters, 0, NULL, &cs)); delete[] cs_parameters; #if CCS_DEBUG diff --git a/include/cconfigspace/configuration_space.h b/include/cconfigspace/configuration_space.h index e13b4c1a..a1a29ff1 100644 --- a/include/cconfigspace/configuration_space.h +++ b/include/cconfigspace/configuration_space.h @@ -19,17 +19,25 @@ extern "C" { * @param[in] num_parameters the number of provided parameters * @param[in] parameters an array of \p num_parameters parameters * to add to the configuration space + * @param[in] num_forbidden_clauses the number of provided forbidden clauses + * @param[in] forbidden_clauses an array o \p num_forbidden_clauses expressions + * to add as forbidden clauses to the + * configuration space * @param[out] configuration_space_ret a pointer to the variable that will hold * the newly created configuration space * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * configuration_space_ret is NULL; or if \p parameters is NULL; or if \p - * num_parameters is NULL + * 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 + * parameter; or if an expression is not a valid CCS expression * @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 + * parameters; or if two or more parameters share the same name; 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_OUT_OF_MEMORY if there was a lack of memory to * allocate the new configuration space * @remarks @@ -40,6 +48,8 @@ ccs_create_configuration_space( const char *name, size_t num_parameters, ccs_parameter_t *parameters, + size_t num_forbidden_clauses, + ccs_expression_t *forbidden_clauses, ccs_configuration_space_t *configuration_space_ret); /** @@ -358,55 +368,6 @@ ccs_configuration_space_get_conditions( ccs_expression_t *expressions, size_t *num_expressions_ret); -/** - * Add a forbidden clause to a configuration space. - * @param[in,out] configuration_space - * @param[in] expression the forbidden clause to dd to the configuration space - * @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 expression is not a valid CCS - * expression - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if expression references a - * parameter that is not in the configuration space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate internal data structures - * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding the forbidden - * clause would render the default configuration invalid - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_add_forbidden_clause( - ccs_configuration_space_t configuration_space, - ccs_expression_t expression); - -/** - * Add a list of forbidden clauses to a configuration space. - * @param[in,out] configuration_space - * @param[in] num_expressions the number of provided expressions - * @param[in] expressions an array o \p num_expressions expressions to add as - * forbidden clauses to the configuration space - * @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 at least one of the provided expressions - * is not a valid CCS expression - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p expressions is NULL and \p - * num_expressions is greater than 0 - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if an expression references a - * parameter that is not in the configuration space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate internal data structures - * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding one of the provided - * forbidden clause would render the default configuration invalid - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_add_forbidden_clauses( - ccs_configuration_space_t configuration_space, - size_t num_expressions, - ccs_expression_t *expressions); - /** * Get the forbidden clause of rank index in a configuration space. * @param[in] configuration_space diff --git a/samples/test_python.c b/samples/test_python.c index 1938b4c5..8c300ee4 100644 --- a/samples/test_python.c +++ b/samples/test_python.c @@ -31,7 +31,8 @@ create_problem(ccs_configuration_space_t *cs, ccs_objective_space_t *os) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY); diff --git a/samples/test_ruby.c b/samples/test_ruby.c index bfe86c30..a0d45b72 100644 --- a/samples/test_ruby.c +++ b/samples/test_ruby.c @@ -40,7 +40,8 @@ create_problem(ccs_configuration_space_t *cs, ccs_objective_space_t *os) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY); diff --git a/src/configuration_space.c b/src/configuration_space.c index 8c98a91e..84e6cbfc 100644 --- a/src/configuration_space.c +++ b/src/configuration_space.c @@ -6,6 +6,7 @@ #include "expression_internal.h" #include "rng_internal.h" #include "utlist.h" +#include "utarray.h" static ccs_result_t _generate_constraints(ccs_configuration_space_t configuration_space); @@ -15,35 +16,24 @@ _ccs_configuration_space_del(ccs_object_t object) { ccs_configuration_space_t configuration_space = (ccs_configuration_space_t)object; - UT_array *array = configuration_space->data->parameters; - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) { - ccs_release_object(wrapper->parameter); - if (wrapper->condition) - ccs_release_object(wrapper->condition); - utarray_free(wrapper->parents); - utarray_free(wrapper->children); - } - array = configuration_space->data->forbidden_clauses; - ccs_expression_t *expr = NULL; - while ((expr = (ccs_expression_t *)utarray_next(array, expr))) { - ccs_release_object(*expr); + _ccs_configuration_space_data_t *data = configuration_space->data; + + for (size_t i = 0; i < data->num_parameters; i++) { + if (data->parameters[i]) + ccs_release_object(data->parameters[i]); + if (data->conditions[i]) + ccs_release_object(data->conditions[i]); + if (data->parents[i]) + utarray_free(data->parents[i]); + if (data->children[i]) + utarray_free(data->children[i]); } + for (size_t i = 0; i < data->num_forbidden_clauses; i++) + if (data->forbidden_clauses[i]) + ccs_release_object(data->forbidden_clauses[i]); + HASH_CLEAR(hh_name, configuration_space->data->name_hash); - _ccs_parameter_index_hash_t *elem, *tmpelem; - HASH_ITER( - hh_handle, configuration_space->data->handle_hash, elem, - tmpelem) - { - HASH_DELETE( - hh_handle, configuration_space->data->handle_hash, - elem); - free(elem); - } - utarray_free(configuration_space->data->parameters); - utarray_free(configuration_space->data->forbidden_clauses); - utarray_free(configuration_space->data->sorted_indexes); + HASH_CLEAR(hh_handle, configuration_space->data->handle_hash); ccs_release_object(configuration_space->data->rng); if (configuration_space->data->default_distribution_space) { _ccs_distribution_space_del_no_release( @@ -59,59 +49,48 @@ _ccs_serialize_bin_size_ccs_configuration_space_data( size_t *cum_size, _ccs_object_serialize_options_t *opts) { - size_t condition_count; - _ccs_parameter_wrapper_cs_t *wrapper; - ccs_expression_t *expr; + size_t condition_count; *cum_size += _ccs_serialize_bin_size_string(data->name); - *cum_size += - _ccs_serialize_bin_size_size(utarray_len(data->parameters)); + *cum_size += _ccs_serialize_bin_size_size(data->num_parameters); condition_count = 0; - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) - if (wrapper->condition) + for (size_t i = 0; i < data->num_parameters; i++) + if (data->conditions[i]) condition_count++; - *cum_size += _ccs_serialize_bin_size_size(condition_count); - *cum_size += _ccs_serialize_bin_size_size( - utarray_len(data->forbidden_clauses)); + *cum_size += _ccs_serialize_bin_size_size(condition_count); + *cum_size += _ccs_serialize_bin_size_size(data->num_forbidden_clauses); /* rng */ CCS_VALIDATE(data->rng->obj.ops->serialize_size( data->rng, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); /* parameters */ - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize_size( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, + for (size_t i = 0; i < data->num_parameters; i++) + CCS_VALIDATE(data->parameters[i]->obj.ops->serialize_size( + data->parameters[i], CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); /* conditions */ - condition_count = 0; - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) { - if (wrapper->condition) { + for (size_t i = 0; i < data->num_parameters; i++) + if (data->conditions[i]) { /* parameter index and condition */ - *cum_size += - _ccs_serialize_bin_size_size(condition_count); - CCS_VALIDATE(wrapper->condition->obj.ops->serialize_size( - wrapper->condition, CCS_SERIALIZE_FORMAT_BINARY, - cum_size, opts)); + *cum_size += _ccs_serialize_bin_size_size(i); + CCS_VALIDATE( + data->conditions[i]->obj.ops->serialize_size( + data->conditions[i], + CCS_SERIALIZE_FORMAT_BINARY, cum_size, + opts)); } - condition_count++; - } /* forbidden clauses */ - expr = NULL; - while ((expr = (ccs_expression_t *)utarray_next( - data->forbidden_clauses, expr))) - CCS_VALIDATE((*expr)->obj.ops->serialize_size( - *expr, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); + for (size_t i = 0; i < data->num_forbidden_clauses; i++) + CCS_VALIDATE( + data->forbidden_clauses[i]->obj.ops->serialize_size( + data->forbidden_clauses[i], + CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); + return CCS_RESULT_SUCCESS; } @@ -122,26 +101,22 @@ _ccs_serialize_bin_ccs_configuration_space_data( char **buffer, _ccs_object_serialize_options_t *opts) { - size_t condition_count; - _ccs_parameter_wrapper_cs_t *wrapper; - ccs_expression_t *expr; + size_t condition_count; CCS_VALIDATE( _ccs_serialize_bin_string(data->name, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->parameters), buffer_size, buffer)); + data->num_parameters, buffer_size, buffer)); condition_count = 0; - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) - if (wrapper->condition) + for (size_t i = 0; i < data->num_parameters; i++) + if (data->conditions[i]) condition_count++; CCS_VALIDATE( _ccs_serialize_bin_size(condition_count, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->forbidden_clauses), buffer_size, buffer)); + data->num_forbidden_clauses, buffer_size, buffer)); /* rng */ CCS_VALIDATE(data->rng->obj.ops->serialize( @@ -149,35 +124,28 @@ _ccs_serialize_bin_ccs_configuration_space_data( opts)); /* parameters */ - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, + for (size_t i = 0; i < data->num_parameters; i++) + CCS_VALIDATE(data->parameters[i]->obj.ops->serialize( + data->parameters[i], CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); /* conditions */ - condition_count = 0; - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - data->parameters, wrapper))) { - if (wrapper->condition) { + for (size_t i = 0; i < data->num_parameters; i++) + if (data->conditions[i]) { CCS_VALIDATE(_ccs_serialize_bin_size( - condition_count, buffer_size, buffer)); - CCS_VALIDATE(wrapper->condition->obj.ops->serialize( - wrapper->condition, CCS_SERIALIZE_FORMAT_BINARY, - buffer_size, buffer, opts)); + i, buffer_size, buffer)); + CCS_VALIDATE(data->conditions[i]->obj.ops->serialize( + data->conditions[i], + CCS_SERIALIZE_FORMAT_BINARY, buffer_size, + buffer, opts)); } - condition_count++; - } /* forbidden clauses */ - expr = NULL; - while ((expr = (ccs_expression_t *)utarray_next( - data->forbidden_clauses, expr))) - CCS_VALIDATE((*expr)->obj.ops->serialize( - *expr, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, - opts)); + for (size_t i = 0; i < data->num_forbidden_clauses; i++) + CCS_VALIDATE(data->forbidden_clauses[i]->obj.ops->serialize( + data->forbidden_clauses[i], CCS_SERIALIZE_FORMAT_BINARY, + buffer_size, buffer, opts)); + return CCS_RESULT_SUCCESS; } @@ -285,131 +253,71 @@ static _ccs_configuration_space_ops_t _configuration_space_ops = { &_ccs_configuration_space_serialize_size, &_ccs_configuration_space_serialize}}}; -static const UT_icd _parameter_wrapper_icd = { - sizeof(_ccs_parameter_wrapper_cs_t), - NULL, - NULL, - NULL, -}; - -static const UT_icd _forbidden_clauses_icd = { - sizeof(ccs_expression_t), - NULL, - NULL, - NULL, -}; - static UT_icd _size_t_icd = {sizeof(size_t), NULL, NULL, NULL}; -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, \ - errordistrib_wrapper, \ - "Out of memory to allocate array"); \ - } -#undef uthash_nonfatal_oom -#define uthash_nonfatal_oom(elt) \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errorutarray, \ - "Out of memory to allocate hash"); \ - } static ccs_result_t -_ccs_configuration_space_add_parameter( +_ccs_configuration_space_add_parameters( ccs_configuration_space_t configuration_space, - ccs_parameter_t parameter) + size_t num_parameters, + ccs_parameter_t *parameters) { - CCS_CHECK_OBJ(parameter, CCS_OBJECT_TYPE_PARAMETER); - ccs_result_t err; - ccs_parameter_type_t type; + for (size_t i = 0; i < num_parameters; i++) { + CCS_VALIDATE(_ccs_context_add_parameter( + (ccs_context_t)configuration_space, parameters[i], i)); + configuration_space->data->sorted_indexes[i] = i; + } + return CCS_RESULT_SUCCESS; +} - CCS_VALIDATE(ccs_parameter_get_type(parameter, &type)); - CCS_REFUTE( - CCS_PARAMETER_TYPE_STRING == type, - CCS_RESULT_ERROR_INVALID_PARAMETER); - - const char *name; - size_t sz_name; - _ccs_parameter_index_hash_t *parameter_hash; - CCS_VALIDATE(ccs_parameter_get_name(parameter, &name)); - sz_name = strlen(name); - HASH_FIND( - hh_name, configuration_space->data->name_hash, name, sz_name, - parameter_hash); +static inline ccs_result_t +_ccs_configuration_space_add_forbidden_clause( + ccs_configuration_space_t configuration_space, + ccs_expression_t expression, + size_t index, + ccs_configuration_t default_config) +{ + CCS_VALIDATE(ccs_expression_check_context( + expression, (ccs_context_t)configuration_space)); + ccs_datum_t d; + CCS_VALIDATE(ccs_expression_eval( + expression, (ccs_context_t)configuration_space, + default_config->data->values, &d)); CCS_REFUTE_MSG( - parameter_hash, CCS_RESULT_ERROR_INVALID_PARAMETER, - "An parameter with name '%s' already exists in the configuration space", - name); - UT_array *parameters; - size_t index; - _ccs_parameter_wrapper_cs_t parameter_wrapper; - parameter_wrapper.parameter = parameter; - CCS_VALIDATE(ccs_retain_object(parameter)); - - parameter_hash = (_ccs_parameter_index_hash_t *)malloc( - sizeof(_ccs_parameter_index_hash_t)); - CCS_REFUTE_ERR_GOTO( - err, !parameter_hash, CCS_RESULT_ERROR_OUT_OF_MEMORY, - errorparameter); - - parameters = configuration_space->data->parameters; - index = utarray_len(parameters); - parameter_hash->parameter = parameter; - parameter_hash->name = name; - parameter_hash->index = index; - parameter_wrapper.condition = NULL; - parameter_wrapper.parents = NULL; - parameter_wrapper.children = NULL; - utarray_new(parameter_wrapper.parents, &_size_t_icd); - utarray_new(parameter_wrapper.children, &_size_t_icd); - - utarray_push_back(parameters, ¶meter_wrapper); - utarray_push_back(configuration_space->data->sorted_indexes, &index); - - HASH_ADD_KEYPTR( - hh_name, configuration_space->data->name_hash, - parameter_hash->name, sz_name, parameter_hash); - HASH_ADD( - hh_handle, configuration_space->data->handle_hash, parameter, - sizeof(ccs_parameter_t), parameter_hash); - + d.type == CCS_DATA_TYPE_BOOL && d.value.i == CCS_TRUE, + CCS_RESULT_ERROR_INVALID_CONFIGURATION, + "Default configuration is invalid"); + CCS_VALIDATE(ccs_retain_object(expression)); + configuration_space->data->forbidden_clauses[index] = expression; return CCS_RESULT_SUCCESS; -errorutarray: - utarray_pop_back(parameters); -errordistrib_wrapper: - if (parameter_hash) - free(parameter_hash); - if (parameter_wrapper.parents) - utarray_free(parameter_wrapper.parents); - if (parameter_wrapper.children) - utarray_free(parameter_wrapper.children); -errorparameter: - ccs_release_object(parameter); - return err; } -#undef utarray_oom -#define utarray_oom() exit(-1) static ccs_result_t -_ccs_configuration_space_add_parameters( +_ccs_configuration_space_add_forbidden_clauses( ccs_configuration_space_t configuration_space, - size_t num_parameters, - ccs_parameter_t *parameters) + size_t num_expressions, + ccs_expression_t *expressions) { - for (size_t i = 0; i < num_parameters; i++) - CCS_VALIDATE(_ccs_configuration_space_add_parameter( - configuration_space, parameters[i])); - return CCS_RESULT_SUCCESS; + ccs_configuration_t default_config; + ccs_result_t err = CCS_RESULT_SUCCESS; + CCS_VALIDATE(ccs_configuration_space_get_default_configuration( + configuration_space, &default_config)); + for (size_t i = 0; i < num_expressions; i++) + CCS_VALIDATE_ERR_GOTO( + err, + _ccs_configuration_space_add_forbidden_clause( + configuration_space, expressions[i], i, + default_config), + end); +end: + ccs_release_object(default_config); + return err; } #undef utarray_oom #define utarray_oom() \ { \ - ccs_release_object(config_space->data->rng); \ CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errarrays, \ + err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errparams, \ "Out of memory to allocate array"); \ } @@ -418,67 +326,91 @@ ccs_create_configuration_space( const char *name, size_t num_parameters, ccs_parameter_t *parameters, + size_t num_forbidden_clauses, + ccs_expression_t *forbidden_clauses, ccs_configuration_space_t *configuration_space_ret) { CCS_CHECK_PTR(name); CCS_CHECK_PTR(configuration_space_ret); CCS_CHECK_ARY(num_parameters, parameters); + for (size_t i = 0; i < num_parameters; i++) + CCS_CHECK_OBJ(parameters[i], CCS_OBJECT_TYPE_PARAMETER); + 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); + ccs_result_t err; uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_configuration_space_s) + - sizeof(struct _ccs_configuration_space_data_s) + - strlen(name) + 1); + 1, + sizeof(struct _ccs_configuration_space_s) + + sizeof(struct _ccs_configuration_space_data_s) + + sizeof(ccs_parameter_t) * num_parameters + + sizeof(_ccs_parameter_index_hash_t) * num_parameters + + sizeof(ccs_expression_t) * num_parameters + + sizeof(UT_array *) * num_parameters * 2 + + sizeof(size_t) * num_parameters + + sizeof(ccs_expression_t) * num_forbidden_clauses + + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); + uintptr_t mem_orig = mem; ccs_rng_t rng; CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); ccs_configuration_space_t config_space; config_space = (ccs_configuration_space_t)mem; + mem += sizeof(struct _ccs_configuration_space_s); _ccs_object_init( &(config_space->obj), CCS_OBJECT_TYPE_CONFIGURATION_SPACE, (_ccs_object_ops_t *)&_configuration_space_ops); - config_space->data = - (struct _ccs_configuration_space_data_s - *)(mem + sizeof(struct _ccs_configuration_space_s)); - config_space->data->name = - (const char - *)(mem + sizeof(struct _ccs_configuration_space_s) + sizeof(struct _ccs_configuration_space_data_s)); - config_space->data->rng = rng; - utarray_new(config_space->data->parameters, &_parameter_wrapper_icd); - utarray_new( - config_space->data->forbidden_clauses, &_forbidden_clauses_icd); - utarray_new(config_space->data->sorted_indexes, &_size_t_icd); - config_space->data->graph_ok = CCS_TRUE; + config_space->data = (struct _ccs_configuration_space_data_s *)mem; + mem += sizeof(struct _ccs_configuration_space_data_s); + config_space->data->parameters = (ccs_parameter_t *)mem; + mem += sizeof(ccs_parameter_t) * num_parameters; + config_space->data->hash_elems = (_ccs_parameter_index_hash_t *)mem; + mem += sizeof(_ccs_parameter_index_hash_t) * num_parameters; + config_space->data->conditions = (ccs_expression_t *)mem; + mem += sizeof(ccs_expression_t) * num_parameters; + config_space->data->parents = (UT_array **)mem; + mem += sizeof(UT_array *) * num_parameters; + config_space->data->children = (UT_array **)mem; + mem += sizeof(UT_array *) * num_parameters; + config_space->data->sorted_indexes = (size_t *)mem; + mem += sizeof(size_t) * num_parameters; + config_space->data->forbidden_clauses = (ccs_expression_t *)mem; + mem += sizeof(ccs_expression_t) * num_forbidden_clauses; + 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; + config_space->data->graph_ok = CCS_TRUE; strcpy((char *)(config_space->data->name), name); - *configuration_space_ret = config_space; CCS_VALIDATE_ERR_GOTO( err, _ccs_configuration_space_add_parameters( config_space, num_parameters, parameters), errparams); + CCS_VALIDATE_ERR_GOTO( + err, + _ccs_configuration_space_add_forbidden_clauses( + config_space, num_forbidden_clauses, forbidden_clauses), + errparams); CCS_VALIDATE_ERR_GOTO( err, _ccs_create_distribution_space_no_retain( config_space, NULL, &config_space->data->default_distribution_space), errparams); + for (size_t i = 0; i < num_parameters; i++) { + utarray_new(config_space->data->parents[i], &_size_t_icd); + utarray_new(config_space->data->children[i], &_size_t_icd); + } + *configuration_space_ret = config_space; return CCS_RESULT_SUCCESS; -errarrays: - if (config_space->data->parameters) - utarray_free(config_space->data->parameters); - if (config_space->data->forbidden_clauses) - utarray_free(config_space->data->forbidden_clauses); - if (config_space->data->sorted_indexes) - utarray_free(config_space->data->sorted_indexes); - ccs_release_object(config_space->data->rng); - _ccs_object_deinit(&(config_space->obj)); -errmem: - free((void *)mem); - return err; errparams: _ccs_configuration_space_del(config_space); _ccs_object_deinit(&(config_space->obj)); - free((void *)mem); +errmem: + free((void *)mem_orig); return err; } #undef utarray_oom @@ -629,23 +561,20 @@ _set_actives( ccs_configuration_space_t configuration_space, ccs_configuration_t configuration) { - size_t *p_index = NULL; - UT_array *indexes = configuration_space->data->sorted_indexes; - UT_array *array = configuration_space->data->parameters; - ccs_datum_t *values = configuration->data->values; - while ((p_index = (size_t *)utarray_next(indexes, p_index))) { - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, *p_index); - if (!wrapper->condition) + size_t *indexes = configuration_space->data->sorted_indexes; + ccs_expression_t *conditions = configuration_space->data->conditions; + ccs_datum_t *values = configuration->data->values; + for (size_t i = 0; i < configuration_space->data->num_parameters; i++) { + size_t index = indexes[i]; + if (!conditions[index]) continue; ccs_datum_t result; CCS_VALIDATE(ccs_expression_eval( - wrapper->condition, (ccs_context_t)configuration_space, + conditions[index], (ccs_context_t)configuration_space, values, &result)); if (!(result.type == CCS_DATA_TYPE_BOOL && result.value.i == CCS_TRUE)) - values[*p_index] = ccs_inactive; + values[index] = ccs_inactive; } return CCS_RESULT_SUCCESS; } @@ -664,15 +593,13 @@ ccs_configuration_space_get_default_configuration( ccs_configuration_t config; CCS_VALIDATE(_ccs_create_configuration( configuration_space, 0, NULL, &config)); - UT_array *array = configuration_space->data->parameters; - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - ccs_datum_t *values = config->data->values; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) + 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++) CCS_VALIDATE_ERR_GOTO( err, ccs_parameter_get_default_value( - wrapper->parameter, values++), + parameters[i], values + i), errc); CCS_VALIDATE_ERR_GOTO( err, _set_actives(configuration_space, config), errc); @@ -689,15 +616,15 @@ _test_forbidden( ccs_datum_t *values, ccs_bool_t *is_valid) { - UT_array *array = configuration_space->data->forbidden_clauses; - ccs_expression_t *p_expression = NULL; - *is_valid = CCS_FALSE; - while ((p_expression = (ccs_expression_t *)utarray_next( - array, p_expression))) { + ccs_expression_t *forbidden_clauses = + configuration_space->data->forbidden_clauses; + *is_valid = CCS_FALSE; + for (size_t i = 0; i < configuration_space->data->num_forbidden_clauses; + i++) { ccs_datum_t result; CCS_VALIDATE(ccs_expression_eval( - *p_expression, (ccs_context_t)configuration_space, - values, &result)); + forbidden_clauses[i], + (ccs_context_t)configuration_space, values, &result)); if (result.type == CCS_DATA_TYPE_INACTIVE) continue; if (result.type == CCS_DATA_TYPE_BOOL && @@ -715,28 +642,26 @@ _check_configuration( ccs_datum_t *values, ccs_bool_t *is_valid_ret) { - UT_array *indexes = configuration_space->data->sorted_indexes; - UT_array *array = configuration_space->data->parameters; + size_t *indexes = configuration_space->data->sorted_indexes; + ccs_parameter_t *parameters = configuration_space->data->parameters; + ccs_expression_t *conditions = configuration_space->data->conditions; CCS_REFUTE( - num_values != utarray_len(array), + num_values != configuration_space->data->num_parameters, CCS_RESULT_ERROR_INVALID_CONFIGURATION); - size_t *p_index = NULL; - while ((p_index = (size_t *)utarray_next(indexes, p_index))) { - ccs_bool_t active = CCS_TRUE; - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, *p_index); - if (wrapper->condition) { + for (size_t i = 0; i < num_values; i++) { + ccs_bool_t active = CCS_TRUE; + size_t index = indexes[i]; + if (conditions[index]) { ccs_datum_t result; CCS_VALIDATE(ccs_expression_eval( - wrapper->condition, + conditions[index], (ccs_context_t)configuration_space, values, &result)); if (!(result.type == CCS_DATA_TYPE_BOOL && result.value.i == CCS_TRUE)) active = CCS_FALSE; } - if (active != (values[*p_index].type == CCS_DATA_TYPE_INACTIVE ? + if (active != (values[index].type == CCS_DATA_TYPE_INACTIVE ? CCS_FALSE : CCS_TRUE)) { *is_valid_ret = CCS_FALSE; @@ -744,7 +669,7 @@ _check_configuration( } if (active) { CCS_VALIDATE(ccs_parameter_check_value( - wrapper->parameter, values[*p_index], + parameters[index], values[index], is_valid_ret)); if (*is_valid_ret == CCS_FALSE) return CCS_RESULT_SUCCESS; @@ -812,18 +737,14 @@ _sample(ccs_configuration_space_t configuration_space, ccs_configuration_t config, ccs_bool_t *found) { - ccs_result_t err; - ccs_rng_t rng = configuration_space->data->rng; - UT_array *array = configuration_space->data->parameters; - ccs_distribution_space_t distribution_space; - _ccs_distribution_wrapper_t *dwrapper = NULL; - _ccs_parameter_wrapper_cs_t *hwrapper = NULL; - ccs_datum_t *values = config->data->values; - - size_t num_parameters = utarray_len(array); - ccs_datum_t *p_values; - ccs_parameter_t *hps; - uintptr_t mem; + ccs_result_t err = CCS_RESULT_SUCCESS; + ccs_rng_t rng = configuration_space->data->rng; + ccs_parameter_t *parameters = configuration_space->data->parameters; + ccs_datum_t *values = config->data->values; + size_t num_parameters = configuration_space->data->num_parameters; + ccs_datum_t *p_values; + ccs_parameter_t *hps; + uintptr_t mem; mem = (uintptr_t)malloc( num_parameters * (sizeof(ccs_datum_t) + sizeof(ccs_parameter_t))); @@ -831,39 +752,39 @@ _sample(ccs_configuration_space_t configuration_space, p_values = (ccs_datum_t *)mem; hps = (ccs_parameter_t *)(mem + num_parameters * sizeof(ccs_datum_t)); + ccs_distribution_space_t distribution_space; if (distrib_space) { distribution_space = distrib_space; CCS_OBJ_RDLOCK(distrib_space); } else distribution_space = configuration_space->data->default_distribution_space; + + _ccs_distribution_wrapper_t *dwrapper = NULL; DL_FOREACH(distribution_space->data->distribution_list, dwrapper) { for (size_t i = 0; i < dwrapper->dimension; i++) { size_t hindex = dwrapper->parameter_indexes[i]; - hwrapper = - (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, hindex); - hps[i] = hwrapper->parameter; + hps[i] = parameters[hindex]; } CCS_VALIDATE_ERR_GOTO( err, ccs_distribution_parameters_sample( dwrapper->distribution, rng, hps, p_values), - memory); + errmem); for (size_t i = 0; i < dwrapper->dimension; i++) { size_t hindex = dwrapper->parameter_indexes[i]; values[hindex] = p_values[i]; } } CCS_VALIDATE_ERR_GOTO( - err, _set_actives(configuration_space, config), memory); + err, _set_actives(configuration_space, config), errmem); CCS_VALIDATE_ERR_GOTO( err, _test_forbidden( configuration_space, config->data->values, found), - memory); -memory: + errmem); +errmem: if (distrib_space) CCS_OBJ_UNLOCK(distrib_space); free((void *)mem); @@ -1028,46 +949,42 @@ struct _parameter_list_s { static ccs_result_t _topological_sort(ccs_configuration_space_t configuration_space) { - utarray_clear(configuration_space->data->sorted_indexes); - UT_array *array = configuration_space->data->parameters; - size_t count = utarray_len(array); + _ccs_configuration_space_data_t *data = configuration_space->data; + size_t num_parameters = data->num_parameters; + size_t *indexes = data->sorted_indexes; + UT_array **parents = data->parents; + UT_array **children = data->children; - struct _parameter_list_s *list = (struct _parameter_list_s *)calloc( - 1, sizeof(struct _parameter_list_s) * count); - CCS_REFUTE(!list, CCS_RESULT_ERROR_OUT_OF_MEMORY); - struct _parameter_list_s *queue = NULL; + for (size_t i = 0; i < num_parameters; i++) + indexes[i] = 0; - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - size_t index = 0; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) { - size_t in_edges = utarray_len(wrapper->parents); + struct _parameter_list_s *list = (struct _parameter_list_s *)calloc( + 1, sizeof(struct _parameter_list_s) * num_parameters); + CCS_REFUTE(!list, CCS_RESULT_ERROR_OUT_OF_MEMORY); + struct _parameter_list_s *queue = NULL; + for (size_t index = 0; index < num_parameters; index++) { + size_t in_edges = utarray_len(parents[index]); list[index].in_edges = in_edges; list[index].index = index; if (in_edges == 0) DL_APPEND(queue, list + index); - index++; } size_t processed = 0; while (queue) { struct _parameter_list_s *e = queue; DL_DELETE(queue, queue); - wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, e->index); size_t *child = NULL; while ((child = (size_t *)utarray_next( - wrapper->children, child))) { + children[e->index], child))) { list[*child].in_edges--; if (list[*child].in_edges == 0) { DL_APPEND(queue, list + *child); } } - utarray_push_back( - configuration_space->data->sorted_indexes, &(e->index)); - processed++; + indexes[processed++] = e->index; }; free(list); - CCS_REFUTE(processed < count, CCS_RESULT_ERROR_INVALID_GRAPH); + CCS_REFUTE(processed < num_parameters, CCS_RESULT_ERROR_INVALID_GRAPH); return CCS_RESULT_SUCCESS; } @@ -1081,34 +998,34 @@ _topological_sort(ccs_configuration_space_t configuration_space) static ccs_result_t _recompute_graph(ccs_configuration_space_t configuration_space) { - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - UT_array *array = configuration_space->data->parameters; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) { - utarray_clear(wrapper->parents); - utarray_clear(wrapper->children); + _ccs_configuration_space_data_t *data = configuration_space->data; + size_t num_parameters = data->num_parameters; + UT_array **pparents = data->parents; + UT_array **pchildren = data->children; + ccs_expression_t *conditions = data->conditions; + + for (size_t index = 0; index < num_parameters; index++) { + utarray_clear(pparents[index]); + utarray_clear(pchildren[index]); } - wrapper = NULL; intptr_t mem = 0; ccs_result_t err = CCS_RESULT_SUCCESS; - for (size_t index = 0; index < utarray_len(array); index++) { - wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, (unsigned int)index); - if (!wrapper->condition) + for (size_t index = 0; index < num_parameters; index++) { + ccs_expression_t condition = conditions[index]; + if (!condition) continue; size_t count; CCS_VALIDATE_ERR_GOTO( err, ccs_expression_get_parameters( - wrapper->condition, 0, NULL, &count), + condition, 0, NULL, &count), errmem); if (count == 0) continue; - ccs_parameter_t *parents = NULL; - size_t *parents_index = NULL; - _ccs_parameter_wrapper_cs_t *parent_wrapper = NULL; - intptr_t oldmem = mem; - mem = (intptr_t)realloc( + ccs_parameter_t *parents = NULL; + size_t *parents_index = NULL; + intptr_t oldmem = mem; + mem = (intptr_t)realloc( (void *)oldmem, count * (sizeof(ccs_parameter_t) + sizeof(size_t))); if (!mem) { @@ -1123,7 +1040,7 @@ _recompute_graph(ccs_configuration_space_t configuration_space) CCS_VALIDATE_ERR_GOTO( err, ccs_expression_get_parameters( - wrapper->condition, count, parents, NULL), + condition, count, parents, NULL), errmem); CCS_VALIDATE_ERR_GOTO( err, @@ -1132,18 +1049,13 @@ _recompute_graph(ccs_configuration_space_t configuration_space) parents_index), errmem); for (size_t i = 0; i < count; i++) { - utarray_push_back(wrapper->parents, parents_index + i); - parent_wrapper = - (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - array, parents_index[i]); - utarray_push_back(parent_wrapper->children, &index); + utarray_push_back(pparents[index], parents_index + i); + utarray_push_back(pchildren[parents_index[i]], &index); } } - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) { - _uniq_size_t_array(wrapper->parents); - _uniq_size_t_array(wrapper->children); + for (size_t index = 0; index < num_parameters; index++) { + _uniq_size_t_array(pparents[index]); + _uniq_size_t_array(pchildren[index]); } errmem: if (mem) @@ -1173,19 +1085,17 @@ ccs_configuration_space_set_condition( { CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); CCS_CHECK_OBJ(expression, CCS_OBJECT_TYPE_EXPRESSION); + CCS_REFUTE( + parameter_index >= configuration_space->data->num_parameters, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); CCS_OBJ_WRLOCK(configuration_space); - ccs_result_t err; - _ccs_parameter_wrapper_cs_t *wrapper = - (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - configuration_space->data->parameters, - (unsigned int)parameter_index); - CCS_REFUTE_ERR_GOTO( - err, !wrapper, CCS_RESULT_ERROR_OUT_OF_BOUNDS, errwrapper); + ccs_result_t err = CCS_RESULT_SUCCESS; + ccs_expression_t *conditions = configuration_space->data->conditions; CCS_REFUTE_ERR_GOTO( - err, wrapper->condition, CCS_RESULT_ERROR_INVALID_PARAMETER, - errwrapper); + err, conditions[parameter_index], + CCS_RESULT_ERROR_INVALID_PARAMETER, errwrapper); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(expression), errwrapper); - wrapper->condition = expression; + conditions[parameter_index] = expression; // Recompute the whole graph for now configuration_space->data->graph_ok = CCS_FALSE; CCS_VALIDATE_ERR_GOTO( @@ -1194,7 +1104,7 @@ ccs_configuration_space_set_condition( return CCS_RESULT_SUCCESS; erre: ccs_release_object(expression); - wrapper->condition = NULL; + conditions[parameter_index] = NULL; _generate_constraints(configuration_space); errwrapper: CCS_OBJ_UNLOCK(configuration_space); @@ -1209,15 +1119,13 @@ ccs_configuration_space_get_condition( { CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); CCS_CHECK_PTR(expression_ret); + CCS_REFUTE( + parameter_index >= configuration_space->data->num_parameters, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); ccs_result_t err = CCS_RESULT_SUCCESS; CCS_OBJ_RDLOCK(configuration_space); - _ccs_parameter_wrapper_cs_t *wrapper = - (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - configuration_space->data->parameters, - (unsigned int)parameter_index); - CCS_REFUTE_ERR_GOTO(err, !wrapper, CCS_RESULT_ERROR_OUT_OF_BOUNDS, end); - *expression_ret = wrapper->condition; -end: + *expression_ret = + configuration_space->data->conditions[parameter_index]; CCS_OBJ_UNLOCK(configuration_space); return err; } @@ -1234,84 +1142,21 @@ ccs_configuration_space_get_conditions( CCS_REFUTE( !expressions && !num_expressions_ret, CCS_RESULT_ERROR_INVALID_VALUE); - ccs_result_t err = CCS_RESULT_SUCCESS; - CCS_OBJ_RDLOCK(configuration_space); - UT_array *array = configuration_space->data->parameters; - size_t num_parameters = utarray_len(array); + ccs_expression_t *conditions = configuration_space->data->conditions; + size_t num_parameters = configuration_space->data->num_parameters; if (expressions) { - CCS_REFUTE_ERR_GOTO( - err, num_expressions < num_parameters, - CCS_RESULT_ERROR_INVALID_VALUE, end); - _ccs_parameter_wrapper_cs_t *wrapper = NULL; - size_t index = 0; - while ((wrapper = (_ccs_parameter_wrapper_cs_t *)utarray_next( - array, wrapper))) - expressions[index++] = wrapper->condition; + CCS_REFUTE( + num_expressions < num_parameters, + CCS_RESULT_ERROR_INVALID_VALUE); + CCS_OBJ_RDLOCK(configuration_space); + for (size_t i = 0; i < num_parameters; i++) + expressions[i] = conditions[i]; + CCS_OBJ_UNLOCK(configuration_space); for (size_t i = num_parameters; i < num_expressions; i++) expressions[i] = NULL; } if (num_expressions_ret) *num_expressions_ret = num_parameters; -end: - CCS_OBJ_UNLOCK(configuration_space); - return err; -} - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, end, \ - "Out of memory to allocate array"); \ - } -ccs_result_t -ccs_configuration_space_add_forbidden_clause( - ccs_configuration_space_t configuration_space, - ccs_expression_t expression) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_CHECK_OBJ(expression, CCS_OBJECT_TYPE_EXPRESSION); - ccs_result_t err = CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_expression_check_context( - expression, (ccs_context_t)configuration_space)); - ccs_datum_t d; - ccs_configuration_t config; - CCS_VALIDATE(ccs_configuration_space_get_default_configuration( - configuration_space, &config)); - - CCS_OBJ_WRLOCK(configuration_space); - CCS_VALIDATE_ERR_GOTO( - err, - ccs_expression_eval( - expression, (ccs_context_t)configuration_space, - config->data->values, &d), - end); - if (d.type == CCS_DATA_TYPE_BOOL && d.value.i == CCS_TRUE) - CCS_RAISE_ERR_GOTO( - err, CCS_RESULT_ERROR_INVALID_CONFIGURATION, end, - "Default configuration is invalid"); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(expression), end); - utarray_push_back( - configuration_space->data->forbidden_clauses, &expression); -end: - CCS_OBJ_UNLOCK(configuration_space); - ccs_release_object(config); - return err; -} -#undef utarray_oom -#define utarray_oom() exit(-1) - -ccs_result_t -ccs_configuration_space_add_forbidden_clauses( - ccs_configuration_space_t configuration_space, - size_t num_expressions, - ccs_expression_t *expressions) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_CHECK_ARY(num_expressions, expressions); - for (size_t i = 0; i < num_expressions; i++) - CCS_VALIDATE(ccs_configuration_space_add_forbidden_clause( - configuration_space, expressions[i])); return CCS_RESULT_SUCCESS; } @@ -1323,16 +1168,11 @@ ccs_configuration_space_get_forbidden_clause( { CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); CCS_CHECK_PTR(expression_ret); - ccs_result_t err = CCS_RESULT_SUCCESS; - CCS_OBJ_RDLOCK(configuration_space); - ccs_expression_t *p_expr = (ccs_expression_t *)utarray_eltptr( - configuration_space->data->forbidden_clauses, - (unsigned int)index); - CCS_REFUTE_ERR_GOTO(err, !p_expr, CCS_RESULT_ERROR_OUT_OF_BOUNDS, end); - *expression_ret = *p_expr; -end: - CCS_OBJ_UNLOCK(configuration_space); - return err; + CCS_REFUTE( + index >= configuration_space->data->num_forbidden_clauses, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); + *expression_ret = configuration_space->data->forbidden_clauses[index]; + return CCS_RESULT_SUCCESS; } ccs_result_t @@ -1347,25 +1187,20 @@ ccs_configuration_space_get_forbidden_clauses( CCS_REFUTE( !expressions && !num_expressions_ret, CCS_RESULT_ERROR_INVALID_VALUE); - ccs_result_t err = CCS_RESULT_SUCCESS; - CCS_OBJ_RDLOCK(configuration_space); - UT_array *array = configuration_space->data->forbidden_clauses; - size_t num_forbidden_clauses = utarray_len(array); + ccs_expression_t *forbidden_clauses = + configuration_space->data->forbidden_clauses; + size_t num_forbidden_clauses = + configuration_space->data->num_forbidden_clauses; if (expressions) { - CCS_REFUTE_ERR_GOTO( - err, num_expressions < num_forbidden_clauses, - CCS_RESULT_ERROR_INVALID_VALUE, end); - ccs_expression_t *p_expr = NULL; - size_t index = 0; - while ((p_expr = (ccs_expression_t *)utarray_next( - array, p_expr))) - expressions[index++] = *p_expr; + CCS_REFUTE( + num_expressions < num_forbidden_clauses, + CCS_RESULT_ERROR_INVALID_VALUE); + for (size_t i = 0; i < num_forbidden_clauses; i++) + expressions[i] = forbidden_clauses[i]; for (size_t i = num_forbidden_clauses; i < num_expressions; i++) expressions[i] = NULL; } if (num_expressions_ret) *num_expressions_ret = num_forbidden_clauses; -end: - CCS_OBJ_UNLOCK(configuration_space); - return err; + return CCS_RESULT_SUCCESS; } diff --git a/src/configuration_space_deserialize.h b/src/configuration_space_deserialize.h index c644248d..f2c9e54f 100644 --- a/src/configuration_space_deserialize.h +++ b/src/configuration_space_deserialize.h @@ -115,6 +115,7 @@ _ccs_deserialize_bin_configuration_space( res, ccs_create_configuration_space( data.name, data.num_parameters, data.parameters, + data.num_forbidden_clauses, data.forbidden_clauses, configuration_space_ret), end); CCS_VALIDATE_ERR_GOTO( @@ -130,12 +131,6 @@ _ccs_deserialize_bin_configuration_space( data.cond_parameter_indices[i], data.conditions[i]), err_configuration_space); - CCS_VALIDATE_ERR_GOTO( - res, - ccs_configuration_space_add_forbidden_clauses( - *configuration_space_ret, data.num_forbidden_clauses, - data.forbidden_clauses), - err_configuration_space); if (opts && opts->map_values && opts->handle_map) CCS_VALIDATE_ERR_GOTO( res, diff --git a/src/configuration_space_internal.h b/src/configuration_space_internal.h index 272edbfc..fc0bb052 100644 --- a/src/configuration_space_internal.h +++ b/src/configuration_space_internal.h @@ -5,14 +5,6 @@ struct _ccs_distribution_wrapper_s; typedef struct _ccs_distribution_wrapper_s _ccs_distribution_wrapper_t; -struct _ccs_parameter_wrapper_cs_s { - ccs_parameter_t parameter; - ccs_expression_t condition; - UT_array *parents; - UT_array *children; -}; -typedef struct _ccs_parameter_wrapper_cs_s _ccs_parameter_wrapper_cs_t; - struct _ccs_configuration_space_data_s; typedef struct _ccs_configuration_space_data_s _ccs_configuration_space_data_t; @@ -28,13 +20,19 @@ struct _ccs_configuration_space_s { struct _ccs_configuration_space_data_s { const char *name; - UT_array *parameters; + size_t num_parameters; + ccs_parameter_t *parameters; + _ccs_parameter_index_hash_t *hash_elems; _ccs_parameter_index_hash_t *name_hash; _ccs_parameter_index_hash_t *handle_hash; - ccs_rng_t rng; - UT_array *forbidden_clauses; + ccs_expression_t *conditions; + UT_array **parents; + UT_array **children; + size_t *sorted_indexes; + size_t num_forbidden_clauses; + ccs_expression_t *forbidden_clauses; ccs_bool_t graph_ok; - UT_array *sorted_indexes; + ccs_rng_t rng; ccs_distribution_space_t default_distribution_space; }; diff --git a/src/context_internal.h b/src/context_internal.h index 3fa6a0bb..bf2a63b2 100644 --- a/src/context_internal.h +++ b/src/context_internal.h @@ -1,6 +1,5 @@ #ifndef _CONTEXT_INTERNAL_H #define _CONTEXT_INTERNAL_H -#include "utarray.h" #ifdef HASH_NONFATAL_OOM #undef HASH_NONFATAL_OOM #endif @@ -15,11 +14,6 @@ struct _ccs_context_ops_s { }; typedef struct _ccs_context_ops_s _ccs_context_ops_t; -struct _ccs_parameter_wrapper_s { - ccs_parameter_t parameter; -}; -typedef struct _ccs_parameter_wrapper_s _ccs_parameter_wrapper_t; - struct _ccs_parameter_index_hash_s { ccs_parameter_t parameter; const char *name; @@ -31,7 +25,9 @@ typedef struct _ccs_parameter_index_hash_s _ccs_parameter_index_hash_t; struct _ccs_context_data_s { const char *name; - UT_array *parameters; + size_t num_parameters; + ccs_parameter_t *parameters; + _ccs_parameter_index_hash_t *hash_elems; _ccs_parameter_index_hash_t *name_hash; _ccs_parameter_index_hash_t *handle_hash; }; @@ -64,7 +60,7 @@ _ccs_context_get_num_parameters( size_t *num_parameters_ret) { CCS_CHECK_PTR(num_parameters_ret); - *num_parameters_ret = utarray_len(context->data->parameters); + *num_parameters_ret = context->data->num_parameters; return CCS_RESULT_SUCCESS; } @@ -75,11 +71,10 @@ _ccs_context_get_parameter( ccs_parameter_t *parameter_ret) { CCS_CHECK_PTR(parameter_ret); - _ccs_parameter_wrapper_t *wrapper = - (_ccs_parameter_wrapper_t *)utarray_eltptr( - context->data->parameters, (unsigned int)index); - CCS_REFUTE(!wrapper, CCS_RESULT_ERROR_OUT_OF_BOUNDS); - *parameter_ret = wrapper->parameter; + CCS_REFUTE( + index >= context->data->num_parameters, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); + *parameter_ret = context->data->parameters[index]; return CCS_RESULT_SUCCESS; } @@ -117,6 +112,49 @@ _ccs_context_get_parameter_index_by_name( return CCS_RESULT_SUCCESS; } +#undef uthash_nonfatal_oom +#define uthash_nonfatal_oom(elt) \ + { \ + CCS_RAISE( \ + CCS_RESULT_ERROR_OUT_OF_MEMORY, \ + "Not enough memory to allocate hash"); \ + } +static inline ccs_result_t +_ccs_context_add_parameter( + ccs_context_t context, + ccs_parameter_t parameter, + size_t index) +{ + const char *name; + size_t sz_name; + _ccs_parameter_index_hash_t *parameter_hash; + CCS_VALIDATE(ccs_parameter_get_name(parameter, &name)); + sz_name = strlen(name); + HASH_FIND( + hh_name, context->data->name_hash, name, sz_name, + parameter_hash); + CCS_REFUTE_MSG( + parameter_hash, CCS_RESULT_ERROR_INVALID_PARAMETER, + "Duplicate parameter name '%s' found", name); + + parameter_hash = context->data->hash_elems + index; + parameter_hash->parameter = parameter; + parameter_hash->name = name; + parameter_hash->index = index; + + HASH_ADD( + hh_handle, context->data->handle_hash, parameter, + sizeof(ccs_parameter_t), parameter_hash); + HASH_ADD_KEYPTR( + hh_name, context->data->name_hash, parameter_hash->name, + sz_name, parameter_hash); + + CCS_VALIDATE(ccs_retain_object(parameter)); + context->data->parameters[index] = parameter; + return CCS_RESULT_SUCCESS; +} +#undef uthash_nonfatal_oom + static inline ccs_result_t _ccs_context_get_parameters( ccs_context_t context, @@ -128,16 +166,13 @@ _ccs_context_get_parameters( CCS_REFUTE( !num_parameters_ret && !parameters, CCS_RESULT_ERROR_INVALID_VALUE); - UT_array *array = context->data->parameters; - size_t size = utarray_len(array); + ccs_parameter_t *params = context->data->parameters; + size_t size = context->data->num_parameters; if (parameters) { CCS_REFUTE( num_parameters < size, CCS_RESULT_ERROR_INVALID_VALUE); - _ccs_parameter_wrapper_t *wrapper = NULL; - size_t index = 0; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - array, wrapper))) - parameters[index++] = wrapper->parameter; + for (size_t i = 0; i < size; i++) + parameters[i] = params[i]; for (size_t i = size; i < num_parameters; i++) parameters[i] = NULL; } @@ -182,13 +217,12 @@ _ccs_context_validate_value( ccs_datum_t *value_ret) { CCS_CHECK_PTR(value_ret); - _ccs_parameter_wrapper_t *wrapper = - (_ccs_parameter_wrapper_t *)utarray_eltptr( - context->data->parameters, (unsigned int)index); - CCS_REFUTE(!wrapper, CCS_RESULT_ERROR_OUT_OF_BOUNDS); + CCS_REFUTE( + index >= context->data->num_parameters, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); ccs_bool_t valid; CCS_VALIDATE(ccs_parameter_validate_value( - wrapper->parameter, value, value_ret, &valid)); + context->data->parameters[index], value, value_ret, &valid)); CCS_REFUTE(!valid, CCS_RESULT_ERROR_INVALID_VALUE); return CCS_RESULT_SUCCESS; } @@ -200,13 +234,10 @@ _ccs_serialize_bin_size_ccs_context_data( _ccs_object_serialize_options_t *opts) { *cum_size += _ccs_serialize_bin_size_string(data->name); - *cum_size += - _ccs_serialize_bin_size_size(utarray_len(data->parameters)); - _ccs_parameter_wrapper_t *wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize_size( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, + *cum_size += _ccs_serialize_bin_size_size(data->num_parameters); + for (size_t i = 0; i < data->num_parameters; i++) + CCS_VALIDATE(data->parameters[i]->obj.ops->serialize_size( + data->parameters[i], CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); return CCS_RESULT_SUCCESS; } @@ -221,12 +252,10 @@ _ccs_serialize_bin_ccs_context_data( CCS_VALIDATE( _ccs_serialize_bin_string(data->name, buffer_size, buffer)); CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->parameters), buffer_size, buffer)); - _ccs_parameter_wrapper_t *wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, + data->num_parameters, buffer_size, buffer)); + for (size_t i = 0; i < data->num_parameters; i++) + CCS_VALIDATE(data->parameters[i]->obj.ops->serialize( + data->parameters[i], CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/distribution_space.c b/src/distribution_space.c index 8e1f3851..cc1de98e 100644 --- a/src/distribution_space.c +++ b/src/distribution_space.c @@ -226,11 +226,10 @@ ccs_distribution_space_set_distribution( _ccs_distribution_wrapper_t *dwrapper; _ccs_distribution_wrapper_t **p_dwrappers_to_del; _ccs_distribution_wrapper_t **p_dwrappers_to_add; - _ccs_parameter_wrapper_cs_t *hwrapper; _ccs_parameter_distribution_t *pdists; _ccs_parameter_distribution_t *pdist; ccs_result_t err; - UT_array *parameters; + ccs_parameter_t *parameters; size_t num_parameters; size_t dim; uintptr_t mem; @@ -325,13 +324,12 @@ ccs_distribution_space_set_distribution( (size_t *)(dmem + sizeof(_ccs_distribution_wrapper_t)); dwrapper->dimension = 1; dwrapper->parameter_indexes[0] = parameters_without_distrib[i]; - hwrapper = (_ccs_parameter_wrapper_cs_t *)utarray_eltptr( - parameters, parameters_without_distrib[i]); CCS_VALIDATE_ERR_GOTO( err, ccs_parameter_get_default_distribution( - hwrapper->parameter, &(dwrapper->distribution)), + parameters[parameters_without_distrib[i]], + &(dwrapper->distribution)), dwrappers); p_dwrappers_to_add[to_add_count++] = dwrapper; } diff --git a/src/features_space.c b/src/features_space.c index 01243a64..adb95f5b 100644 --- a/src/features_space.c +++ b/src/features_space.c @@ -6,21 +6,16 @@ static ccs_result_t _ccs_features_space_del(ccs_object_t object) { - ccs_features_space_t features_space = (ccs_features_space_t)object; - UT_array *array = features_space->data->parameters; - _ccs_parameter_wrapper_t *wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - array, wrapper))) { - ccs_release_object(wrapper->parameter); - } + ccs_features_space_t features_space = (ccs_features_space_t)object; + size_t num_parameters = features_space->data->num_parameters; + ccs_parameter_t *parameters = features_space->data->parameters; + + for (size_t i = 0; i < num_parameters; i++) + if (parameters[i]) + ccs_release_object(parameters[i]); + HASH_CLEAR(hh_name, features_space->data->name_hash); - _ccs_parameter_index_hash_t *elem, *tmpelem; - HASH_ITER(hh_handle, features_space->data->handle_hash, elem, tmpelem) - { - HASH_DELETE(hh_handle, features_space->data->handle_hash, elem); - free(elem); - } - utarray_free(features_space->data->parameters); + HASH_CLEAR(hh_handle, features_space->data->handle_hash); return CCS_RESULT_SUCCESS; } @@ -73,82 +68,6 @@ static _ccs_features_space_ops_t _features_space_ops = { {{&_ccs_features_space_del, &_ccs_features_space_serialize_size, &_ccs_features_space_serialize}}}; -static const UT_icd _parameter_wrapper_icd = { - sizeof(_ccs_parameter_wrapper_t), - NULL, - NULL, - NULL, -}; - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errormem, \ - "Not enough memory to allocate array"); \ - } -#undef uthash_nonfatal_oom -#define uthash_nonfatal_oom(elt) \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errorutarray, \ - "Not enough memory to allocate hash"); \ - } -static ccs_result_t -_ccs_features_space_add_parameter( - ccs_features_space_t features_space, - ccs_parameter_t parameter) -{ - CCS_CHECK_OBJ(parameter, CCS_OBJECT_TYPE_PARAMETER); - ccs_result_t err; - const char *name; - size_t sz_name; - _ccs_parameter_index_hash_t *parameter_hash; - CCS_VALIDATE(ccs_parameter_get_name(parameter, &name)); - sz_name = strlen(name); - HASH_FIND( - hh_name, features_space->data->name_hash, name, sz_name, - parameter_hash); - CCS_REFUTE_MSG( - parameter_hash, CCS_RESULT_ERROR_INVALID_PARAMETER, - "An parameter with name '%s' already exists in the feature space", - name); - UT_array *parameters; - CCS_VALIDATE(ccs_retain_object(parameter)); - _ccs_parameter_wrapper_t parameter_wrapper; - parameter_wrapper.parameter = parameter; - - parameters = features_space->data->parameters; - parameter_hash = (_ccs_parameter_index_hash_t *)malloc( - sizeof(_ccs_parameter_index_hash_t)); - CCS_REFUTE_ERR_GOTO( - err, !parameter_hash, CCS_RESULT_ERROR_OUT_OF_MEMORY, - errorparameter); - parameter_hash->parameter = parameter; - parameter_hash->name = name; - parameter_hash->index = utarray_len(parameters); - - utarray_push_back(parameters, ¶meter_wrapper); - - HASH_ADD_KEYPTR( - hh_name, features_space->data->name_hash, parameter_hash->name, - sz_name, parameter_hash); - HASH_ADD( - hh_handle, features_space->data->handle_hash, parameter, - sizeof(ccs_parameter_t), parameter_hash); - - return CCS_RESULT_SUCCESS; -errorutarray: - utarray_pop_back(parameters); -errormem: - free(parameter_hash); -errorparameter: - ccs_release_object(parameter); - return err; -} -#undef utarray_oom -#define utarray_oom() exit(-1) - static ccs_result_t _ccs_features_space_add_parameters( ccs_features_space_t features_space, @@ -156,19 +75,11 @@ _ccs_features_space_add_parameters( ccs_parameter_t *parameters) { for (size_t i = 0; i < num_parameters; i++) - CCS_VALIDATE(_ccs_features_space_add_parameter( - features_space, parameters[i])); + CCS_VALIDATE(_ccs_context_add_parameter( + (ccs_context_t)features_space, parameters[i], i)); return CCS_RESULT_SUCCESS; } -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, arrays, \ - "Not enough memory to allocate array"); \ - } - ccs_result_t ccs_create_features_space( const char *name, @@ -180,46 +91,46 @@ ccs_create_features_space( CCS_CHECK_PTR(name); CCS_CHECK_PTR(features_space_ret); CCS_CHECK_ARY(num_parameters, parameters); + for (size_t i = 0; i < num_parameters; i++) + CCS_CHECK_OBJ(parameters[i], CCS_OBJECT_TYPE_PARAMETER); uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_features_space_s) + - sizeof(struct _ccs_features_space_data_s) + - strlen(name) + 1); + 1, + sizeof(struct _ccs_features_space_s) + + sizeof(struct _ccs_features_space_data_s) + + sizeof(ccs_parameter_t) * num_parameters + + sizeof(_ccs_parameter_index_hash_t) * num_parameters + + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); + uintptr_t mem_orig = mem; ccs_features_space_t feat_space = (ccs_features_space_t)mem; + mem += sizeof(struct _ccs_features_space_s); _ccs_object_init( &(feat_space->obj), CCS_OBJECT_TYPE_FEATURES_SPACE, (_ccs_object_ops_t *)&_features_space_ops); - feat_space->data = - (struct _ccs_features_space_data_s - *)(mem + sizeof(struct _ccs_features_space_s)); - feat_space->data->name = - (const char - *)(mem + sizeof(struct _ccs_features_space_s) + sizeof(struct _ccs_features_space_data_s)); - utarray_new(feat_space->data->parameters, &_parameter_wrapper_icd); + feat_space->data = (struct _ccs_features_space_data_s *)mem; + mem += sizeof(struct _ccs_features_space_data_s); + feat_space->data->parameters = (ccs_parameter_t *)mem; + mem += sizeof(ccs_parameter_t) * num_parameters; + feat_space->data->hash_elems = (_ccs_parameter_index_hash_t *)mem; + mem += sizeof(_ccs_parameter_index_hash_t) * num_parameters; + feat_space->data->name = (const char *)mem; + feat_space->data->num_parameters = num_parameters; strcpy((char *)(feat_space->data->name), name); - *features_space_ret = feat_space; CCS_VALIDATE_ERR_GOTO( err, _ccs_features_space_add_parameters( feat_space, num_parameters, parameters), errparams); + *features_space_ret = feat_space; return CCS_RESULT_SUCCESS; -arrays: - if (feat_space->data->parameters) - utarray_free(feat_space->data->parameters); - _ccs_object_deinit(&(feat_space->obj)); - free((void *)mem); - return err; errparams: _ccs_features_space_del(feat_space); _ccs_object_deinit(&(feat_space->obj)); - free((void *)mem); + free((void *)mem_orig); return err; } -#undef utarray_oom -#define utarray_oom() exit(-1) ccs_result_t ccs_features_space_get_name( @@ -340,17 +251,15 @@ _check_features( ccs_datum_t *values, ccs_bool_t *is_valid_ret) { - UT_array *array = features_space->data->parameters; - size_t num_parameters = utarray_len(array); + ccs_parameter_t *parameters = features_space->data->parameters; + size_t num_parameters = features_space->data->num_parameters; CCS_REFUTE( num_values != num_parameters, CCS_RESULT_ERROR_INVALID_FEATURES); *is_valid_ret = CCS_TRUE; for (size_t i = 0; i < num_values; i++) { - _ccs_parameter_wrapper_t *wrapper = - (_ccs_parameter_wrapper_t *)utarray_eltptr(array, i); CCS_VALIDATE(ccs_parameter_check_value( - wrapper->parameter, values[i], is_valid_ret)); + parameters[i], values[i], is_valid_ret)); if (*is_valid_ret == CCS_FALSE) return CCS_RESULT_SUCCESS; } diff --git a/src/features_space_internal.h b/src/features_space_internal.h index ed79601d..c723e2d8 100644 --- a/src/features_space_internal.h +++ b/src/features_space_internal.h @@ -17,7 +17,9 @@ struct _ccs_features_space_s { struct _ccs_features_space_data_s { const char *name; - UT_array *parameters; + size_t num_parameters; + ccs_parameter_t *parameters; + _ccs_parameter_index_hash_t *hash_elems; _ccs_parameter_index_hash_t *name_hash; _ccs_parameter_index_hash_t *handle_hash; }; diff --git a/src/objective_space.c b/src/objective_space.c index 11e98c88..0a74e24c 100644 --- a/src/objective_space.c +++ b/src/objective_space.c @@ -7,27 +7,21 @@ static ccs_result_t _ccs_objective_space_del(ccs_object_t object) { ccs_objective_space_t objective_space = (ccs_objective_space_t)object; - UT_array *array = objective_space->data->parameters; - _ccs_parameter_wrapper_t *wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - array, wrapper))) { - ccs_release_object(wrapper->parameter); - } - array = objective_space->data->objectives; - _ccs_objective_t *obj = NULL; - while ((obj = (_ccs_objective_t *)utarray_next(array, obj))) { - ccs_release_object(obj->expression); - } + size_t num_parameters = objective_space->data->num_parameters; + ccs_parameter_t *parameters = objective_space->data->parameters; + size_t num_objectives = objective_space->data->num_objectives; + _ccs_objective_t *objectives = objective_space->data->objectives; + + for (size_t i = 0; i < num_parameters; i++) + if (parameters[i]) + ccs_release_object(parameters[i]); + + for (size_t i = 0; i < num_objectives; i++) + if (objectives[i].expression) + ccs_release_object(objectives[i].expression); + HASH_CLEAR(hh_name, objective_space->data->name_hash); - _ccs_parameter_index_hash_t *elem, *tmpelem; - HASH_ITER(hh_handle, objective_space->data->handle_hash, elem, tmpelem) - { - HASH_DELETE( - hh_handle, objective_space->data->handle_hash, elem); - free(elem); - } - utarray_free(objective_space->data->parameters); - utarray_free(objective_space->data->objectives); + HASH_CLEAR(hh_handle, objective_space->data->handle_hash); return CCS_RESULT_SUCCESS; } @@ -37,32 +31,28 @@ _ccs_serialize_bin_size_ccs_objective_space_data( size_t *cum_size, _ccs_object_serialize_options_t *opts) { - _ccs_parameter_wrapper_t *wrapper; - _ccs_objective_t *objective; + 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_size(utarray_len(data->parameters)); - *cum_size += - _ccs_serialize_bin_size_size(utarray_len(data->objectives)); + *cum_size += _ccs_serialize_bin_size_size(num_parameters); + *cum_size += _ccs_serialize_bin_size_size(num_objectives); /* parameters */ - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize_size( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, - cum_size, opts)); + for (size_t i = 0; i < num_parameters; i++) + CCS_VALIDATE(parameters[i]->obj.ops->serialize_size( + parameters[i], CCS_SERIALIZE_FORMAT_BINARY, cum_size, + opts)); /* objectives */ - objective = NULL; - while ((objective = (_ccs_objective_t *)utarray_next( - data->objectives, objective))) { - CCS_VALIDATE(objective->expression->obj.ops->serialize_size( - objective->expression, CCS_SERIALIZE_FORMAT_BINARY, + for (size_t i = 0; i < num_objectives; i++) { + CCS_VALIDATE(objectives[i].expression->obj.ops->serialize_size( + objectives[i].expression, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); *cum_size += _ccs_serialize_bin_size_ccs_objective_type( - objective->type); + objectives[i].type); } return CCS_RESULT_SUCCESS; @@ -75,33 +65,31 @@ _ccs_serialize_bin_ccs_objective_space_data( char **buffer, _ccs_object_serialize_options_t *opts) { - _ccs_parameter_wrapper_t *wrapper; - _ccs_objective_t *objective; + 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_size( - utarray_len(data->parameters), buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->objectives), buffer_size, buffer)); + CCS_VALIDATE( + _ccs_serialize_bin_size(num_parameters, buffer_size, buffer)); + CCS_VALIDATE( + _ccs_serialize_bin_size(num_objectives, buffer_size, buffer)); /* parameters */ - wrapper = NULL; - while ((wrapper = (_ccs_parameter_wrapper_t *)utarray_next( - data->parameters, wrapper))) - CCS_VALIDATE(wrapper->parameter->obj.ops->serialize( - wrapper->parameter, CCS_SERIALIZE_FORMAT_BINARY, - buffer_size, buffer, opts)); + for (size_t i = 0; i < num_parameters; i++) + CCS_VALIDATE(parameters[i]->obj.ops->serialize( + parameters[i], CCS_SERIALIZE_FORMAT_BINARY, buffer_size, + buffer, opts)); /* objectives */ - objective = NULL; - while ((objective = (_ccs_objective_t *)utarray_next( - data->objectives, objective))) { - CCS_VALIDATE(objective->expression->obj.ops->serialize( - objective->expression, CCS_SERIALIZE_FORMAT_BINARY, + for (size_t i = 0; i < num_objectives; i++) { + CCS_VALIDATE(objectives[i].expression->obj.ops->serialize( + objectives[i].expression, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, opts)); CCS_VALIDATE(_ccs_serialize_bin_ccs_objective_type( - objective->type, buffer_size, buffer)); + objectives[i].type, buffer_size, buffer)); } return CCS_RESULT_SUCCESS; @@ -189,90 +177,6 @@ static _ccs_objective_space_ops_t _objective_space_ops = { {{&_ccs_objective_space_del, &_ccs_objective_space_serialize_size, &_ccs_objective_space_serialize}}}; -static const UT_icd _parameter_wrapper2_icd = { - sizeof(_ccs_parameter_wrapper_t), - NULL, - NULL, - NULL, -}; - -static const UT_icd _objectives_icd = { - sizeof(_ccs_objective_t), - NULL, - NULL, - NULL, -}; - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errormem, \ - "Not enough memory to allocate array"); \ - } -#undef uthash_nonfatal_oom -#define uthash_nonfatal_oom(elt) \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, errorutarray, \ - "Not enough memory to allocate hash"); \ - } -static ccs_result_t -_ccs_objective_space_add_parameter( - ccs_objective_space_t objective_space, - ccs_parameter_t parameter) -{ - CCS_CHECK_OBJ(parameter, CCS_OBJECT_TYPE_PARAMETER); - ccs_result_t err; - const char *name; - size_t sz_name; - _ccs_parameter_index_hash_t *parameter_hash; - CCS_VALIDATE(ccs_parameter_get_name(parameter, &name)); - sz_name = strlen(name); - HASH_FIND( - hh_name, objective_space->data->name_hash, name, sz_name, - parameter_hash); - CCS_REFUTE_MSG( - parameter_hash, CCS_RESULT_ERROR_INVALID_PARAMETER, - "An parameter with name '%s' already exists in the objective space", - name); - UT_array *parameters; - CCS_VALIDATE(ccs_retain_object(parameter)); - _ccs_parameter_wrapper_t parameter_wrapper; - parameter_wrapper.parameter = parameter; - - parameters = objective_space->data->parameters; - - parameter_hash = (_ccs_parameter_index_hash_t *)malloc( - sizeof(_ccs_parameter_index_hash_t)); - CCS_REFUTE_ERR_GOTO( - err, !parameter_hash, CCS_RESULT_ERROR_OUT_OF_MEMORY, - errorparameter); - parameter_hash->parameter = parameter; - parameter_hash->name = name; - parameter_hash->index = utarray_len(parameters); - - utarray_push_back(parameters, ¶meter_wrapper); - - HASH_ADD_KEYPTR( - hh_name, objective_space->data->name_hash, parameter_hash->name, - sz_name, parameter_hash); - HASH_ADD( - hh_handle, objective_space->data->handle_hash, parameter, - sizeof(ccs_parameter_t), parameter_hash); - - return CCS_RESULT_SUCCESS; -errorutarray: - utarray_pop_back(parameters); -errormem: - free(parameter_hash); -errorparameter: - ccs_release_object(parameter); - return err; -} -#undef utarray_oom -#define utarray_oom() exit(-1) - static ccs_result_t _ccs_objective_space_add_parameters( ccs_objective_space_t objective_space, @@ -280,19 +184,11 @@ _ccs_objective_space_add_parameters( ccs_parameter_t *parameters) { for (size_t i = 0; i < num_parameters; i++) - CCS_VALIDATE(_ccs_objective_space_add_parameter( - objective_space, parameters[i])); + CCS_VALIDATE(_ccs_context_add_parameter( + (ccs_context_t)objective_space, parameters[i], i)); return CCS_RESULT_SUCCESS; } -#undef utarray_oom -#define utarray_oom() \ - { \ - ccs_release_object(expressions[i]); \ - CCS_RAISE( \ - CCS_RESULT_ERROR_OUT_OF_MEMORY, \ - "Out of memory to allocate array"); \ - } ccs_result_t _ccs_objective_space_add_objectives( ccs_objective_space_t objective_space, @@ -300,29 +196,16 @@ _ccs_objective_space_add_objectives( ccs_expression_t *expressions, ccs_objective_type_t *types) { - ccs_result_t err = CCS_RESULT_SUCCESS; + _ccs_objective_t *objectives = objective_space->data->objectives; for (size_t i = 0; i < num_objectives; i++) { CCS_VALIDATE(ccs_expression_check_context( expressions[i], (ccs_context_t)objective_space)); CCS_VALIDATE(ccs_retain_object(expressions[i])); - _ccs_objective_t objective; - objective.expression = expressions[i]; - objective.type = types[i]; - utarray_push_back( - objective_space->data->objectives, &objective); + objectives[i].expression = expressions[i]; + objectives[i].type = types[i]; } - return err; + return CCS_RESULT_SUCCESS; } -#undef utarray_oom -#define utarray_oom() exit(-1) - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, arrays, \ - "Not enough memory to allocate array"); \ - } ccs_result_t ccs_create_objective_space( @@ -341,25 +224,33 @@ ccs_create_objective_space( CCS_CHECK_ARY(num_objectives, types); uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_objective_space_s) + - sizeof(struct _ccs_objective_space_data_s) + - strlen(name) + 1); + 1, + sizeof(struct _ccs_objective_space_s) + + sizeof(struct _ccs_objective_space_data_s) + + sizeof(ccs_parameter_t) * num_parameters + + sizeof(_ccs_parameter_index_hash_t) * num_parameters + + sizeof(_ccs_objective_t) * num_objectives + + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); + uintptr_t mem_orig = mem; ccs_result_t err; ccs_objective_space_t obj_space = (ccs_objective_space_t)mem; + mem += sizeof(struct _ccs_objective_space_s); _ccs_object_init( &(obj_space->obj), CCS_OBJECT_TYPE_OBJECTIVE_SPACE, (_ccs_object_ops_t *)&_objective_space_ops); - obj_space->data = - (struct _ccs_objective_space_data_s - *)(mem + sizeof(struct _ccs_objective_space_s)); - obj_space->data->name = - (const char - *)(mem + sizeof(struct _ccs_objective_space_s) + sizeof(struct _ccs_objective_space_data_s)); - utarray_new(obj_space->data->parameters, &_parameter_wrapper2_icd); - utarray_new(obj_space->data->objectives, &_objectives_icd); + obj_space->data = (struct _ccs_objective_space_data_s *)mem; + mem += sizeof(struct _ccs_objective_space_data_s); + obj_space->data->parameters = (ccs_parameter_t *)mem; + mem += sizeof(ccs_parameter_t) * num_parameters; + obj_space->data->hash_elems = (_ccs_parameter_index_hash_t *)mem; + mem += sizeof(_ccs_parameter_index_hash_t) * num_parameters; + obj_space->data->objectives = (_ccs_objective_t *)mem; + mem += sizeof(_ccs_objective_t) * num_objectives; + obj_space->data->name = (const char *)mem; + obj_space->data->num_parameters = num_parameters; + obj_space->data->num_objectives = num_objectives; strcpy((char *)(obj_space->data->name), name); - *objective_space_ret = obj_space; CCS_VALIDATE_ERR_GOTO( err, _ccs_objective_space_add_parameters( @@ -370,23 +261,14 @@ ccs_create_objective_space( _ccs_objective_space_add_objectives( obj_space, num_objectives, objectives, types), errparams); + *objective_space_ret = obj_space; return CCS_RESULT_SUCCESS; -arrays: - if (obj_space->data->parameters) - utarray_free(obj_space->data->parameters); - if (obj_space->data->objectives) - utarray_free(obj_space->data->objectives); - _ccs_object_deinit(&(obj_space->obj)); - free((void *)mem); - return err; errparams: _ccs_objective_space_del(obj_space); _ccs_object_deinit(&(obj_space->obj)); - free((void *)mem); + free((void *)mem_orig); return err; } -#undef utarray_oom -#define utarray_oom() exit(-1) ccs_result_t ccs_objective_space_get_name( @@ -494,17 +376,15 @@ _check_evaluation( ccs_datum_t *values, ccs_bool_t *is_valid_ret) { - UT_array *array = objective_space->data->parameters; - size_t num_parameters = utarray_len(array); + ccs_parameter_t *parameters = objective_space->data->parameters; + size_t num_parameters = objective_space->data->num_parameters; CCS_REFUTE( num_values != num_parameters, CCS_RESULT_ERROR_INVALID_EVALUATION); *is_valid_ret = CCS_TRUE; for (size_t i = 0; i < num_values; i++) { - _ccs_parameter_wrapper_t *wrapper = - (_ccs_parameter_wrapper_t *)utarray_eltptr(array, i); CCS_VALIDATE(ccs_parameter_check_value( - wrapper->parameter, values[i], is_valid_ret)); + parameters[i], values[i], is_valid_ret)); if (*is_valid_ret == CCS_FALSE) return CCS_RESULT_SUCCESS; } @@ -548,11 +428,12 @@ ccs_objective_space_get_objective( CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_CHECK_PTR(expression_ret); CCS_CHECK_PTR(type_ret); - _ccs_objective_t *p_obj = (_ccs_objective_t *)utarray_eltptr( - objective_space->data->objectives, (unsigned int)index); - CCS_REFUTE(!p_obj, CCS_RESULT_ERROR_OUT_OF_BOUNDS); - *expression_ret = p_obj->expression; - *type_ret = p_obj->type; + CCS_REFUTE( + index >= objective_space->data->num_objectives, + CCS_RESULT_ERROR_OUT_OF_BOUNDS); + _ccs_objective_t *p_obj = objective_space->data->objectives + index; + *expression_ret = p_obj->expression; + *type_ret = p_obj->type; return CCS_RESULT_SUCCESS; } @@ -570,18 +451,14 @@ ccs_objective_space_get_objectives( CCS_REFUTE( !expressions && !num_objectives_ret, CCS_RESULT_ERROR_INVALID_VALUE); - UT_array *array = objective_space->data->objectives; - size_t size = utarray_len(array); + _ccs_objective_t *objectives = objective_space->data->objectives; + size_t size = objective_space->data->num_objectives; if (expressions) { CCS_REFUTE( num_objectives < size, CCS_RESULT_ERROR_INVALID_VALUE); - _ccs_objective_t *p_obj = NULL; - size_t index = 0; - while ((p_obj = (_ccs_objective_t *)utarray_next( - array, p_obj))) { - expressions[index] = p_obj->expression; - types[index] = p_obj->type; - index++; + for (size_t i = 0; i < size; i++) { + expressions[i] = objectives[i].expression; + types[i] = objectives[i].type; } for (size_t i = size; i < num_objectives; i++) { expressions[i] = NULL; diff --git a/src/objective_space_internal.h b/src/objective_space_internal.h index e99993a2..a7b0f7a0 100644 --- a/src/objective_space_internal.h +++ b/src/objective_space_internal.h @@ -24,10 +24,13 @@ struct _ccs_objective_space_s { struct _ccs_objective_space_data_s { const char *name; - UT_array *parameters; + size_t num_parameters; + ccs_parameter_t *parameters; + _ccs_parameter_index_hash_t *hash_elems; _ccs_parameter_index_hash_t *name_hash; _ccs_parameter_index_hash_t *handle_hash; - UT_array *objectives; + size_t num_objectives; + _ccs_objective_t *objectives; }; #endif //_OBJECTIVE_SPACE_INTERNAL_H diff --git a/tests/test_condition.c b/tests/test_condition.c index ed27b198..2d21d585 100644 --- a/tests/test_condition.c +++ b/tests/test_condition.c @@ -30,7 +30,8 @@ test_simple(void) parameters[0] = parameter1 = create_numerical("param1"); parameters[1] = parameter2 = create_numerical("param2"); - err = ccs_create_configuration_space("space", 2, parameters, &space); + err = ccs_create_configuration_space( + "space", 2, parameters, 0, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_binary_expression( @@ -114,7 +115,8 @@ test_transitive(void) parameters[1] = create_numerical("param2"); parameters[2] = create_numerical("param3"); - err = ccs_create_configuration_space("space", 3, parameters, &space); + err = ccs_create_configuration_space( + "space", 3, parameters, 0, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_binary_expression( diff --git a/tests/test_configuration_space.c b/tests/test_configuration_space.c index 89ae1ccc..fc8266b2 100644 --- a/tests/test_configuration_space.c +++ b/tests/test_configuration_space.c @@ -98,7 +98,7 @@ test_empty(void) ccs_result_t err; err = ccs_create_configuration_space( - "my_config_space", 0, NULL, &configuration_space); + "my_config_space", 0, NULL, 0, NULL, &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( @@ -134,17 +134,19 @@ test_create(void) parameters[2] = parameters[0]; err = ccs_create_configuration_space( - "my_config_space", 3, NULL, &configuration_space); + "my_config_space", 3, NULL, 0, NULL, &configuration_space); assert(err == CCS_RESULT_ERROR_INVALID_VALUE); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &configuration_space); + "my_config_space", 3, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_ERROR_INVALID_PARAMETER); parameters[2] = parameter3; err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &configuration_space); + "my_config_space", 3, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_object_get_type(configuration_space, &type); @@ -184,7 +186,8 @@ test_sample(void) assert(err == CCS_RESULT_SUCCESS); err = ccs_create_configuration_space( - "my_config_space", 4, parameters, &configuration_space); + "my_config_space", 4, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( @@ -247,7 +250,8 @@ test_configuration_deserialize(void) parameters[2] = create_numerical("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &configuration_space); + "my_config_space", 3, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample( @@ -325,8 +329,14 @@ test_deserialize(void) parameters[1] = create_numerical("param2"); parameters[2] = create_numerical("param3"); - err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &space); + err = ccs_create_binary_expression( + CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]), + ccs_float(0.0), &expression); + assert(err == CCS_RESULT_SUCCESS); + err = ccs_create_configuration_space( + "my_config_space", 3, parameters, 1, &expression, &space); + assert(err == CCS_RESULT_SUCCESS); + err = ccs_release_object(expression); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_binary_expression( @@ -347,15 +357,6 @@ test_deserialize(void) err = ccs_release_object(expression); assert(err == CCS_RESULT_SUCCESS); - err = ccs_create_binary_expression( - CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]), - ccs_float(0.0), &expression); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_space_add_forbidden_clause(space, expression); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_release_object(expression); - assert(err == CCS_RESULT_SUCCESS); - for (size_t i = 0; i < 3; i++) { err = ccs_release_object(parameters[i]); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_distribution_space.c b/tests/test_distribution_space.c index 5dd91239..2e5ad7fe 100644 --- a/tests/test_distribution_space.c +++ b/tests/test_distribution_space.c @@ -129,7 +129,8 @@ test_create(void) parameters[2] = create_dummy_parameter("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &configuration_space); + "my_config_space", 3, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_distribution_space( @@ -175,7 +176,8 @@ test_set_distribution(void) parameters[2] = create_dummy_parameter("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &configuration_space); + "my_config_space", 3, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_distribution_space( @@ -321,7 +323,7 @@ test_deserialize(void) parameters[2] = create_numerical("param3"); err = ccs_create_configuration_space( - "my_config_space", 3, parameters, &space); + "my_config_space", 3, parameters, 0, NULL, &space); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_distribution_space(space, &distrib_space); diff --git a/tests/test_expression.c b/tests/test_expression.c index 49b9cc3c..3c3c3696 100644 --- a/tests/test_expression.c +++ b/tests/test_expression.c @@ -168,7 +168,8 @@ test_equal_numerical(void) parameters[1] = create_dummy_numerical("param2"); err = ccs_create_configuration_space( - "my_config_space", 2, parameters, &configuration_space); + "my_config_space", 2, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); nodes[0] = ccs_object(parameters[0]); @@ -222,7 +223,8 @@ 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, &configuration_space); + "my_config_space", 2, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); nodes[0] = ccs_object(parameters[0]); @@ -262,7 +264,8 @@ 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, &configuration_space); + "my_config_space", 2, parameters, 0, NULL, + &configuration_space); assert(err == CCS_RESULT_SUCCESS); nodes[0] = ccs_object(parameters[0]); @@ -900,7 +903,8 @@ test_check_context(void) parameters[0] = parameter1; parameters[1] = parameter2; - err = ccs_create_configuration_space("space", 2, parameters, &space); + err = ccs_create_configuration_space( + "space", 2, parameters, 0, 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 d8984033..0eeb3411 100644 --- a/tests/test_forbidden.c +++ b/tests/test_forbidden.c @@ -30,15 +30,12 @@ test_simple(void) parameters[0] = parameter1 = create_numerical("param1"); parameters[1] = parameter2 = create_numerical("param2"); - err = ccs_create_configuration_space("space", 2, parameters, &space); + err = ccs_create_binary_expression( + CCS_EXPRESSION_TYPE_LESS, ccs_object(parameter1), + ccs_float(0.0), &expression); assert(err == CCS_RESULT_SUCCESS); - - err = ccs_create_binary_expression( - CCS_EXPRESSION_TYPE_LESS, ccs_object(parameter1), - ccs_float(0.0), &expression); - assert(err == CCS_RESULT_SUCCESS); - - err = ccs_configuration_space_add_forbidden_clause(space, expression); + err = ccs_create_configuration_space( + "space", 2, parameters, 1, &expression, &space); assert(err == CCS_RESULT_SUCCESS); for (int i = 0; i < 100; i++) { @@ -111,7 +108,14 @@ test_combined(void) parameters[1] = create_numerical("param2"); parameters[2] = create_numerical("param3"); - err = ccs_create_configuration_space("space", 3, parameters, &space); + err = ccs_create_binary_expression( + CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]), + ccs_float(0.0), &expression); + assert(err == CCS_RESULT_SUCCESS); + err = ccs_create_configuration_space( + "space", 3, parameters, 1, &expression, &space); + assert(err == CCS_RESULT_SUCCESS); + err = ccs_release_object(expression); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_binary_expression( @@ -132,15 +136,6 @@ test_combined(void) err = ccs_release_object(expression); assert(err == CCS_RESULT_SUCCESS); - err = ccs_create_binary_expression( - CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]), - ccs_float(0.0), &expression); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_space_add_forbidden_clause(space, expression); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_release_object(expression); - assert(err == CCS_RESULT_SUCCESS); - for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; diff --git a/tests/test_random_features_tuner.c b/tests/test_random_features_tuner.c index ff13ae81..75257104 100644 --- a/tests/test_random_features_tuner.c +++ b/tests/test_random_features_tuner.c @@ -39,7 +39,8 @@ test(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY); @@ -262,7 +263,8 @@ test_evaluation_deserialize(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample(cspace, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_random_tuner.c b/tests/test_random_tuner.c index b20a36fa..26fce85d 100644 --- a/tests/test_random_tuner.c +++ b/tests/test_random_tuner.c @@ -35,7 +35,8 @@ test(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY); @@ -176,7 +177,8 @@ test_evaluation_deserialize(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); err = ccs_configuration_space_sample(cspace, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_user_defined_features_tuner.c b/tests/test_user_defined_features_tuner.c index b68d1213..6901f963 100644 --- a/tests/test_user_defined_features_tuner.c +++ b/tests/test_user_defined_features_tuner.c @@ -180,7 +180,8 @@ test(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY); diff --git a/tests/test_user_defined_tuner.c b/tests/test_user_defined_tuner.c index d33f1563..cc3464d3 100644 --- a/tests/test_user_defined_tuner.c +++ b/tests/test_user_defined_tuner.c @@ -164,7 +164,8 @@ test(void) parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0); parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0); - err = ccs_create_configuration_space("2dplane", 2, parameters, &cspace); + err = ccs_create_configuration_space( + "2dplane", 2, parameters, 0, NULL, &cspace); assert(err == CCS_RESULT_SUCCESS); parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY);