Class: Chainer::Datasets::TupleDataset
- Inherits:
-
Object
- Object
- Chainer::Datasets::TupleDataset
- Defined in:
- lib/chainer/datasets/tuple_dataset.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(*datasets) ⇒ TupleDataset
constructor
A new instance of TupleDataset.
- #size ⇒ Object
Constructor Details
#initialize(*datasets) ⇒ TupleDataset
Returns a new instance of TupleDataset.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/chainer/datasets/tuple_dataset.rb', line 4 def initialize(*datasets) if datasets.empty? raise "no datasets are given" end length = datasets[0].shape[0] datasets.each_with_index do |dataset, idx| raise "dataset of the index #{idx} has a wrong length" unless dataset.shape[0] == length end @datasets = datasets @length = length end |
Instance Method Details
#[](index) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chainer/datasets/tuple_dataset.rb', line 18 def [](index) batches = @datasets.map do |dataset| dataset.ndim > 1 ? dataset[index, false] : dataset[index] end if index.kind_of?(Enumerable) length = batches[0].shape[0] length.times.map {|i| batches.map { |m| m.ndim > 1 ? m[i, false] : m[i] } } else batches end end |
#size ⇒ Object
30 31 32 |
# File 'lib/chainer/datasets/tuple_dataset.rb', line 30 def size @length end |