Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Brice Videau
CCS
Commits
a20553b2
Commit
a20553b2
authored
May 27, 2020
by
Brice Videau
Browse files
Added a check on configurations.
parent
80f82b8c
Changes
8
Hide whitespace changes
Inline
Side-by-side
include/ccs/base.h
View file @
a20553b2
...
...
@@ -38,6 +38,7 @@ enum ccs_error_e {
CCS_INVALID_SCALE
,
CCS_INVALID_DISTRIBUTION
,
CCS_INVALID_HYPERPARAMETER
,
CCS_INVALID_CONFIGURATION
,
CCS_INVALID_NAME
,
CCS_TYPE_NOT_COMPARABLE
,
CCS_INVALID_BOUNDS
,
...
...
include/ccs/configuration.h
View file @
a20553b2
...
...
@@ -45,6 +45,9 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
const
char
*
name
,
ccs_datum_t
*
value_ret
);
extern
ccs_error_t
ccs_configuration_check
(
ccs_configuration_t
configuration
);
#ifdef __cplusplus
}
#endif
...
...
src/configuration.c
View file @
a20553b2
...
...
@@ -153,3 +153,10 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
}
ccs_error_t
ccs_configuration_check
(
ccs_configuration_t
configuration
)
{
if
(
!
configuration
||
!
configuration
->
data
)
return
-
CCS_INVALID_OBJECT
;
return
ccs_configuration_space_check_configuration
(
configuration
->
data
->
configuration_space
,
configuration
);
}
src/configuration_space.c
View file @
a20553b2
#include "cconfigspace_internal.h"
#include "configuration_space_internal.h"
#include "configuration_internal.h"
static
inline
_ccs_configuration_space_ops_t
*
ccs_configuration_space_get_ops
(
ccs_configuration_space_t
configuration_space
)
{
...
...
@@ -369,4 +370,32 @@ error:
return
err
;
}
ccs_error_t
ccs_configuration_space_check_configuration
(
ccs_configuration_space_t
configuration_space
,
ccs_configuration_t
configuration
)
{
if
(
!
configuration_space
||
!
configuration_space
->
data
)
return
-
CCS_INVALID_OBJECT
;
if
(
!
configuration
||
!
configuration
->
data
)
return
-
CCS_INVALID_OBJECT
;
if
(
configuration
->
data
->
configuration_space
!=
configuration_space
)
return
-
CCS_INVALID_CONFIGURATION
;
size_t
index
=
0
;
UT_array
*
array
=
configuration_space
->
data
->
hyperparameters
;
if
(
configuration
->
data
->
num_values
!=
utarray_len
(
array
))
return
-
CCS_INVALID_CONFIGURATION
;
_ccs_hyperparameter_wrapper_t
*
wrapper
=
NULL
;
ccs_datum_t
*
values
=
configuration
->
data
->
values
;
while
(
(
wrapper
=
(
_ccs_hyperparameter_wrapper_t
*
)
utarray_next
(
array
,
wrapper
))
)
{
ccs_bool_t
res
;
ccs_error_t
err
;
err
=
ccs_hyperparameter_check_value
(
wrapper
->
hyperparameter
,
values
[
index
++
],
&
res
);
if
(
unlikely
(
err
))
return
err
;
if
(
res
==
CCS_FALSE
)
return
-
CCS_INVALID_CONFIGURATION
;
}
return
CCS_SUCCESS
;
}
tests/test_categorical_hyperparameter.c
View file @
a20553b2
...
...
@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t
type
;
ccs_datum_t
default_value
;
ccs_error_t
err
;
ccs_bool_t
check
;
const
char
*
name
;
void
*
user_data
;
ccs_distribution_t
distribution
;
...
...
@@ -60,6 +61,18 @@ void test_create() {
assert
(
interval
.
upper
.
i
==
4
);
assert
(
interval
.
upper_included
==
CCS_FALSE
);
for
(
size_t
i
=
0
;
i
<
num_possible_values
;
i
++
)
{
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
possible_values
[
i
],
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_TRUE
);
}
default_value
.
type
=
CCS_FLOAT
;
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
default_value
,
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_FALSE
);
err
=
ccs_release_object
(
distribution
);
assert
(
err
==
CCS_SUCCESS
);
err
=
ccs_release_object
(
hyperparameter
);
...
...
tests/test_configuration_space.c
View file @
a20553b2
...
...
@@ -94,6 +94,9 @@ void check_configuration(ccs_configuration_space_t configuration_space,
err
=
ccs_configuration_space_get_default_configuration
(
configuration_space
,
&
configuration
);
assert
(
err
==
CCS_SUCCESS
);
err
=
ccs_configuration_check
(
configuration
);
assert
(
err
==
CCS_SUCCESS
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
ccs_datum_t
datum
;
ccs_datum_t
hdatum
;
...
...
tests/test_numerical_hyperparameter.c
View file @
a20553b2
...
...
@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t
type
;
ccs_datum_t
default_value
;
ccs_error_t
err
;
ccs_bool_t
check
;
const
char
*
name
;
void
*
user_data
;
ccs_distribution_t
distribution
;
...
...
@@ -54,6 +55,15 @@ void test_create() {
assert
(
interval
.
upper
.
f
==
5
.
0
);
assert
(
interval
.
upper_included
==
CCS_FALSE
);
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
default_value
,
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_TRUE
);
default_value
.
value
.
f
=
6
.
0
;
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
default_value
,
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_FALSE
);
err
=
ccs_release_object
(
distribution
);
assert
(
err
==
CCS_SUCCESS
);
err
=
ccs_release_object
(
hyperparameter
);
...
...
tests/test_ordinal_hyperparameter.c
View file @
a20553b2
...
...
@@ -8,6 +8,7 @@ void test_create() {
ccs_hyperparameter_type_t
type
;
ccs_datum_t
default_value
;
ccs_error_t
err
;
ccs_bool_t
check
;
const
char
*
name
;
void
*
user_data
;
ccs_distribution_t
distribution
;
...
...
@@ -61,6 +62,18 @@ void test_create() {
assert
(
interval
.
upper
.
i
==
4
);
assert
(
interval
.
upper_included
==
CCS_FALSE
);
for
(
size_t
i
=
0
;
i
<
num_possible_values
;
i
++
)
{
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
possible_values
[
i
],
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_TRUE
);
}
default_value
.
type
=
CCS_FLOAT
;
err
=
ccs_hyperparameter_check_value
(
hyperparameter
,
default_value
,
&
check
);
assert
(
err
==
CCS_SUCCESS
);
assert
(
check
==
CCS_FALSE
);
err
=
ccs_release_object
(
distribution
);
assert
(
err
==
CCS_SUCCESS
);
err
=
ccs_release_object
(
hyperparameter
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment