Class: Torch::Utils::Data::DataPipes::IterDataPipe

Inherits:
IterableDataset show all
Defined in:
lib/torch/utils/data/data_pipes/iter_data_pipe.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.functional_datapipe(name) ⇒ Object



6
7
8
# File 'lib/torch/utils/data/data_pipes/iter_data_pipe.rb', line 6

def self.functional_datapipe(name)
  IterDataPipe.register_datapipe_as_function(name, self)
end

.functionsObject



10
11
12
# File 'lib/torch/utils/data/data_pipes/iter_data_pipe.rb', line 10

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

.register_datapipe_as_function(function_name, cls_to_register) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/torch/utils/data/data_pipes/iter_data_pipe.rb', line 14

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

Instance Method Details

#each(&block) ⇒ Object



33
34
35
36
# File 'lib/torch/utils/data/data_pipes/iter_data_pipe.rb', line 33

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

#resetObject



29
30
31
# File 'lib/torch/utils/data/data_pipes/iter_data_pipe.rb', line 29

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