Sha256: 34d7dee410dbd7b53383c3ab53411b7b52ebc8bbfeded731357910b2a1c6d920

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

module Torch
  module Utils
    module Data
      module DataPipes
        class IterDataPipe < IterableDataset
          def self.functional_datapipe(name)
            IterDataPipe.register_datapipe_as_function(name, self)
          end

          def self.functions
            @functions ||= {}
          end

          def self.register_datapipe_as_function(function_name, cls_to_register)
            if functions.include?(function_name)
              raise Error, "Unable to add DataPipe function name #{function_name} as it is already taken"
            end

            function = lambda do |source_dp, *args, **options, &block|
              cls_to_register.new(source_dp, *args, **options, &block)
            end
            functions[function_name] = function

            define_method function_name do |*args, **options, &block|
              IterDataPipe.functions[function_name].call(self, *args, **options, &block)
            end
          end

          def reset
            # no-op, but subclasses can override
          end

          def each(&block)
            reset
            @source_datapipe.each(&block)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
torch-rb-0.18.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.17.1 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.17.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.16.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.15.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.14.1 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.14.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.13.2 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.13.1 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.13.0 lib/torch/utils/data/data_pipes/iter_data_pipe.rb
torch-rb-0.12.2 lib/torch/utils/data/data_pipes/iter_data_pipe.rb