Example #1
0
    def upsample2_test(self):
        """
        Here testing upsampling with the following configurations (+ testing stereo):
        IN:  |     |     |     |
        OUT: |   |   |   |   |
        """

        def gen():
            """
            [[0, 0], [-2, 2], [-4, 4]] [[-6, 6], [-8, 8], [-10, 10]] ...
            """
            for i in range(0, 2):
                block_in = numpy.vstack([
                    numpy.arange(-i * 2 * 3, -(i + 1) * 2 * 3, -2),
                    numpy.arange(i * 2 * 3, (i + 1) * 2 * 3, 2)
                ]).transpose()
                yield block_in

        resampler = stream_functions.resample(gen())
        ratio = 3.0 / 2
        resampler.set_ratio(ratio)


        # IN:  0     1     2     3     4     5
        # OUT: 0   1   2   3   4   5   6   7
        numpy.testing.assert_array_equal(
            stream_functions.concatenate(resampler).round(8),
            (numpy.array([
                [0, 0], [-1, 1], [-2, 2], [-3, 3], 
                [-4, 4], [-5, 5], [-6, 6], [-7, 7]
            ]) * 2 / ratio).round(8)
        )
Example #2
0
    def upsample1_test(self):
        """
        Testing upsampling with the following configurations :
        IN:  |     |     |
        OUT: | | | | | | |
        """

        def gen():
            """
            [[0], [2], [4]] [[6], [8], [10]] ...
            """
            for i in range(0, 2):
                yield numpy.arange(i * 2 * 3, (i + 1) * 2 * 3, 2).reshape(3, 1)

        resampler = stream_functions.resample(gen())
        resampler.set_ratio(3.0)

        # IN:  0     1     2     3     4     5
        # OUT: 0 1 2 3 4 5 6 7 8 9 a b c d e f
        numpy.testing.assert_array_equal(
            stream_functions.concatenate(resampler).round(8),
            (numpy.array([
                [0], [1], [2], [3], [4], [5], [6], [7], [8], 
                [9], [10], [11], [12], [13], [14], [15]
            ]) * 2.0 / 3).round(8)
        )
Example #3
0
 def simple_test(self):
     def source():
         for i in range(0, 3):
             yield numpy.ones([3, 1]) * i
     block = stream_functions.concatenate(source())
     numpy.testing.assert_array_equal(block, numpy.array([
         [0], [0], [0], [1], [1], [1], [2], [2], [2]
     ]))
Example #4
0
 def hop_size_bigger_than_win_size_test(self):
     def gen():
         for i in range(6):
             yield numpy.array([[i * 11, i * 11]])
     window = stream_functions.window(gen(), 2, 3, pad=True)
     numpy.testing.assert_array_equal(
         stream_functions.concatenate(window), 
         [[0, 0], [11, 11], [33, 33], [44, 44]]
     )
Example #5
0
 def win_size_exact_and_pad_test(self):
     """
     Test when padding is True, and last window falls exactly, without actual need for padding. 
     """
     def gen():
         for i in range(2):
             yield numpy.array([[i * 11, i * 11]])
     window = stream_functions.window(gen(), 1, 1, pad=True)
     numpy.testing.assert_array_equal(
         stream_functions.concatenate(window), 
         [[0, 0], [11, 11]]
     )
Example #6
0
    def ratio1_test(self):
        """
        Ratio 1 test.
        """

        def gen():
            """
            [[0], [0.5], [1]] [[1.5], [2], [2.5]] ...
            """
            for i in range(0, 2):
                yield numpy.arange(i * 3 * 0.5, (i + 1) * 3 * 0.5, 0.5).reshape(3, 1)

        resampler = stream_functions.resample(gen())

        numpy.testing.assert_array_equal(
            stream_functions.concatenate(resampler).round(8),
            (numpy.array([[0], [1], [2], [3], [4], [5]]) * 0.5).round(8)
        )
Example #7
0
    def downsample3_test(self):
        """
        Testing high downsampling, several blocks of incoming data fetched for one frame out.
        """

        def gen():
            """
            [[0], [0.5], [1]] [[1.5], [2], [2.5]] ...
            """
            for i in range(0, 6):
                yield numpy.arange(i * 3 * 0.5, (i + 1) * 3 * 0.5, 0.5).reshape(3, 1)

        resampler = stream_functions.resample(gen())
        ratio = 1.0 / 8
        resampler.set_ratio(ratio)

        # IN:  0 1 2 3 4 5 6 7 8 9 a b c d e f g h
        # OUT: 0               1               2
        numpy.testing.assert_array_equal(
            stream_functions.concatenate(resampler).round(8),
            (numpy.array([[0], [1], [2]]) * (0.5 / ratio)).round(8)
        )
Example #8
0
    def downsample2_test(self):
        """
        Testing downsampling with the following configurations:
        # IN:  | | | | | | | | |
        # OUT: |       |       |
        """

        def gen():
            """
            [[0], [0.5], [1]] [[1.5], [2], [2.5]] ...
            """
            for i in range(0, 3):
                yield numpy.arange(i * 3 * 0.5, (i + 1) * 3 * 0.5, 0.5).reshape(3, 1)

        resampler = stream_functions.resample(gen())
        ratio = 1.0 / 4
        resampler.set_ratio(ratio)

        # IN:  0 1 2 3 4 5 6 7 8
        # OUT: 0       1       2
        numpy.testing.assert_array_equal(
            stream_functions.concatenate(resampler).round(8),
            (numpy.array([[0], [1], [2]]) * 0.5 / ratio).round(8)
        )