lib/dnn/core/utils.rb in ruby-dnn-1.2.3 vs lib/dnn/core/utils.rb in ruby-dnn-1.3.0

- old
+ new

@@ -37,9 +37,23 @@ # Return the result of the softmax function. def self.softmax(x) Losses::SoftmaxCrossEntropy.softmax(x) end + # Check training or evaluate input data type. + def self.check_input_data_type(data_name, data, expected_type) + if !data.is_a?(expected_type) && !data.is_a?(Array) + raise TypeError, "#{data_name}:#{data.class.name} is not an instance of #{expected_type.name} class or Array class." + end + if data.is_a?(Array) + data.each.with_index do |v, i| + unless v.is_a?(expected_type) + raise TypeError, "#{data_name}[#{i}]:#{v.class.name} is not an instance of #{expected_type.name} class." + end + end + end + end + # Perform numerical differentiation. def self.numerical_grad(x, func) (func.(x + 1e-7) - func.(x)) / 1e-7 end