Esempio n. 1
0
    def test_extract_overlapping_v(self, its=50):
        for it in range(its):
            num_subs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(1, 10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_subs * step + overlap

            vec = randn(vec_size)
            target = None if rand_bool() else randn(num_subs, width)

            if target is None:
                subvectors = bmo.extract_overlapping_v(vec, width, step=step)
                assert subvectors.shape == (num_subs, width)
            else:
                bmo.extract_overlapping_v(vec, width, step=step, target=target)
                subvectors = target

            for index in range(num_subs):
                assert_allequal(subvectors[index],
                                vec[(index * step):(index * step + width)])
Esempio n. 2
0
    def test_extract_overlapping_v(self, its=50):
        for it in range(its):
            num_subs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(1, 10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_subs * step + overlap

            vec = randn(vec_size)
            target = None if rand_bool() else randn(num_subs, width)

            if target is None:
                subvectors = bmo.extract_overlapping_v(vec, width, step=step)
                assert subvectors.shape == (num_subs, width)
            else:
                bmo.extract_overlapping_v(vec, width, step=step, target=target)
                subvectors = target

            for index in range(num_subs):
                assert_allequal(
                    subvectors[index],
                    vec[(index * step):(index * step + width)]
                )
Esempio n. 3
0
    def test_extract_overlapping_v_chunked(self, its=50):
        for it in range(its):
            num_subs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(1, 10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_subs * step + overlap
            chunk_size = random.choice([1, randint(1, 10), randint(1, 10)])

            vec = randn(vec_size)

            indices_remaining = set(range(num_subs))
            subvectors_all = np.empty((num_subs, width))
            for start, end, subvectors in bmo.extract_overlapping_v_chunked(
                    vec, width, chunk_size, step=step):
                assert end >= start + 1
                for index in range(start, end):
                    assert index in indices_remaining
                    indices_remaining.remove(index)
                subvectors_all[start:end] = subvectors

            subvectors_good = bmo.extract_overlapping_v(vec, width, step=step)
            assert_allclose(subvectors_all, subvectors_good)
Esempio n. 4
0
    def test_extract_overlapping_v_chunked(self, its=50):
        for it in range(its):
            num_subs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(1, 10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_subs * step + overlap
            chunk_size = random.choice([1, randint(1, 10), randint(1, 10)])

            vec = randn(vec_size)

            indices_remaining = set(range(num_subs))
            subvectors_all = np.empty((num_subs, width))
            for start, end, subvectors in bmo.extract_overlapping_v_chunked(
                vec, width, chunk_size, step=step
            ):
                assert end >= start + 1
                for index in range(start, end):
                    assert index in indices_remaining
                    indices_remaining.remove(index)
                subvectors_all[start:end] = subvectors

            subvectors_good = bmo.extract_overlapping_v(vec, width, step=step)
            assert_allclose(subvectors_all, subvectors_good)