Exemple #1
0
 def zip(datastreams: List[Datastream]) -> Datastream[Tuple]:
     '''
     Zip multiple datastreams together so that all combinations of examples
     are possible (i.e. the product) creating tuples like
     ``(example1, example2, ...)``. The samples are drawn independently
     from each underlying datastream.
     '''
     return Datastream(
         Dataset.combine([datastream.dataset
                          for datastream in datastreams]),
         ZipSampler(*zip(*[(datastream.sampler, datastream.dataset)
                           for datastream in datastreams])),
     )
Exemple #2
0
def test_combine_concat_merge():
    dataset = Dataset.concat([
        Dataset.zip([
            Dataset.from_subscriptable([1]),
            Dataset.from_subscriptable([2]),
        ]),
        Dataset.combine([
            Dataset.from_subscriptable([3, 3]),
            Dataset.from_subscriptable([4, 4, 4]),
        ]),
    ])

    datastream = Datastream.merge([
        Datastream(dataset),
        Datastream(
            Dataset.zip([
                Dataset.from_subscriptable([5]),
                Dataset.from_subscriptable([6]),
            ])),
    ])

    assert len(list(datastream)) == 2