Class: Torch::Utils::Data::DataPipes::Iter::FileOpener

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

Instance Method Summary collapse

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

functional_datapipe, functions, register_datapipe_as_function, #reset

Constructor Details

#initialize(datapipe, mode: "r", encoding: nil, length: -1)) ⇒ FileOpener

Returns a new instance of FileOpener.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/torch/utils/data/data_pipes/iter/file_opener.rb', line 7

def initialize(datapipe, mode: "r", encoding: nil, length: -1)
  super()
  @datapipe = datapipe
  @mode = mode
  @encoding = encoding

  if !["b", "t", "rb", "rt", "r"].include?(@mode)
    raise ArgumentError, "Invalid mode #{mode}"
  end

  if mode.include?("b") && !encoding.nil?
    raise ArgumentError, "binary mode doesn't take an encoding argument"
  end

  @length = length
end

Instance Method Details

#each(&block) ⇒ Object



24
25
26
# File 'lib/torch/utils/data/data_pipes/iter/file_opener.rb', line 24

def each(&block)
  get_file_binaries_from_pathnames(@datapipe, @mode, encoding: @encoding, &block)
end