lib/menoh.rb in menoh-1.0.0 vs lib/menoh.rb in menoh-1.0.1

- old
+ new

@@ -2,39 +2,24 @@ require 'menoh/menoh_native' module Menoh class Menoh def initialize(file) - if !File.exist?(file) - raise "No such file : #{file}" - end + raise "No such file : #{file}" unless File.exist?(file) native_init file yield self if block_given? end def make_model(option) - if option[:backend].nil? - raise "Required ':backend' : #{option[:backend]}" - end + raise "Required ':backend' : #{option[:backend]}" if option[:backend].nil? model = MenohModel.new self, option yield model if block_given? model end end -end -def transpose(buffer, shape) - sliced_buffer = buffer.each_slice(buffer.length / shape[0]).to_a - if shape.length > 2 - next_shape = shape.slice(1, a.length) - sliced_buffer = sliced_buffer.map { |buf| transpose buf, next_shape } - end - sliced_buffer -end - -module Menoh class MenohModel def initialize(menoh, option) if option[:input_layers].nil? || option[:input_layers].empty? raise "Required ':input_layers'" end @@ -75,13 +60,24 @@ # reshape result results.map do |raw| buffer = raw[:data] shape = raw[:shape] - raw[:data] = transpose buffer, shape + raw[:data] = Util.reshape buffer, shape end yield results if block_given? results + end + end + + module Util + def self.reshape(buffer, shape) + sliced_buffer = buffer.each_slice(buffer.length / shape[0]).to_a + if shape.length > 2 + next_shape = shape.slice(1, shape.length) + sliced_buffer = sliced_buffer.map { |buf| reshape buf, next_shape } + end + sliced_buffer end end end