Class: Torch::Utils::Data::Subset

Inherits:
Dataset
  • Object
show all
Defined in:
lib/torch/utils/data/subset.rb

Instance Method Summary collapse

Constructor Details

#initialize(dataset, indices) ⇒ Subset

Returns a new instance of Subset.



5
6
7
8
# File 'lib/torch/utils/data/subset.rb', line 5

def initialize(dataset, indices)
  @dataset = dataset
  @indices = indices
end

Instance Method Details

#[](idx) ⇒ Object



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

def [](idx)
  @dataset[@indices[idx]]
end

#lengthObject Also known as: size



14
15
16
# File 'lib/torch/utils/data/subset.rb', line 14

def length
  @indices.length
end

#to_aObject



19
20
21
# File 'lib/torch/utils/data/subset.rb', line 19

def to_a
  @indices.map { |i| @dataset[i] }
end