Commit c4fbf826 authored by Brice Videau's avatar Brice Videau

Fix c++ library.

parent 8fec6645
...@@ -28,25 +28,8 @@ ccs_interval_equal(ccs_interval_t *interval1, ...@@ -28,25 +28,8 @@ ccs_interval_equal(ccs_interval_t *interval1,
ccs_interval_t *interval2, ccs_interval_t *interval2,
ccs_bool_t *equal_res); ccs_bool_t *equal_res);
inline ccs_bool_t extern ccs_bool_t
ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) { ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value);
if (interval->type == CCS_NUM_FLOAT) {
return ( interval->lower_included ?
interval->lower.f <= value.f :
interval->lower.f < value.f ) &&
( interval->upper_included ?
interval->upper.f >= value.f :
interval->upper.f > value.f );
} else {
return ( interval->lower_included ?
interval->lower.i <= value.i :
interval->lower.i < value.i ) &&
( interval->upper_included ?
interval->upper.i >= value.i :
interval->upper.i > value.i );
}
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -3,6 +3,25 @@ ...@@ -3,6 +3,25 @@
#include <cconfigspace.h> #include <cconfigspace.h>
static inline ccs_bool_t
_ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) {
if (interval->type == CCS_NUM_FLOAT) {
return ( interval->lower_included ?
interval->lower.f <= value.f :
interval->lower.f < value.f ) &&
( interval->upper_included ?
interval->upper.f >= value.f :
interval->upper.f > value.f );
} else {
return ( interval->lower_included ?
interval->lower.i <= value.i :
interval->lower.i < value.i ) &&
( interval->upper_included ?
interval->upper.i >= value.i :
interval->upper.i > value.i );
}
}
struct _ccs_object_ops_s { struct _ccs_object_ops_s {
ccs_result_t (*del)(ccs_object_t object); ccs_result_t (*del)(ccs_object_t object);
}; };
......
...@@ -28,14 +28,14 @@ _ccs_hyperparameter_numerical_check_values(_ccs_hyperparameter_data_t *data, ...@@ -28,14 +28,14 @@ _ccs_hyperparameter_numerical_check_values(_ccs_hyperparameter_data_t *data,
if (values[i].type != CCS_FLOAT) if (values[i].type != CCS_FLOAT)
results[i] = CCS_FALSE; results[i] = CCS_FALSE;
else else
results[i] = ccs_interval_include(interval, CCSF(values[i].value.f)); results[i] = _ccs_interval_include(interval, CCSF(values[i].value.f));
} }
else { else {
for(size_t i = 0; i < num_values; i++) for(size_t i = 0; i < num_values; i++)
if (values[i].type != CCS_INTEGER) if (values[i].type != CCS_INTEGER)
results[i] = CCS_FALSE; results[i] = CCS_FALSE;
else else
results[i] = ccs_interval_include(interval, CCSI(values[i].value.i)); results[i] = _ccs_interval_include(interval, CCSI(values[i].value.i));
} }
return CCS_SUCCESS; return CCS_SUCCESS;
} }
...@@ -75,11 +75,11 @@ _ccs_hyperparameter_numerical_samples(_ccs_hyperparameter_data_t *data, ...@@ -75,11 +75,11 @@ _ccs_hyperparameter_numerical_samples(_ccs_hyperparameter_data_t *data,
size_t found = 0; size_t found = 0;
if (type == CCS_NUM_FLOAT) { if (type == CCS_NUM_FLOAT) {
for(size_t i = 0; i < num_values; i++) for(size_t i = 0; i < num_values; i++)
if (ccs_interval_include(interval, vs[i])) if (_ccs_interval_include(interval, vs[i]))
values[found++].value.f = vs[i].f; values[found++].value.f = vs[i].f;
} else { } else {
for(size_t i = 0; i < num_values; i++) for(size_t i = 0; i < num_values; i++)
if (ccs_interval_include(interval, vs[i])) if (_ccs_interval_include(interval, vs[i]))
values[found++].value.i = vs[i].i; values[found++].value.i = vs[i].i;
} }
vs = NULL; vs = NULL;
...@@ -93,11 +93,11 @@ _ccs_hyperparameter_numerical_samples(_ccs_hyperparameter_data_t *data, ...@@ -93,11 +93,11 @@ _ccs_hyperparameter_numerical_samples(_ccs_hyperparameter_data_t *data,
buff_sz, vs); buff_sz, vs);
if (type == CCS_NUM_FLOAT) { if (type == CCS_NUM_FLOAT) {
for(size_t i = 0; i < buff_sz && found < num_values; i++) for(size_t i = 0; i < buff_sz && found < num_values; i++)
if (ccs_interval_include(interval, vs[i])) if (_ccs_interval_include(interval, vs[i]))
values[found++].value.f = vs[i].f; values[found++].value.f = vs[i].f;
} else { } else {
for(size_t i = 0; i < buff_sz && found < num_values; i++) for(size_t i = 0; i < buff_sz && found < num_values; i++)
if (ccs_interval_include(interval, vs[i])) if (_ccs_interval_include(interval, vs[i]))
values[found++].value.i = vs[i].i; values[found++].value.i = vs[i].i;
} }
coeff <<= 1; coeff <<= 1;
......
#include "cconfigspace.h" #include "cconfigspace_internal.h"
ccs_result_t ccs_result_t
ccs_interval_empty(ccs_interval_t *interval, ccs_bool_t *empty_ret) { ccs_interval_empty(ccs_interval_t *interval, ccs_bool_t *empty_ret) {
...@@ -117,5 +117,7 @@ ccs_interval_equal(ccs_interval_t *interval1, ...@@ -117,5 +117,7 @@ ccs_interval_equal(ccs_interval_t *interval1,
return CCS_SUCCESS; return CCS_SUCCESS;
} }
extern inline ccs_bool_t ccs_bool_t
ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value); ccs_interval_include(ccs_interval_t *interval, ccs_numeric_t value) {
return _ccs_interval_include(interval, value);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment