Sha256: d22657e21d13199fd40568d10b58a6784858bb5c6c479ce71141ee536cf462e0

Contents?: true

Size: 540 Bytes

Versions: 9

Compression:

Stored size: 540 Bytes

Contents

module Torch
  module Utils
    module Data
      class DataLoader
        include Enumerable

        attr_reader :dataset

        def initialize(dataset, batch_size: 1)
          @dataset = dataset
          @batch_size = batch_size
        end

        def each
          size.times do |i|
            start_index = i * @batch_size
            yield @dataset[start_index...(start_index + @batch_size)]
          end
        end

        def size
          (@dataset.size / @batch_size.to_f).ceil
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
torch-rb-0.2.2 lib/torch/utils/data/data_loader.rb
torch-rb-0.2.1 lib/torch/utils/data/data_loader.rb
torch-rb-0.2.0 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.8 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.7 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.6 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.5 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.4 lib/torch/utils/data/data_loader.rb
torch-rb-0.1.3 lib/torch/utils/data/data_loader.rb