Class: Torch::Utils::Data::DataPipes::Iter::IterableWrapper

Inherits:
Torch::Utils::Data::DataPipes::IterDataPipe show all
Defined in:
lib/torch/utils/data/data_pipes/iter/iterable_wrapper.rb

Instance Method Summary collapse

Methods inherited from Torch::Utils::Data::DataPipes::IterDataPipe

functional_datapipe, functions, register_datapipe_as_function, #reset

Constructor Details

#initialize(iterable, deepcopy: true) ⇒ IterableWrapper

Returns a new instance of IterableWrapper.



7
8
9
10
# File 'lib/torch/utils/data/data_pipes/iter/iterable_wrapper.rb', line 7

def initialize(iterable, deepcopy: true)
  @iterable = iterable
  @deepcopy = deepcopy
end

Instance Method Details

#eachObject



12
13
14
15
16
17
18
19
20
# File 'lib/torch/utils/data/data_pipes/iter/iterable_wrapper.rb', line 12

def each
  source_data = @iterable
  if @deepcopy
    source_data = Marshal.load(Marshal.dump(@iterable))
  end
  source_data.each do |data|
    yield data
  end
end

#lengthObject



22
23
24
# File 'lib/torch/utils/data/data_pipes/iter/iterable_wrapper.rb', line 22

def length
  @iterable.length
end