Commit 6d2ae67f authored by Brice Videau's avatar Brice Videau

Use uniform error reporting.

parent ca395341
......@@ -243,7 +243,7 @@ class ccs_numeric(ct.Union):
elif t == ccs_numeric_type.NUM_FLOAT:
return self.v
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
def set_value(self, v):
if isinstance(v, int):
......@@ -251,7 +251,7 @@ class ccs_numeric(ct.Union):
elif isinstance(v, float):
self.f = v
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
class ccs_value(ct.Union):
_fields_ = [('f', ccs_float),
......@@ -288,7 +288,7 @@ class ccs_datum(ct.Structure):
elif self.type.value == ccs_data_type.OBJECT:
return Object.from_handle(ct.c_void_p(self._value.o))
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
@value.setter
def value(self, v):
......@@ -316,7 +316,7 @@ class ccs_datum(ct.Structure):
self._object = v
self._value.o = v.handle
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
class Error(Exception):
def __init__(self, message):
......@@ -340,7 +340,7 @@ Error.check(_res)
class Object:
def __init__(self, handle, retain = False, auto_release = True):
if handle is None:
raise Error(ccs_error.INVALID_OBJECT)
raise Error(ccs_error(ccs_error.INVALID_OBJECT))
self._handle = handle
self.auto_release = auto_release
if retain:
......@@ -397,7 +397,7 @@ class Object:
elif v == ccs_object_type.Tuner:
return Tuner.from_handle(h)
else:
raise Error(ccs_error.INVALID_OBJECT)
raise Error(ccs_error(ccs_error.INVALID_OBJECT))
_ccs_id = 0
def _ccs_get_id():
......
......@@ -90,7 +90,7 @@ class ConfigurationSpace(Context):
return None
if distributions:
if count != len(distributions):
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
distribs = (ccs_distribution * count)(*[x.handle.value if x else x for x in distributions])
else:
distribs = None
......@@ -216,7 +216,7 @@ class ConfigurationSpace(Context):
def check_values(self, values):
count = len(values)
if count != self.num_hyperparameters:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
v = (ccs_datum * count)()
for i in range(count):
v[i].value = values[i]
......
......@@ -39,7 +39,7 @@ class Distribution(Object):
elif v == ccs_distribution_type.ROULETTE:
return RouletteDistribution(handle = handle, retain = True)
else:
raise Error(ccs_error.INVALID_DISTRIBUTION)
raise Error(ccs_error(ccs_error.INVALID_DISTRIBUTION))
@property
def type(self):
......@@ -94,7 +94,7 @@ class Distribution(Object):
elif t == ccs_numeric_type.NUM_FLOAT:
self._quantization = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._quantization
@property
......@@ -123,7 +123,7 @@ class Distribution(Object):
elif t == ccs_numeric_type.NUM_FLOAT:
return v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
def samples(self, rng, count):
if count == 0:
......@@ -134,7 +134,7 @@ class Distribution(Object):
elif t == ccs_numeric_type.NUM_FLOAT:
v = (ccs_float * count)()
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
res = ccs_distribution_samples(self.handle, rng.handle, count, ct.cast(v, ct.POINTER(ccs_numeric)))
Error.check(res)
return list(v)
......@@ -153,7 +153,7 @@ class UniformDistribution(Distribution):
elif data_type == NUM_INTEGER:
res = ccs_create_uniform_int_distribution(lower, upper, scale, quantization, ct.byref(handle))
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
Error.check(res)
super().__init__(handle = handle, retain = False)
else:
......@@ -180,7 +180,7 @@ class UniformDistribution(Distribution):
elif t == ccs_numeric_type.NUM_FLOAT:
self._lower = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._lower
@property
......@@ -196,7 +196,7 @@ class UniformDistribution(Distribution):
elif t == ccs_numeric_type.NUM_FLOAT:
self._upper = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._upper
ccs_create_normal_distribution = _ccs_get_function("ccs_create_normal_distribution", [ccs_numeric_type, ccs_float, ccs_float, ccs_scale_type, ccs_int, ct.POINTER(ccs_distribution)])
......@@ -213,7 +213,7 @@ class NormalDistribution(Distribution):
elif data_type == NUM_INTEGER:
res = ccs_create_normal_int_distribution(mu, sigma, scale, quantization, ct.byref(handle))
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
Error.check(res)
super().__init__(handle = handle, retain = False)
else:
......
......@@ -160,14 +160,14 @@ class Expression(Object):
if context and values:
count = context.num_hyperparameters
if count != len(values):
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
v = (ccs_datum * count)()
for i in range(count):
v[i].value = values[i]
values = v
context = context.handle
elif context or values:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
v = ccs_datum()
res = ccs_expression_eval(self.handle, context, values, ct.byref(v))
Error.check(res)
......@@ -255,14 +255,14 @@ class List(Expression):
if context and values:
count = context.num_hyperparameters
if count != len(values):
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
v = (ccs_datum * count)()
for i in range(count):
v[i].value = values[i]
values = v
context = context.handle
elif context or values:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
v = ccs_datum()
res = ccs_expression_list_eval_node(self.handle, context, values, index, ct.byref(v))
Error.check(res)
......
......@@ -39,7 +39,7 @@ class Hyperparameter(Object):
elif v == ccs_hyperparameter_type.DISCRETE:
return DiscreteHyperparameter(handle = handle, retain = True)
else:
raise Error(ccs_error.INVALID_HYPERPARAMETER)
raise Error(ccs_error(ccs_error.INVALID_HYPERPARAMETER))
@classmethod
def default_name(cls):
......@@ -165,7 +165,7 @@ class NumericalHyperparameter(Hyperparameter):
q.i = quantization
d.i = default
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
handle = ccs_hyperparameter()
res = ccs_create_numerical_hyperparameter(str.encode(name), data_type, l.i, u.i, q.i, d.i, user_data, ct.byref(handle))
Error.check(res)
......@@ -204,7 +204,7 @@ class NumericalHyperparameter(Hyperparameter):
elif t == ccs_numeric_type.NUM_FLOAT:
self._lower = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._lower
@property
......@@ -220,7 +220,7 @@ class NumericalHyperparameter(Hyperparameter):
elif t == ccs_numeric_type.NUM_FLOAT:
self._upper = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._upper
@property
......@@ -236,7 +236,7 @@ class NumericalHyperparameter(Hyperparameter):
elif t == ccs_numeric_type.NUM_FLOAT:
self._quantization = v.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
return self._quantization
ccs_create_categorical_hyperparameter = _ccs_get_function("ccs_create_categorical_hyperparameter", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_datum), ct.c_size_t, ct.c_void_p, ct.POINTER(ccs_hyperparameter)])
......
......@@ -16,7 +16,7 @@ class ccs_interval(ct.Structure):
elif self.type.value == ccs_numeric_type.NUM_FLOAT:
return self._lower.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
@lower.setter
def lower(self, value):
......@@ -25,7 +25,7 @@ class ccs_interval(ct.Structure):
elif self.type.value == ccs_numeric_type.NUM_FLOAT:
self._lower.f = value
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
@property
def upper(self):
......@@ -34,7 +34,7 @@ class ccs_interval(ct.Structure):
elif self.type.value == ccs_numeric_type.NUM_FLOAT:
return self._upper.f
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
@upper.setter
def upper(self, value):
......@@ -43,7 +43,7 @@ class ccs_interval(ct.Structure):
elif self.type.value == ccs_numeric_type.NUM_FLOAT:
self._upper.f = value
else:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
@property
def lower_included(self):
......
......@@ -124,7 +124,7 @@ class ObjectiveSpace(Context):
return None
if types:
if len(types) != sz:
raise Error(ccs_error.INVALID_VALUE)
raise Error(ccs_error(ccs_error.INVALID_VALUE))
types = (ccs_objective_type * sz)(*types)
else:
types = (ccs_objective_type * sz)(*([ccs_objective_type.MINIMIZE] * sz))
......
......@@ -34,7 +34,7 @@ class Tuner(Object):
elif v == ccs_hyperparameter_type.USER_DEFIND:
return UserDefinedTuner(handle = handle, retain = True)
else:
raise Error(ccs_error.INVALID_TUNER)
raise Error(ccs_error(ccs_error.INVALID_TUNER))
@property
def type(self):
......
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