Example #1
0
 def cut_into_smaller_blocks_test(self):
     def gen():
         yield numpy.tile(numpy.arange(0, 10), (2, 1)).transpose()
     stream = StreamControl(gen())
     blocks = [stream.pull(2) for i in range(0, 5)]
     numpy.testing.assert_array_equal(blocks, [
         [[0, 0], [1, 1]], [[2, 2], [3, 3]], [[4, 4], [5, 5]],
         [[6, 6], [7, 7]], [[8, 8], [9, 9]]
     ])
Example #2
0
 def pad_test(self):
     def gen():
         yield numpy.tile(numpy.arange(0, 5), (2, 1)).transpose()
     stream = StreamControl(gen())
     block = stream.pull(8, pad=True)
     numpy.testing.assert_array_equal(block, [
         [0, 0], [1, 1], [2, 2], [3, 3],
         [4, 4], [0, 0], [0, 0], [0, 0]
     ])
Example #3
0
 def get_bigger_blocks_test(self):
     def gen():
         for i in range(10):
             yield numpy.array([[i * 11]])
     stream = StreamControl(gen())
     blocks = [stream.pull(2) for i in range(0, 5)]
     numpy.testing.assert_array_equal(blocks, [
         [[0], [11]], [[22], [33]], [[44], [55]],
         [[66], [77]], [[88], [99]]
     ])    
Example #4
0
 def receive_variable_block_size_test(self):
     def gen():
         for i in range(5):
             yield numpy.array([[i * 1] * 3])
         yield numpy.tile(numpy.arange(5, 10), (3, 1)).transpose()
     stream = StreamControl(gen())
     blocks = [stream.pull(2) for i in range(0, 5)]
     numpy.testing.assert_array_equal(blocks, [
         [[0, 0, 0], [1, 1, 1]], [[2, 2, 2], [3, 3, 3]],
         [[4, 4, 4], [5, 5, 5]], [[6, 6, 6], [7, 7, 7]],
         [[8, 8, 8], [9, 9, 9]]
     ])
Example #5
0
    def exhausted_test(self):
        def gen():
            yield numpy.tile(numpy.arange(0, 11), (2, 1)).transpose()
        stream = StreamControl(gen())
        blocks = [stream.pull(3) for i in range(0, 3)]
        numpy.testing.assert_array_equal(blocks, [
            [[0, 0], [1, 1], [2, 2]],
            [[3, 3], [4, 4], [5, 5]],
            [[6, 6], [7, 7], [8, 8]]
        ])

        block = stream.pull(3)
        numpy.testing.assert_array_equal(block, [[9, 9], [10, 10]])
        self.assertRaises(StopIteration, stream.pull, 2)
Example #6
0
 def pull_variable_block_size_test(self):
     def gen():
         for i in range(20):
             yield numpy.array([[i * 1] * 2])
     stream = StreamControl(gen())
     numpy.testing.assert_array_equal(
         stream.pull(3),
         [[0, 0], [1, 1], [2, 2]]
     )
     numpy.testing.assert_array_equal(
         stream.pull(3),
         [[3, 3], [4, 4], [5, 5]]
     )
     numpy.testing.assert_array_equal(
         stream.pull(6),
         [[6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]]
     )