Commit efe8699e authored by Brice Videau's avatar Brice Videau
Browse files

Reworked binding error handling.

parent 80e9f76e
......@@ -152,7 +152,7 @@ module CCS
when :CCS_NUM_INTEGER
self[:i]
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -167,7 +167,7 @@ module CCS
n[:i] = v
n
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -178,7 +178,7 @@ module CCS
when Integer
self[:i] = v
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
end
......@@ -238,7 +238,7 @@ module CCS
when :CCS_OBJECT
Object::from_handle(self[:value][:o])
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -282,7 +282,7 @@ module CCS
self[:type] = :CCS_OBJECT
self[:value][:o] = v.handle
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
v
end
......@@ -321,7 +321,7 @@ module CCS
d.instance_variable_set(:@object, v)
d
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
end
......@@ -338,9 +338,19 @@ module CCS
alias version ccs_get_version
end
class CCSError < StandardError
def self.to_native(sym)
-Error.to_native(sym, nil)
end
def to_native
-Error.to_native(message.to_sym, nil)
end
end
def self.error_check(result)
if result < 0
raise StandardError, Error.from_native(-result, nil)
raise CCSError, Error.from_native(-result, nil)
end
end
......@@ -393,7 +403,7 @@ module CCS
def initialize(handle, retain: false, auto_release: true)
if !handle
raise StandardError, :CCS_INVALID_OBJECT
raise CCSError, :CCS_INVALID_OBJECT
end
@handle = handle
if retain
......@@ -427,7 +437,7 @@ module CCS
when :CCS_TUNER
CCS::Tuner::from_handle(handle)
else
raise StandardError, :CCS_INVALID_OBJECT
raise CCSError, :CCS_INVALID_OBJECT
end
end
......
......@@ -23,7 +23,7 @@ module CCS
else
if values
count = values.size
raise StandardError, :CCS_INVALID_VALUE if count == 0
raise CCSError, :CCS_INVALID_VALUE if count == 0
p_values = MemoryPointer::new(:ccs_datum_t, count)
values.each_with_index { |v, i| Datum::new(p_values[i]).value = v }
values = p_values
......@@ -64,7 +64,7 @@ module CCS
when Integer
res = CCS.ccs_configuration_get_value(@handle, hyperparameter, ptr)
else
raise StandardError, :CCS_INVALID_VALUE
raise CCSError, :CCS_INVALID_VALUE
end
CCS.error_check(res)
Datum::new(ptr).value
......
......@@ -77,7 +77,7 @@ module CCS
count = hyperparameters.size
return self if count == 0
if distributions
raise StandardError, :CCS_INVALID_VALUE if count != distributions.size
raise CCSError, :CCS_INVALID_VALUE if count != distributions.size
p_dists = MemoryPointer::new(:ccs_distribution_t, count)
p_dists.write_array_of_pointer(distributions.collect(&:handle))
distributions = p_dist
......@@ -204,7 +204,7 @@ module CCS
def check_values(values)
count = values.size
raise StandardError, :CCS_INVALID_VALUE if count != num_hyperparameters
raise CCSError, :CCS_INVALID_VALUE if count != num_hyperparameters
ptr = MemoryPointer::new(:ccs_datum_t, count)
values.each_with_index { |v, i| Datum::new(ptr[i]).value = v }
res = CCS.ccs_configuration_space_check_configuration_values(@handle, count, ptr)
......
......@@ -49,7 +49,7 @@ module CCS
when :CCS_ROULETTE
RouletteDistribution::new(handle, retain: true)
else
raise StandardError, :CCS_INVALID_DISTRIBUTION
raise CCSError, :CCS_INVALID_DISTRIBUTION
end
end
......
......@@ -36,7 +36,7 @@ module CCS
else
if values
count = values.size
raise StandardError, :CCS_INVALID_VALUE if count == 0
raise CCSError, :CCS_INVALID_VALUE if count == 0
p_values = MemoryPointer::new(:ccs_datum_t, count)
values.each_with_index { |v, i| Datum::new(p_values[i]).value = v }
values = p_values
......@@ -85,7 +85,7 @@ module CCS
when Integer
res = CCS.ccs_evaluation_get_value(@handle, hyperparameter, ptr)
else
raise StandardError, :CCS_INVALID_VALUE
raise CCSError, :CCS_INVALID_VALUE
end
CCS.error_check(res)
Datum::new(ptr).value
......
......@@ -112,7 +112,7 @@ module CCS
def eval(context: nil, values: nil)
if values && context
count = context.num_hyperparameters
raise StandardError, :CCS_INVALID_VALUES if values.size != count
raise CCSError, :CCS_INVALID_VALUES if values.size != count
p_values = MemoryPointer::new(:ccs_datum_t, count)
values.each_with_index{ |v, i| Datum::new(p_values[i]).value = v }
values = p_values
......@@ -231,7 +231,7 @@ module CCS
def eval(index, context: nil, values: nil)
if values && context
count = context.num_hyperparameters
raise StandardError, :CCS_INVALID_VALUES if values.size != count
raise CCSError, :CCS_INVALID_VALUES if values.size != count
p_values = MemoryPointer::new(:ccs_datum_t, count)
values.each_with_index{ |v, i| Datum::new(p_values[i]).value = v }
values = p_values
......
......@@ -48,7 +48,7 @@ module CCS
when :CCS_ORDINAL
OrdinalHyperparameter::new(handle, retain: true)
else
raise StandardError, :CCS_INVALID_HYPERPARAMETER
raise CCSError, :CCS_INVALID_HYPERPARAMETER
end
end
......@@ -138,7 +138,7 @@ module CCS
quantization = Numeric::from_value(quantization.to_i)
default = Numeric::from_value(default.to_i)
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
res = CCS.ccs_create_numerical_hyperparameter(name, data_type, lower, upper, quantization, default, user_data, ptr)
CCS.error_check(res)
......
......@@ -8,7 +8,7 @@ module CCS
def initialize(*args, type:, lower: nil, upper: nil, lower_included: true, upper_included: false)
unless [:CCS_NUM_FLOAT, :CCS_NUM_INTEGER].include?(type)
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
super(*args)
self[:type] = type
......@@ -41,7 +41,7 @@ module CCS
when :CCS_NUM_INTEGER
self[:lower][:i]
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -52,7 +52,7 @@ module CCS
when :CCS_NUM_INTEGER
self[:lower][:i] = v
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -63,7 +63,7 @@ module CCS
when :CCS_NUM_INTEGER
self[:upper][:i]
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -74,7 +74,7 @@ module CCS
when :CCS_NUM_INTEGER
self[:upper][:i] = v
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
end
......@@ -123,7 +123,7 @@ module CCS
when :CCS_NUM_INTEGER
n[:i] = v
else
raise StandardError, :CCS_INVALID_TYPE
raise CCSError, :CCS_INVALID_TYPE
end
res = CCS.ccs_interval_include(self, n)
res == CCS::FALSE ? false : true
......
......@@ -129,7 +129,7 @@ module CCS
count = expressions.length
return self if count == 0
if types
raise StandardError, :CCS_INVALID_VALUE if types.size != count
raise CCSError, :CCS_INVALID_VALUE if types.size != count
else
types = [:CCS_MINIMIZE] * count
end
......
......@@ -37,7 +37,7 @@ module CCS
when :CCS_TUNER_USER_DEFINED
GenericTuner::new(handle, retain: true)
else
raise StandardError, :CCS_INVALID_TUNER
raise CCSError, :CCS_INVALID_TUNER
end
end
......
......@@ -19,7 +19,7 @@ class CConfigSpaceTestHyperparameter < Minitest::Test
assert_equal( 1, h.compare(3.0, "foo") )
assert_equal( 1, h.compare(3.0, 2) )
assert_equal( 0, h.compare(3.0, 3.0) )
assert_raises(StandardError, :CCS_INVALID_VALUE) { h.compare(4.0, "foo") }
assert_raises(CCS::CCSError, :CCS_INVALID_VALUE) { h.compare(4.0, "foo") }
end
def test_from_handle_ordinal
......
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