lib/dnn/core/utils.rb in ruby-dnn-1.1.6 vs lib/dnn/core/utils.rb in ruby-dnn-1.2.0

- old
+ new

@@ -41,7 +41,30 @@ # Perform numerical differentiation. def self.numerical_grad(x, func) (func.(x + 1e-7) - func.(x)) / 1e-7 end + + # Convert numo to cumo. + def self.numo2cumo(na) + b = na.to_binary + ca = Cumo::SFloat.from_binary(b) + ca.reshape(*na.shape) + end + + # Convert cumo to numo. + def self.cumo2numo(ca) + b = ca.to_binary + na = Numo::SFloat.from_binary(b) + na.reshape(*ca.shape) + end + + # Force convert to Float. + def self.to_f(x) + if x.is_a?(Xumo::NArray) + x[0].to_f + else + x.to_f + end + end end end