Exemple #1
0
class TestDuplicate(object):
    def setUp(self):
        rng = numpy.random.RandomState(123)
        self.stream = DataStream(
            IndexableDataset(
                OrderedDict([('features', rng.rand(4, 2, 2)),
                             ('targets', numpy.array([0, 1, 0, 1]))]),
                axis_labels={'features': ('batch', 'width', 'height'),
                             'targets': ('batch',)}),
            iteration_scheme=SequentialScheme(4, 2))

        self.duplicate = Duplicate(self.stream, 'features')

    def test_init(self):
        duplicate = Duplicate(self.stream)
        assert_equal(duplicate.which_sources, self.stream.sources)
        assert_equal(self.duplicate.which_sources, ['features'])

    def test_sources(self):
        assert_equal(self.duplicate.sources, ['features',
                                              'features_duplicate',
                                              'targets'])

    def test_get_data(self):
        self.duplicate.get_epoch_iterator()
        assert_raises(ValueError, self.duplicate.get_data, **{'request': 'k'})
        data = self.duplicate.get_data()
        assert_equal(data[0], data[1])
Exemple #2
0
class TestDuplicate(object):
    def setUp(self):
        rng = numpy.random.RandomState(123)
        self.stream = DataStream(IndexableDataset(OrderedDict([
            ('features', rng.rand(4, 2, 2)),
            ('targets', numpy.array([0, 1, 0, 1]))
        ]),
                                                  axis_labels={
                                                      'features':
                                                      ('batch', 'width',
                                                       'height'),
                                                      'targets': ('batch', )
                                                  }),
                                 iteration_scheme=SequentialScheme(4, 2))

        self.duplicate = Duplicate(self.stream, 'features')

    def test_init(self):
        duplicate = Duplicate(self.stream)
        assert_equal(duplicate.which_sources, self.stream.sources)
        assert_equal(self.duplicate.which_sources, ['features'])

    def test_sources(self):
        assert_equal(self.duplicate.sources,
                     ['features', 'features_duplicate', 'targets'])

    def test_get_data(self):
        self.duplicate.get_epoch_iterator()
        assert_raises(ValueError, self.duplicate.get_data, **{'request': 'k'})
        data = self.duplicate.get_data()
        assert_equal(data[0], data[1])